Clear Filters
Clear Filters

Getting the amplitude back from FFT, how to ?

31 views (last 30 days)
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

Accepted Answer

Youssef  Khmou
Youssef Khmou on 18 Feb 2013
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 :

More Answers (1)

Wayne King
Wayne King on 18 Feb 2013
By getting back do you mean finding the information in the Fourier domain? You have to know which DFT bin contains the frequency of interest
Fs = 100;
t = 0:1/Fs:1-1/Fs;
x = 1.5*cos(2*pi*10*t-pi/4);
xdft = fft(x);
Now the spacing in the frequency domain is Fs/N where N is the length of the signal, so 1 Hz in this case. Because the first DFT bin corresponds to 0 frequency, this means that 10 Hz is localized to DFT bin number 11.
tenHzcoef = xdft(11)/length(x);
angle(tenHzcoef) % this is the starting phase
2*abs(tenHzcoef) % the amplitude
  2 Comments
Nina
Nina on 18 Feb 2013
Thank Wayne, again :) but (and please excuse the stupid question) what exactly is a bin? also, could you please refer me to some good source where I can get information on fft (Google is good but I get lost on where to start). Thank again!
Wayne King
Wayne King on 18 Feb 2013
The discrete Fourier transform (DFT) uses a discrete set of frequencies. Don't get hung up on fft(), fft() is an algorithm, you want to understand the DFT.
Once you see the defining equation for the DFT, you'll see what set of frequencies the coefficients are associated with. Those are the DFT "bins".
There are so many good textbooks and sources to understand the DFT.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!