Fast Fourier Transform function
Show older comments
I tried to make a FFT of a sine wave but I didn't get what I expected.
t = 0:0.01:5; % time interval
w = 4*pi; % rad/s , so w = 2*pi*f, f=frequency
x = sin(w*t);
r = fft(x); % fast fourier transform function
R = real(r);
plot(R) % plotted only the real part of r
What I don't understand is that the only frequency should be 2 Hz, since f=w/(2*pi) = (4*pi)/(2*pi) = 2, but I get a total different value.
Can anyone help me understand the result?
Thanks!

Accepted Answer
More Answers (1)
Mitch Lautigar
on 5 May 2022
1 vote
Couple things i'd like to comment on to try and help you. Please see bullets below.
- You're original graph is setup correctly, but i'd recommend the following change to allow for more samples and therefore better end results. "t = 0:0.01:5;" should probably be changed to "t = 0:0.001:5;"
- When you take the FFT, you need to set the axis up correctly. This is a common complexity in signals and systems, but looking at the MATLAB FFT command will help you set it up (https://www.mathworks.com/help/matlab/ref/fft.html).
Try these two tips, and if you are still stuck, let me know.
Categories
Find more on Discrete Fourier and Cosine Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

