What to do for the right FFT in Matlab (two peaks and incorrect amplitude)?
8 次查看(过去 30 天)
显示 更早的评论
This is the FFT I'm using. But two peaks (did not expect the one in the beginning) are occurring and the amplitude is not as specified (expecting a value of 2). Any help is much appreciated!
Amp = 2;
freqHz = 10000;
fsHz = freqHz*2+1;
dt = 1/fsHz;
sine = Amp*sin(2*pi*freqHz*(0:dt:1-dt));
transform = fft(sine,fsHz)/fsHz;
magTransform = abs(transform);
faxis = linspace(0,fsHz/2,fsHz);
plot(faxis,fftshift(magTransform));
xlabel('Frequency')
1 个评论
Image Analyst
2018-6-26
Why do you (incorrectly) think the fft of a sinewave should have only one peak instead of 2? It has 2 because it's supposed to have 2.
回答(1 个)
David Goodmanson
2018-6-28
Hi mldmnn,
Since
A*sin(2*pi*f0*t) = (A/(2i)) * ( exp(2*pi*i*f0*t) - exp(-2*pi*i*f0*t) ),
the transform of sin has two peaks, one at positive frequency, one at negative frequency. Each has absolute value of half the amplitude of the sine function. You are getting the correct result. But with your values of freqHz and dt,
freqHz*dt = .499975 % cycles per point.
The frequency is very high and there are only about two points per cycle. So it's hard to see what's going on. If you plot your sine as a function of time, you get something ugly. (Actually it's kind of pretty, but ugly in this context). The following example uses a more suitable frequency and you can see peaks at +-f0.
N = 1000;
fs = 1000;
dt = 1/fs;
t = (0:N-1)*dt;
df = fs/N;
f = (-N/2:N/2-1)*df;
f0 = 20;
y = 2*sin(2*pi*f0*t);
figure(1)
plot(t,y)
z = fft(y)/N;
figure(2)
plot(f,fftshift(abs(z)))
ylim([0 1.2])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!