|
Please replace line starting with t2 by the following:
t2 = 63/1024;
This is because, although we think that we have only one period of the signal, in the discrete world, things are considered to be periodic. Therefore, you should have a full period of your sine wave. Your period is T = 1/16 which is equal to 64/1024. But since you started from 0/1024, which will have the identical signal amplitude with 64/1024, we will exclude 64/1024 and end the sequence at 63/1024.
"Kola Ogidi" <jreal_kkoo@hotmail.com> wrote in message <gv9ivh$97d$1@fred.mathworks.com>...
> Hello,
>
> I am trying to produce the FFT for a 16Hz sine wave sampled at 1024Hz on MATLAB and also illlustrate this graphically on MATLAB.
>
> I have tried the following code:
> fs=1024;
> f=16;
> t1=0;
> tstep=(1/1024);
> t2=4/1024;
> t=[t1:tstep:t2];
> x=sin(2*pi*f*t);
> X=fft(x);
> Sampleresp=abs(X);
> N=length(X);
> F=[0:N-1]*fs/N;
> stem(F,Sampleresp);
>
> However, my output figure is not showing a peak at 16Hz as I expect. Could you please explain to me what changes I need to make to my code to yield the correct output/graph.
>
> Thank you.
|