Difference of amplitude after FFT calculation
3 次查看(过去 30 天)
显示 更早的评论
The amplitude value obtained after FFT calculation is different from the amplitude of the original function.
I want to get the right amplitude value.
How can I get the right amplitude value?
Why does it make a difference?
clc
clear
close all
format long
t = 0:0.001:10;
y = 10*sin(2*pi()*10*t);
figure(1)
plot(t,y)
y_fft = fft(y);
f = (0:length(y)-1)/0.001/length(y);
figure(2)
semilogy(f,abs(y_fft))
xlim([0,100])
0 个评论
采纳的回答
David Goodmanson
2021-3-25
编辑:David Goodmanson
2021-3-25
Hi SO,
The y array consists of (supposedly) just one frequency, but aside from the scaling your plot shows spread-out frequency content. With correct scaling you could get close to the correct answer but it would never be quite right since there is energy outside of the main peak at f = 10. The reason is that the value of y(t) at t=0 and the value of y(t) at t=10 are both zero, so one point is repeated and you do not have a true periodic sine wave.
The code below omits the last point, t = 10. Then to scale the fft correctly in this situation, the fft is divided by the number of points. Ater that, you get two sharp spikes, at +10 Hz and at the fft version of -10 Hz (which appears in the upper half of the frequency array). The amplitude for each of those is exactly 5 as it should be. That's because of the factor of 2 in
sin(w*t) = ( exp(i*w*t)-exp(i*w*t) )/(2*i)
N = 1e4;
delt = 1e-3;
t = (0:N-1)*delt;
y = 10*sin(2*pi()*10*t);
figure(3)
plot(t,y)
y_fft = fft(y)/N;
f = (0:N-1)/(N*delt);
figure(4)
plot(f,abs(y_fft))
更多回答(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!