Problem

Here's the original code, with comments I added to the side to help understanding:

F0 =13; %frequency in hz
T0 =1/F0; %period
Ts = 0.07; %time between samples
t  = 0:Ts:13*T0; % we want 13 periods of music
x = real(exp(j*(2*pi*F0*t-pi/2))); %here's our calculation of the sine wave
plot(t,x) %...and we plot it.

It appears that we are plotting a graph that is about at 1.25 hz. However, we want a graph that's at 13 hz. What's wrong?

Solution

Simply put, it's the sample rate. 1/13 ~= 0.076, which means that the 13 hz wave we are trying to generate is getting sampled only a bit more than once per cycle. Certainly, more samples than that are needed to model a sine wave. Thus, we just need to change Ts:

F0 =13; %frequency in hz
T0 =1/F0; %period
Ts = 1/44100; %time between samples - CD Quality
t  = 0:Ts:13*T0; % we want 13 periods of music
x = real(exp(j*(2*pi*F0*t-pi/2))); %here's our calculation of the sine wave
plot(t,x) %...and we plot it.

...and our problem goes away!

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang