CHAPTER 10 Fourier Analysis of Discrete-Time Signals and Systems
10.2 Discrete-Time Fourier Transform
10.2.3 Computation of the DTFT Using MATLAB
According to the definitions of the direct and the inverse DTFT, their computation needs to be done for a continuous frequencyω∈[−π,π)and requires integration. In MATLAB the DTFT is approxi- mated in a discrete set of frequency values, and summation instead of integration is used. As we will see later, this can be done by sampling in frequency the DTFT to obtain the discrete Fourier transform (DFT), which in turn is efficiently implemented by an algorithm called the Fast Fourier Transform (FFT). We will introduce the FFT in Chapter 12, and so for now consider the FFT as a black box capable of giving a discrete approximation of the DTFT.
To understand the use of the MATLAB functionfftin the script below consider the following issues:
n The commandX = fft(x), wherexis a vector with the entries the sample valuesx[n],n=0,. . .,L−1, computes the FFT valuesX[k],k=0,. . .,L−1, or the DTFTX(ejω)at discrete frequencies{2πk/L}.
n The{k}values correspond to the discretized frequencies{ωk=2πk/L}, which go from 0 to 2π(L− 1)/L(close to 2πfor largeL). This is a discretization of the frequencyω∈[0, 2π).
n To find an equivalent representation of the frequencyω∈[−π, π), we simply subtractπ from ωk =2πk/Lto get a band of frequencies,
ω˜k =ωk−π =π2k−L
L , k=0,. . .,L−1 or −π ≤ ˜ωk< π
The frequencyω˜ can be normalized to [−1, 1)with no units by dividing byπ. This change in the frequency scale requires a corresponding shift of the magnitude and the phase spectra. This is done by means of the MATLAB functionfftshift.
n When plotting the signal, which is discrete in time, the functionstemis more appropriate than plot. However, the plotfunction is more appropriate for plotting the magnitude and the phase frequency response functions, which are supposed to be continuously varying with respect to frequency.
n The functionabs computes the magnitude and the function angle computes the phase of the frequency response. The magnitude and the phase are even and odd symmetric when plotted in ω∈[−π,π)or in the normalized frequencyω/π ∈[−1, 1).
The three signals in the following script are a rectangular pulse, a windowed sinusoid, and a chirp. In the script, to process one of the signals you delete the corresponding comment % and keep it for the other two. The length of the FFT is set toL=256, which is larger or equal to the length of either of the three signals.
%%%%%%%%%%%%%%%%%%%%%%
% DTFT of aperiodic signals
%%%%%%%%%%%%%%%%%%%%%%
% signals
L = 256; % length of FFT with added zeros
% N = 21; x = [ones(1,N) zeros(1,L - N)]; % pulse
% N = 200; n = 0:N - 1; x = [cos(4∗pi∗n/N) zeros(1,L - N)]; % windowed sinusoid n = 0:L - 1; x = cos(pi∗n. ˆ 2/(4∗L)); % chirp
X = fft(x);
w = 0:2∗pi/L:2∗pi - 2∗pi/L;w1 = (w - pi)/pi; % normalized frequency n = 0:length(x) - 1;
subplot(311)
stem(n,x); axis([0 length(n) - 1 1.1∗min(x) 1.1∗max(x)]); grid;
xlabel(‘n’); ylabel(‘x(n)’) subplot(312)
plot(w1,fftshift(abs(X))); axis([min(w1) max(w1) 0 1.1∗max(abs(X))]);
ylabel(‘|X|’); grid subplot(313)
plot(w1,fftshift(angle(X))); ylabel(‘<X’); xlabel(‘ω/π’); grid axis([min(w1) max(w1) 1.1∗min(angle(X)) 1.1∗max(angle(X))])
As expected, the magnitude spectrum for the rectangular pulse is like a sinc. The windowed sinusoid has a spectrum that resembles that of the sinusoid but the rectangular window makes it broader.
Finally, a chirp is a sinusoid with time-varying frequency; thus its magnitude spectrum displays com- ponents over a range of frequencies. We will comment on the phase spectra later. The results are shown in Figure 10.1.
Sampled Signals
When computing the DTFT of a sampled signal, it is important to display the frequency in radi- ans/second or in hertz rather than the discrete frequency in radians. The discrete frequencyω(rad) is converted into the analog signal (rad/sec) according to the relation ω=Ts whereTs is the sampling period used. Thus,
=ω/Ts rad/sec (10.13)
If the signal is sampled according to the Nyquist sampling rate condition, the discrete-frequency rangeω∈[−π, π)(rad) corresponds to∈[−π/Ts, π/Ts)or [−s/2, s/2), wheres/2≥max
10.2 Discrete-Time Fourier Transform 579
0 10 20 30 40 50 60 70 80 90 100
0 0.5 1
n
x[n]
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 0
10 20
|X(ejω)|
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8
−2 0 2
<X(ejω)
(a) (b)
0 20 40 60 80 100 120 140 160 180 200
−1 0 1
n
x(n)
x(n)
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 0
20 40 60 80
|X(ejω)|
|X(ejω)|
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8
−2 0 2
<X(ejω)
<X(ejω)
(c)
0 10 20 30 40 50 60 70 80 90 100
−1 0 1
n
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 0
10 20
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8
−2 0 2
ω/π
ω/π ω/π
FIGURE 10.1
MATLAB computation of the DTFT of (a) a pulse, (b) a windowed sinusoid, and (c) a chirp: magnitude and phase spectra are shown for each.
fors the sampling frequency in radians/second andmax the maximum frequency in the signal being sampled.
To illustrate this, we sampled a signalx(t)=5−2tu(t)withTs=0.01 sec/sample, created a vector of 256 values from the signal, and computed its FFT as before. The above script is modified to consider the change of scale. The changes are as follows:
%%%%%%%%%%%%%%%%%%%%%
% DTFT of sampled signal
%%%%%%%%%%%%%%%%%%%%%
L = 256;Ts = 0.01; t = 0:Ts:(L - 1)∗Ts; x = 5.ˆ( - 2∗t); % sampling of signal X = fft(x);
w = 0:2∗pi/L:2∗pi - 2∗pi/L;W = (w - pi)/Ts; % W is analog frequency
FIGURE 10.2 DTFT of (a) a sampled signal, and (b) the magnitude of DTFT and (c) the phase of DTFT as functions of(rad/sec).
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.2 0.4 0.60.81
nTs(sec) x(nTs)
−300 −200 −100 0 100 200 300
0 20
|X(ejΩTs)|
−300 −200 −100 0 100 200 300
−1 0 1
<X(ejΩTs)
Ω (rad /sec) (a)
(b)
(c)
The results are shown in Figure 10.2. Given that the signal is very smooth, most of the frequency components have low frequencies.