2
votes

I am trying to understand the fft function, for that I have a really simple code to generate a sine wave of 500Hz.

%Time specifications:
   Fs = 1000;                   % samples per second
   dt = 1/Fs;                   % seconds per sample
   StopTime = 0.6;             % seconds
   t = (0:dt:StopTime-dt)';     % seconds
    % Sine wave:
   Fc = 500;                     % hertz
   x = sin(2*pi*Fc*t);
   % Plot the signal versus time:
   figure;
   plot(t,x);
   xlabel('time (in seconds)');
   title('Signal versus Time');
   zoom xon;

Now, the output of that give me a sinusoidal wave which amplitude increases with time.

Why is that? when I didnt add any factor for amplitude. I know that has something to do with the Fs value. what is it exactly?

Thank you

1
You are using 0.001 as atime step. You are building the sine of (2*pi*500*t). This results in :(2*pi*500/1000=pi),(2*pi*500*2/1000)=2pi). This is just not useful. Change your frequency (Fc) to sth. smaller e.g. 50 or use smaller timesteps, thus changing Fs to 5000 or just define dt as 1/5*Fs.The Minion
@TheMinion Make that an answer. The obtained values are 0 to within numerical accuracyLuis Mendo

1 Answers

6
votes

You are using 0.001 as time step. You are building the sine of (2*pi*500*t). This results in :

2*pi*500/1000=pi,
2*pi*500*2/1000=2pi,
2*pi*500*3/1000 =3pi,
...

As values for your first 3 data points. THis would continue til the end. As Luis Mendo said in his comment, within numerical accuracy those values are 0. This is just not useful. Change your frequency (Fc) to sth. smaller e.g. 50 or use smaller timesteps, thus changing Fs=5000 or just define dt=1/5*Fs.