FFT magnitude

Thread Starter

jut

Joined Aug 25, 2007
224
I wrote some code in Matlab to do a simple FFT on a sine wave. How does one interpret the amplitude?



Rich (BB code):
% FFT
fs=10     % sampling frequency
x=sin(2*pi*[0:1/fs:10]);      % frequency of signal is 1Hz
N=131072
X = abs(fft(x,N));
F = fs*[0:N-1]/N;
figure
plot(F,X)
xlabel('Hz')
ylabel('I never remember what the magnitude in a FFT means...ehh')
legend(sprintf('sampling frequency = %d Hz',fs))
axis([0 fs/2 0 max(X)*1.1])
 

kevinarms

Joined Jun 29, 2011
6
The FFT is a way of breaking down a signal into its frequency components. So if you created individual sinusoidal waves of each frequency present in the FFT, and each had an amplitude and phase shift given by the FFT for that frequency, then you could sum them up to get your original signal (which is basically what a fourier series is).

Basically, the magnitude of the FFT is the amplitude of the associated frequency component.

When you're using the FFT function in MATLAB you probably also want to use the fftshift function to center the results around 0.

Hope that helps.
 

MrChips

Joined Oct 2, 2009
30,802
Here are some points to note:

In your example, your input is not a sine wave. Because N = 131072 is larger than the number of points in x, this is a windowed sine.

Your magnitude is 50 because you are forgetting to normalise the result of the FFT, i.e. you should divide by N. For a full sinewave your amplitue would be 0.5

Why 0.5?

Because you are plotting only one half of the spectrum. Don't forget the negative frequencies!
 
Last edited:

Thread Starter

jut

Joined Aug 25, 2007
224
Here are some points to note:

In your example, your input is not a sine wave. Because N = 131072 is larger than the number of points in x, this is a windowed sine.

Your magnitude is 50 because you are forgetting to normalise the result of the FFT, i.e. you should divide by N. For a full sinewave your amplitue would be 0.5

Why 0.5?

Because you are plotting only one half of the spectrum. Don't forget the negative frequencies!
If I divide 50 by 131072, that would be tiny! 0.0003814! My input sine wave has a magnitude of 1.
 

davebee

Joined Oct 22, 2008
540
The Fourier transform (and the fft) break a signal down into phase as well as frequency.

The term magnitude usually means the square root of the sum of the squares of both the sine (real) part and the cosine (imaginary) parts.

This will be equivalent to the amplitude of the sine part if the imaginary part is zero, but it would not really be correct to consider just the sine part of a signal to be the magnitude.
 

Barnaby Walters

Joined Mar 2, 2011
102
I have never understood how a FFT shows phase (all I have ever used them for is tuning a circuit to a particular frequency) — could someone explain please?

Also, am I right in thinking that the FFT of a 'pure' sine wave would only have one peak, i.e. no harmonics?

Thanks,
Barnaby
 

MrChips

Joined Oct 2, 2009
30,802
I have never understood how a FFT shows phase (all I have ever used them for is tuning a circuit to a particular frequency) — could someone explain please?

Also, am I right in thinking that the FFT of a 'pure' sine wave would only have one peak, i.e. no harmonics?

Thanks,
Barnaby
Please do not hijack someone else's post. Your question is a new topic.
For now I will oblige and answer your questions.

The FFT converts the time signal into its frequency components (in our context, but note that the FFT can be used for many other applications other than electrical signals).

The results of the FFT will contain two components, the sine component and the cosine component. Another way of looking at this is it is a complex number consisting of a real component and an imaginary component such as x + iy. (Electrical Engineers use x +jy).

The ratio of the two components (y/x) gives you the phase angle of that sine wave, i.e. tan(phase angle) = y/x.

Hope this helps.

Also, am I right in thinking that the FFT of a 'pure' sine wave would only have one peak, i.e. no harmonics?
Yes, a 'pure' sinewave would have one peak.

(Sorry, I just noticed that other posters brought up the point about "phase".
If you wish to continue discussing the Original Post I would be happy to respond.)
 
Last edited:

Barnaby Walters

Joined Mar 2, 2011
102
Please do not hijack someone else's post. Your question is a new topic.
For now I will oblige and answer your questions. (Sorry, I just noticed that other posters brought up the point about "phase".
If you wish to continue discussing the Original Post I would be happy to respond.)
Yep, sorry about that. If others hadn't mentioned phase shift I would not have known that FFTs showed it.

Thanks,
Barnaby
 
Top