why fft spectrum for f1=sin(2*pi*10*t) is so much different from f2=sin(2*pi*9*t)?
10 views (last 30 days)
Show older comments
when I plot p=fft(f1) vs freq, I get perfect peak at 10Hz. When I plot f=fft(f2) vs freq, at get a poor peak at 9Hz. Why?
My program look like this: N=1000; T=3; t=[0:N-1]/N; t=t*T; f1=sin(2*pi*10*t); f2=sin(2*pi*9*t); p1=abs(fft(f1))/(N/2); p2=abs(fft(f2))/(N/2); p1=p1(1:N/2); p2=p2(1:N/2); freq=[0:N/2-1]/T; plot(freq,p1); plot(freq,p2); I expect the first chart getts a perfect peak at 10Hz, indeed, I got it. I do not get a good peak for the second at 9Hz. Why? Thank you!
0 Comments
Answers (1)
Youssef Khmou
on 18 Feb 2013
Edited: Youssef Khmou
on 18 Feb 2013
hi,
Nothing wrong with the code, it is true, the two spectra have an amplitude of 1. Perhaps you have drawn the two graphs in the same figure, so that the second graph has replaced the first, draw figures separated or in the same figure using "hold on" command: i re-post the code:
N=1000;
T=3;
t=[0:N-1]/N;
t=t*T;
f1=sin(2*pi*10*t);
f2=sin(2*pi*9*t);
p1=abs(fft(f1))/(N/2);
p2=abs(fft(f2))/(N/2);
p1=p1(1:N/2);
p2=p2(1:N/2);
freq=[0:N/2-1]/T;
plot(freq,p1);
hold on
plot(freq,p2,'r');
0 Comments
See Also
Categories
Find more on Spectral Measurements 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!