CHAPTER 10 Fourier Analysis of Discrete-Time Signals and Systems
10.4.3 Computation of the DFT via the FFT
Although we now have discrete frequencies and use only summations to compute the direct and the inverse DFT, there are still several issues that should be understood when computing these trans- forms. Assuming that the given signal is finite length, or it is made finite length by windowing, we have:
n Efficient computation with the FFT algorithm:A very efficient computation of the DFT is done by means of the FFT algorithm, which takes advantage of some special characteristics of the DFT, as we will discuss in Chapter 12. It should be understood that the FFT is not another transformation but an algorithm to efficiently compute DFTs. For now, we will consider the FFT as a black box that for an inputx[n] (orX[k]) gives as output the DFTX[k] (or IDFTx[n]).
n Causal aperiodic signals:If the given signalx[n] is causal of lengthN—that is, the samples {x[n], n=0, 1,. . .,N−1}
are given—we can proceed to obtain{X[k], k=0, 1,. . .,N−1}or the DFT ofx[n] by means of an FFT of lengthL=N. To compute anL>NDFT we simply attachL−Nzeros at the end of the
above sequence and obtainLvalues corresponding to the DFT ofx[n] of lengthL(why this could be seen as a better version of the DFT ofx[n] is discussed below in frequency resolution).
n Noncausal aperiodic signals: When the given signal x[n] is noncausal of length N—that is, the samples
{x[n], n= −n0,. . ., 0, 1,. . .,N−n0−1}
are given—we need to recall that a periodic extension ofx[n] orx[n] was used to obtain its DFT.˜ This means that we need to create a sequence ofNvalues corresponding to the first period of
˜
x[n]—that is,
x[0]x[1] ã ã ãx[N−n0−1]
| {z }
causal samples
x[−n0]x[−n0+1]ã ã ãx[−1]
| {z }
noncausal samples
where as indicated the samplesx[−n0] x[−n0+1]ã ã ãx[−1] are the values that make x[n] non- causal. If we wish to consider zeros afterx[N−n0−1] to be part of the signal, so as to obtain a better DFT transform as we discuss later in frequency resolution, we simply attach zeros between the causal and noncausal components—that is,
x[0]x[1] ã ã ãx[N−n0−1]
| {z }
causal samples
0 0 ã ã ã 0 0 x[−n0]x[−n0+1]ã ã ãx[−1]
| {z }
noncausal samples
to compute an L>N DFT of the noncausal signal. The periodic extension ˜x[n] represented circularly instead of linearly would clearly show the above sequence.
n Periodic signals:If the signalx[n] is periodic of periodNwe will then chooseL=N(or a multiple ofN) and calculate the DFTX[k] by means of the FFT algorithm. If we use a multiple of the period (e.g.,L=MNfor some integerM>0), we need to divide the obtained DFT by the valueM. For periodic signals we cannot chooseLto be anything but a multiple ofNas we are really computing the Fourier series of the signal. Likewise, no zeros can be attached to a period (or periods when M>1) to improve the frequency resolution of its DFT—by attaching zeros to a period we distort the signal.
n Frequency resolution:When the signalx[n] is periodic of periodN, the DFT values are normalized Fourier series coefficients ofx[n] that only exist for the harmonic frequencies{2πk/N}, as no fre- quency components exist for any other frequencies. On the other hand, whenx[n] is aperiodic, the number of possible frequencies depend on the lengthLchosen to compute its DFT. In either case, the frequencies at which we compute the DFT can be seen as frequencies around the unit cir- cle in thez-plane. In both cases one would like to have a significant number of frequencies in the unit circle so as to visualize the frequency content of the signal well. The number of frequencies considered is related to thefrequency resolutionof the DFT of the signal.
n If the signal is aperiodic we can improve the frequency resolution of its DFT by increasing the number of samples in the signal without distorting the signal. This can be done bypadding the signal with zeros(i.e., attaching zeros to the end of the signal). These zeros do not change the frequency content of the signal (they can be considered part of the aperiodic signal) but permit us to increase the available frequency components of the signal.
10.4 Discrete Fourier Transform 619
n On the other hand, the harmonic frequencies of a periodic signal of periodNare fixed to 2πk/Nfor 0≤k<N. In such a case we cannot pad the given period of the signal with an arbitrary number of zeros, because such zeros are not part of the periodic signal. As an alter- native, to increase the frequency resolution of a periodic signal we consider more periods which give the same harmonic frequencies as for one period, but add zeros in between the harmonic frequencies when considering more than one period.
n Frequency scales: When computing the DFT we obtain a sequence of complex values X[k] for k=0, 1,. . .,N−1 corresponding to an input signal x[n] of length N. Since each of the kval- ues corresponds to a discrete frequency 2πk/Nthe k=0, 1,. . .,N−1 scale is converted into a discrete frequency scale [0 2π(N−1)/N] (rad) (the last value is always smaller than 2πto keep the periodicity in frequency ofX[k]) by multiplying the integer scale{0≤k≤N−1}by 2π/N.
Subtractingπ to this frequency scale we obtain discrete frequencies [−π π−2π/N] (rad) where again the last frequency does not coincide withπ in order to keep the periodicity of 2π of the X[k]. We obtain a normalized discrete-frequency scale by dividing the above scale byπ so as to obtain a nonunits normalized scale of [0 1−2(N−1)/N] or [−1 1−2/N]. Finally, if the signal is the result of sampling and we wish to display the analog frequency, we then use the relation whereTsis the sampling period andfsis the sampling frequency:
= ω
Ts =ωfs(rad/sec) or f = ω
2πTs =ωfs
2π (Hz) (10.54)
giving analog scales [0 πfs] (rad/sec) and [0 fs/2] (Hz).
nExample 10.20
Consider the DFT computation via the FFT of a causal signalx[n]=(sin(πn/32))(u[n]−u[n−34]) and of its advanced versionx[n+16]. To improve its frequency resolution compute FFTs of length N=512. Explain the difference between computing the FFTs of the causal and the noncausal signals.
Solution
As indicated above, when computing the FFT of a causal signal the signal is simply inputted into the function. However, to improve the frequency resolution of the FFT we attach zeros to the signal.
These zeros make it possible to have additional values of the frequency response of the signal, with no effect on the frequency content of the signal.
For the noncausal signalx[n+16], we need to recall that the DFTs of an aperiodic signal were computed by extending the signal into a periodic signal with an arbitrary periodN, which exceeds the length of the signal. Thus, the periodic extension ofx[n+16] can be obtained by creating an input vector consisting ofx[n],n=0,. . ., 16;N−33 zeros (Nbeing the length of the FFT and 33 the length of the signal) to improve the frequency resolution, andx[n],n= −16,. . .,−1.
In either case, the output of the FFT is available as an array of lengthN=512 values. This array X[k],k=0,. . .,N−1 can be understood as values of the spectrum at frequencies 2πk/N—that is,
from 0 to 2π(N−1)/Nrad (notice that this value is close to 2π but always smaller than 2π as needed to display a period of X[k]). We can change this scale into other frequency scales—for instance, if we wish a scale that considers positive as well as negative frequencies, to the above scale we subtractπ, and if we wish a normalized scale [−1 1), we simply divide the previous scale byπ. When shifting to a [−π π)or [−1 1)frequency scale, the spectrum also needs to be shifted accordingly—this is done using thefftshift function. To understand this change recall thatX[k] is also periodic of periodN.
The following script is used to compute the DFT ofx[n] andx[n+16] given above. The results are shown in Figure 10.14.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example 10.20---FFFT computation of causal and
% noncausal signals
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; clf
N = 512; % order of the FFT n = 0:N - 1;
% causal signal
x = [ones(1,33) zeros(1,N - 33)]; x = x.∗sin(pi∗n/32); % zero-padding X = fft(x); X = fftshift(X); % fft and its shifting to [-1 1] frequency scale w = 2∗[0:N - 1]./N - 1; % normalized frequencies
n1 = [-9:40]; % time scale
% noncausal signal
xnc = [zeros(1,3) x(1:33) zeros(1,3)]; % noncausal signal
x = [x(17:33) zeros(1,N-33) x(1:16)]; % periodic extension and zero-padding X = fft(x); X = fftshift(X);
n1 = [-19:19]; % time scale
n
nExample 10.21
Consider improving the frequency resolution of a periodic sampled signal y(nTs)=4 cos(2πf0nTs)−cos(2πf1nTs) f0=100 Hz,f1 =4f0
where the sampling period isTs=1/(3f1)sec/sample.
Solution
In the case of a periodic signal, the frequency resolution of its FFT cannot be improved by attaching zeros. The length of the FFT must be the period or a multiple of the period of the signal. The following script illustrates how the FFT of the given periodic signal can be obtained by using 4 or 12 periods. As the number of periods increases the harmonic components appear in each case at exactly the same frequencies, and only zeros in between these fixed harmonic frequencies result from increasing the number of periods. However, the magnitude frequency response is increasing
10.4 Discrete Fourier Transform 621
FIGURE 10.14 Computation of the FFT of (a) a causal signal and (b) a noncausal signal. Notice that as expected the magnitude responses are
equal—only the phase responses change.
(a)
(b) x1[n]x[n]
−200 −15 −10 −5 0 5 10 15 20
0.5 1 0 0.5 1
n
|X1(ejω)||X(ejω)|
0 5 10 15 5 10 15
20 25
−1 0
−0.5 0 0.5 1
ω/π
−1 −0.5 0 0.5 1
ω/π
−4
−2 0 2 4
<X1(ejω)
−1 −0.5 0 0.5 1 1
ω/π
−1 −0.5 0 0.5
−4
−2 0 2 4
ω/π
<X(ejω)
−5
−10 0 5 10 15 20 25 30 35 40
n
as the number of periods increases. Thus, we need to divide by the number of periods used in computing the FFT.
Since the signal is sampled, it is of interest to have the frequency scale of the FFTs in hertz, so we convert the discrete frequencyω(rad) intof (Hz) according to
f = ω
2πTs = ωfs 2π
where fs=1/Ts is the sampling rate given in samples/second. The results are shown in Figure 10.15.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example 10.21---Improving frequency resolution of FFFT of periodic signals
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f0 = 100; f1 = 4∗f0; % frequencies in Hz of signal Ts = 1/(3∗f1); % sampling period
t = 0:Ts:4/f0; % time for 4 periods
y = 4∗cos(2∗pi∗f0∗t) - cos(2∗pi∗f1∗t); % sampled signal (4 periods) M = length(y);
Y = fft(y,M); Y = fftshift(Y)/4; % fft using 4 periods, shifting and normalizing t1 = 0:Ts:12/f0; % time for 12 periods
y1 = 4∗cos(2∗pi∗f0∗t1) - cos(2∗pi∗f1∗t1); % sampled signal (12 periods) Y1 = fft(y1);Y1 = fftshift(Y1)/12; % fft using 12 periods, shifting and normalizing w = 2∗[0:M - 1]./M - 1;f = w/(2∗Ts); % frequency scale (4 periods)
N = length(y1);
w1 = 2∗[0:N - 1]./N - 1;f = w/(2∗Ts); % frequency scale (12 periods) n