MATLAB Answers

Difference of amplitude after FFT calculation

23 ビュー (過去 30 日間)
show
show 2021 年 3 月 25 日
コメント済み: show 2021 年 3 月 29 日
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])

採用された回答

David Goodmanson
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))
  1 件のコメント
show
show 2021 年 3 月 29 日
Thank you for answering.
The problem has been resolved.

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by