To compute the Discrete-Time Fourier Transform (DTFT) of a signal in Matlab, you can use the fft
function. However, since the DTFT is a continuous function of frequency, it cannot be represented by a finite number of samples. Therefore, the fft
function in Matlab computes a sampled version of the DTFT.
The basic syntax for computing the DTFT in Matlab is:
main.m12 chars2 lines
where x
is the input signal and X
is the output DTFT. By default, fft
computes the DTFT for frequencies ranging from 0 to 2*pi
in steps of 2*pi/N
, where N
is the length of the input signal x
. To shift the frequency range to be centered at zero, you can use the fftshift
function as follows:
main.m25 chars2 lines
This will move the zero-frequency component of the DTFT to the center of the output vector X_shifted
.
Here is an example of computing the DTFT of a simple sine wave:
main.m445 chars16 lines
This will generate a plot showing the magnitude and phase of the DTFT of the sine wave.
gistlibby LogSnag