|On this page…|
Spectral analysis is the process of identifying component frequencies in data. For discrete data, the computational basis of spectral analysis is the discrete Fourier transform (DFT). The DFT transforms time- or space-based data into frequency-based data.
The DFT of a vector x of length n is another vector y of length n:
where ω is a complex nth root of unity:
This notation uses i for the imaginary unit, and p and j for indices that run from 0 to n–1. The indices p+1 and j+1 run from 1 to n, corresponding to ranges associated with MATLAB® vectors.
Data in the vector x are assumed to be separated by a constant interval in time or space, dt = 1/fs or ds = 1/fs, where fs is the sampling frequency. The DFT y is complex-valued. The absolute value of y at index p+1 measures the amount of the frequency f = p(fs / n) present in the data.
The documentation example function fftgui opens a graphical user interface that allows you to explore the real and imaginary parts of a data vector and its DFT. (Here fft refers to efficient computation of the DFT by the MATLAB fft function, as discussed in Fast Fourier Transform (FFT).)
Add the examples folder to your path for access to the function fftgui.
If x is a vector,
plots the real and imaginary parts of both x and its DFT (fft(x)). Use your mouse to drag points in any of the plots and the points in the other plots respond to the changes.
For example, use fftgui to display the DFT of a unit impulse at x(1):
x = [1 zeros(1,11)]; fftgui(x)
The transform is quite different if the unit impulse is at x(2):
x = [0 1 zeros(1,10)]; fftgui(x)
The following commands display DFTs of square and sine waves, respectively:
x = [ones(1,25),-ones(1,25)]; fftgui(x)
t = linspace(0,1,50); x = sin(2*pi*t); fftgui(x)
The midpoint of the DFT (or the point just to the right of the midpoint if the length is even), corresponding to half the sampling frequency of the data, is the Nyquist point. For real x, the real part of the DFT is symmetric about the Nyquist point, and the imaginary part is antisymmetric about the Nyquist point.