Thread Subject: FFT on MATLAB with Graphical Illustration

Subject: FFT on MATLAB with Graphical Illustration

From: Kola Ogidi

Date: 23 May, 2009 19:32:01

Message: 1 of 3

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.

Subject: FFT on MATLAB with Graphical Illustration

From: Sadik

Date: 23 May, 2009 20:09:02

Message: 2 of 3

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.

Subject: FFT on MATLAB with Graphical Illustration

From: Kola Ogidi

Date: 23 May, 2009 20:51:01

Message: 3 of 3

Thank you so very much, Sadik. My output figure is now showing a peak at approximately 16Hz. I believe I just need to tweak around with the MATLAB equivalent for zoom to confirm my results. Thanks again.
 
Kola

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com