Obtaining amplitude values from an FFT

Hi there, I have made a single-sided spectrum using FFT of a time-domain signal. From that FFT, I would like to somehow get the amplitude at each of the frequencies from the signal.
If I am outputting an FFT that looks like the attached plot, which has about 4 distinct peaks, what should I do with this plot to get amplitude? I got it using
S = fft(eta)
P2 = abs(S/nFFT);
Where nFFT is the number of sampling points and eta is a time-domain signal.

 Accepted Answer

To get the _correct) amplitudes for a one-sided fft, you need to change your code to:
S = fft(eta)/nFFT;
P2 = abs(S)*2;
Then plot ‘P2’.
The reason is that the total energy in the signal is conserved in the total fft, that, because it is symmetric, will have half the energy at the positive frequency and half at the negative. You have to multiply the amplitudes of the one-sided fft by 2 to plot the correct amplitudes.
The units of the Fourier-transformed amplitudes (using the code I changed) are the same units as the original signal.
For a full discussion, see the R2015a documentation for fft (link).

6 Comments

Hi,
Thanks a lot for this. These details relating to bins, etc have been confusing me (even after several readings of the matlab documentation) but I did that and the number on the y-axis look maybe more what I would expect. For instance, if this is the FFT of a wave, where the amplitude changes over time and then the plot (after making the changes you suggested) is attached here, would the peaks correspond to the amplitude (y axis)? I think I'm mostly confused about what the units of the y-axis are so I can extract the individual amplitude data.
My pleasure.
The Fourier transform will give you the mean amplitude of a signal at each frequency in the entire time-domain signal. If the amplitude at a particular frequency varies, the Fourier transform will still be the mean amplitude at each frequency. It will not show any of the variation.
The amplitude of the Fourier transform as calculated here are in the same units as the original time-domain signal. So if your original signal was in volts, the Fourier transform amplitudes will be in volts, and the same for other units.
If you have a signal with time-varying signal amplitudes (for example an amplitude-modulated signal) and want to see the time-varying Fourier transform of it, use the spectrogram function. Although I usually just use the default options, it has a number of options to experiment with to produce the result you want.
The Fourier transform, its properties, and interpreting its results are not as straightforward as some other concepts. It took me time to understand and be comfortable with them, and I still go back to my references. The documentation is good (I still prefer the R2015a documentation for the fft), but it is intended to support the functions it documents, not be an exhaustive discussion. If you are beginning with signal analysis and processing, I suggest a good signal processing text, such as the text by Proakis, to understand the Fourier transform. There are also entire books that discuss the Fourier transform and its applications.
Hmm I thought I sent a reply to this but I'm not seeing it now.. what a pain.. Anyway, thanks a lot for this answer. It's really helpful and much clearer than other answers I've had! Fourier transforms are one of those areas that I've spent a lot of time deriving and working on, but when actually needing to apply it, I'm realising that I'm sort of missing a fundamental understanding of its application.
Ok so here's a final question: let's say I want to see the spatial variation of the frequency of amplitude. The signal I have here is the surface elevation in metres as a wave travels along a distance. From what you are saying here that FFT doesn't show a variation, this leads me to understand that an FFT will not actually give me the variation of the amplitude (in metres) of the four highest harmonics (shown by the four peaks in the FFT) of the signal. What I would ultimately like to do is decompose this signal into its four harmonics and plot the harmonics over the length of the domain. Do you know if the fft the right way to go about doing this?
I know well the difference between understanding the Fourier transform from a theoretical perspective, then applying it to real-world sampled signals. The continuous-time theory is easier, especially with the Symbolic Math Toolbox to do the (error-free) integration. Sampled signals have their own characteristics, such as being finite so having to deal with the truncation of an infinite series, and having a finite frequency resolution (up to and including the Nyquist frequency, but not beyond it).
The fft will give you the actual mean amplitude. The spectrogram function will give you the time-varying amplitude. I would experiment with it. I usually use the default options, at least at first, and ‘tweak’ it as necessary to get the time resolution I want.
An alternative approach would be to use the Signal Processing Toolbox demod function to isolate the modulating waveform from each of the four ‘carrier’ frequencies you want to plot. Then, the ribbon plot might be an option to plot them as a function of time.
Hi Star rider,
Could you plz help me with interpreting this FFT figure. this is the Fourier transform of a small scale fading component (comming from not periodic signal). The Y axis is the abs of the normalized amplitude.
"These details relating to bins, etc have been confusing me..."
In particular, note there is only one (1) DC and one (1) Fmax bin so when take the double-sided FFT frequencies, do NOT double those two. The example of a one-sided PSD in the documentation accounts for this but is sadly lacking in a comment as to why the specific subscripting...
P1(2:end-1) = 2*P1(2:end-1);
but that's why the initial "2" and the "end-1" in the above; exclude doubling the energy in those two bins that's already fully accounted for.
Often there's little energy in Fmax if the input signal is, as should be, oversampled and the data collection system uses anti-aliasing filters so doubling it often is undetected and doesn't make any practical difference. OTOH, if there's any DC in the signal and/or the mean isn't subtracted from the signal before FFT, then the DC component can be large and when/if doubled really distort the resulting appearance.
Of course, it's stil just the DC component, but can be confusing and will definitely screw up the overall energy if not properly accounted for.

Sign in to comment.

More Answers (1)

If have Signal Processing toolbox, see
doc findpeaks
Otherwise, peaks cannot be found easily simply by comparing values. Use trend data to identify peak locations. A peak happens when the slope sign changes from +ive to -ive, i.e., a peak is where the difference changed from a streak of positives and/or zeros to negative. In your sample, peaks are quite well defined and not very noisy at all; this won't be terribly difficult.
I'm sure there are some peak-finding routines to be found on File Exchange if you don't have the SP Toolbox that could save some effort but I don't have a direct link at hand.

2 Comments

[Moved from Answer to Comment--dpb]
Hi dbp,
Thanks for your answer. Ok I've used findpeaks before but then I was confused when using it how to know what the units are or how to output an actual amplitude value. Can you offer any advice on this?
Thanks!
Not sure why the confusion??
>> help findpeaks
findpeaks Find local peaks in data
PKS = findpeaks(X) finds local peaks in the data vector X. ...
[PKS,LOCS]= findpeaks(X) also returns the indices LOCS at which the peaks occur.
...
The value(s) of the peak(s) is(are) the default return; you can also find where to look up frequency from the second index optional return.
The magnitude is dependent upon the units of the signal you passed into fft and how you normalized it.
It is peculiar how you got a one-sided spectrum looking like the attached figure from the code snippet posted; I presumed that was not the actual code but only a partial outline or the figure isn't that you actually have but from some other source???
There's an example in
doc fft
of the normalization and how to get the one-sided PSD from the full 2-sided transform.
A detailed analysis of the relationships is found at <introduction-to-communication-control-and-signal-processing_chap10.pdf>

Sign in to comment.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Asked:

on 6 Oct 2016

Commented:

dpb
on 17 Mar 2020

Community Treasure Hunt

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

Start Hunting!