| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| 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 first element of y, corresponding to zero frequency, is the sum of the data in x. This DC component is often removed from y so that it does not obscure the positive frequency content of 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).)
Note Documentation example files for MATLAB mathematics are located in the \help\techdoc\math\examples subdirectory of your MATLAB root directory (matlabroot). This subdirectory is not on the MATLAB path at installation. To use the M-files in this subdirectory, either add the subdirectory to the MATLAB path (addpath) or make the subdirectory your current working directory (cd). |
If x is a vector,
fftgui(x)
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.
![]() | Fourier Transforms | Fast Fourier Transform (FFT) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |