Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How does Matlab handle timing ?

Status
Not open for further replies.

Element_115

Advanced Member level 2
Joined
Mar 23, 2002
Messages
508
Helped
72
Reputation
144
Reaction score
43
Trophy points
1,308
Activity points
3,755
matlab function daqfcngen

Hi Genz

I was trying to tune my guitar so I wrote a matlab program to
generate a 440Hz tone . (So I thought)

t=1:05:10; % 10 Seconds (time)
y=sin((440*t/(2*pi)); % sin is in rad's
sound(y);
%%%%%%%END%%%%%%

The tone sounds close to 440Hz but the length
was not 10 second only about 1 or 2.
Can anyone tell me how Matlab handles time.
Or is this a processor based issue, and I should
just do trial and error?

Thanks
 

y=sin((440*t/(2*pi));

This is worng..

y=sin(440*2*pi*t); % This is correct..

Note that w=2*pi*f, but you used w=f/(2*pi) which is not correct..

good luck..
 

Timing in Matlab?

You need to define a frequency sample(Fs), Fs tells matlab, the time to reproduce a single sample.
In accordance with your code t=1:0.5:10, you are using a Fs=1/0.5, so you must give to the sound command the same Fs.

Plus, you have to fix the formula :)
good luck
 

Re: Timing in Matlab?

Yes

additionally you have to choose very fast sampling rate for t for a pure sinusiodal waveform

for these you can use a t=0:1/8192:10 sampling rate for radio quality. This is about 20 point for cycle of wave.

I don't konw if you have in your version of matlab the DAQ toolbox, if you have it use the daqfcngen function see the help

for this purpose you can use a signal generator software (I remember siggen) which you can find easyly in the web.
 

Re: Timing in Matlab?

Thanks for your help!
I did initially use (2*Pi*F*t) but this produced too high of a frequency.
So I played around and the code I showed was close to 440Hz.
I will look into the DAQ help file. But if I use Fs=100KHz (5*20KHz)
how do I know that "1: (1/100000) : 10" will be ten seconds? Is there
a WAV file format that determines Fs?...

Thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top