The discrete Fourier transform, or DFT, is the primary tool of digital signal processing. The foundation of the product is the fast Fourier transform (FFT), a method for computing the DFT with reduced execution time. Many of the toolbox functions (including z-domain frequency response, spectrum and cepstrum analysis, and some filter design and implementation functions) incorporate the FFT.
The MATLAB® environment provides the functions
compute the discrete Fourier transform and its inverse, respectively.
For the input sequence x and its transformed version X (the
discrete-time Fourier transform at equally spaced frequencies around
the unit circle), the two functions implement the relationships
In these equations, the series subscripts begin with 1 instead of 0 because of the MATLAB vector indexing scheme, and
The MATLAB convention is to use a negative j for
fft, with a single input argument,
computes the DFT of the input vector or matrix. If
fft computes the DFT of the vector; if
a rectangular array,
fft computes the DFT of each
For example, create a time vector and signal:
t = 0:1/100:10-1/100; % Time vector x = sin(2*pi*15*t) + sin(2*pi*40*t); % Signal
The DFT of the signal, and the magnitude and phase of the transformed sequence, are then
y = fft(x); % Compute DFT of x m = abs(y); % Magnitude p = unwrap(angle(y)); % Phase
To plot the magnitude and phase, type the following commands:
f = (0:length(y)-1)*100/length(y); % Frequency vector subplot(2,1,1) plot(f,m) title('Magnitude') ax = gca; ax.XTick = [15 40 60 85]; subplot(2,1,2) plot(f,p*180/pi) title('Phase') ax = gca; ax.XTick = [15 40 60 85];
A second argument to
fft specifies a number
n for the transform, representing DFT
n = 512; y = fft(x,n); m = abs(y); p = unwrap(angle(y)); f = (0:length(y)-1)*100/length(y); subplot(2,1,1) plot(f,m) title('Magnitude') ax = gca; ax.XTick = [15 40 60 85]; subplot(2,1,2) plot(f,p*180/pi) title('Phase') ax = gca; ax.XTick = [15 40 60 85];
In this case,
fft pads the input sequence
with zeros if it is shorter than
n, or truncates
the sequence if it is longer than
not specified, it defaults to the length of the input sequence. Execution
fft depends on the
n, of the DFT it performs;
fft for details about
The resulting FFT amplitude is
The inverse discrete Fourier transform function
ifft also accepts an input sequence
and, optionally, the number of desired points for the transform. Try
the example below; the original sequence
the reconstructed sequence are identical (within rounding error).
t = 0:1/255:1; x = sin(2*pi*120*t); y = real(ifft(fft(x)));
This toolbox also includes functions for the two-dimensional
FFT and its inverse,
ifft2. These functions are useful for
two-dimensional signal or image processing. The
goertzel function, which is another algorithm
to compute the DFT, also is included in the toolbox. This function
is efficient for computing the DFT of a portion of a long signal.
It is sometimes convenient to rearrange the output of the
so the zero frequency component is at the center of the sequence.
the zero frequency component to the center of a vector or matrix.