MATLAB Answers

# Difference of amplitude after FFT calculation

1 view (last 30 days)
show on 25 Mar 2021
Commented: show on 29 Mar 2021
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 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

David Goodmanson on 25 Mar 2021
Edited: David Goodmanson on 25 Mar 2021
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 CommentShowHide None
show on 29 Mar 2021
Thank you for answering.
The problem has been resolved.

Sign in to comment.

R2020b

### Community Treasure Hunt

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

Start Hunting!