MATLAB: Getting the amplitude back from FFT, how to

cosfftmagnitudesin

Hi everyone, I have a wave that is a sum of sines and cosines:
x = A*sin(wt * phi1) + B*cos(2w*t + phi2) + C*sin(2wt +phi3) and D*cos(wt +phi4). Now I use fft on x and get the magnitude with abs(fft(x)). How do I get A, B, C and D back? The reason behind this is that I am new to fft and I am trying to understand the output that Matlab fft gives back in depth. Thank you

Best Answer

hi Nina,
1) the fft(x) is Finite Fourier Transform, the computation is fast when n=length(x) is the product of powers of small primes.
2) Yes you can get the amplitudes A,B,C,D if Nyquist condition is met :
the sampling frequency Fs of your vector t must be At least >= 2*max(F)
3) In your case, x = A*sin(wt * phi1) + B*cos(2w*t + phi2) + C*sin(2wt +phi3)* D*cos(wt +phi4) you will see two bins A=D and B=C because the each two of them have the same frequencies 2*w and w :
Let is try now to compute the Onde sided amplitude spectrum :
Fs=400;
t=0:1/Fs:2-1/Fs;
A=10;
B=15;
C=22;
D=17.6;
phi=[2 4 1 5];
F=70; % 70Hz
omega=2*pi*F; % Angular velocity
x=A*sin(omega*t+phi(1))+B*cos(2*omega*t+phi(2))+C*sin(2*omega*t+phi(3))+D*cos(omega*t+phi(4));
figure, plot(t,x);
%Make FFT fast :
n=ceil(log2(length(x))); % Or you can use the function nextpow2
fx=fft(x,2^n);
fx=2*fx/length(x); % This operation is Adjusting the Magnitudes A,B,C,D
f=(Fs/2^n)*(0:2^(n-1)-1);
figure, plot(f,abs(fx(1:2^(n-1)))), xlabel(' Frequency (Hz)'), ylabel(' |F(y)|');
Now to visualize the four Magnitudes A,..D, we have to give to each wave a different frequency f=omega /2* pi, change the x in the code above with this as example w,2w,3w,4w:
x=A*sin(omega*t+phi(1))+B*cos(2*omega*t+phi(2))+C*sin(3*omega*t+phi(3))+D*cos(4*omega*t+phi(4));
I hope this helps .
if you want more details , try my submission :