*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*:

$${y}_{p+1}={\displaystyle \sum _{j=0}^{n-1}{\omega}^{jp}{x}_{j+1}}$$

where *ω* is a complex *n*th
root of unity:

$$\omega ={e}^{-2\pi i/n}$$

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/*f*_{s} or *ds* =
1/*f*_{s},
where *f*_{s} 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*(*f*_{s} / *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).)

Add the examples folder to your path for access to the function `fftgui`

.

addpath(fullfile(matlabroot,'/help/matlab/math/examples'))

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.

Was this topic helpful?