Advanced Digital Signal Processing Ch2
Advanced Digital Signal Processing Ch2
College of Engineering
Department of Electrical Engineering
Second Term
Ph.D. Course for Electronics & Communications
By
Prof. Dr. Ehab A. Hussein
Chapter (2)
Discrete Fourier Transform and Signal Spectrum
Objectives:
This chapter investigates Discrete Fourier
transform (DFT) and Fast Fourier Transform (FFT)
and their properties; introduces the DFT/FFT algorithms
to compute signal amplitude spectrum and power
spectrum; and uses the window function to reduce spectral
leakage. Finally, the chapter describes the FFT algorithm
and shows how to apply it to estimate a speech spectrum.
10
Figure .4: Periodic digital signal. Prof. Dr. Ehab
Example .1:
Choosing the duration of one period, N = 4, we have the sample values as follows:
x(0) = 0; x(1) = 1; x(2) = 0; and x(3) = -1.
Using Equation above,
1 3 1 1
𝑐0 = 𝑛=0 𝑥 𝑛 = (𝑥 0 + 𝑥 1 + 𝑥 2 + 𝑥(3))= 0+1+0−1 =0
4 4 4
3
1 1 −
𝑗𝜋
−
𝑗3𝜋
𝑐1 = 𝑥 𝑛 𝑒 −𝑗2𝜋𝑛/4 = (𝑥 0 + 𝑥 1 𝑒 2 + 𝑥 2 𝑒 −𝑗𝜋 +𝑥 3 𝑒 2 )
4 4
𝑛=0
1
= 𝑥 0 − 𝑗𝑥 1 − 𝑥 2 + 𝑗𝑥(3) = 0 − 𝑗 1 − 0 + 𝑗 −1 = −𝑗0.5.
4
Similarly, we get
3 3
1 1
𝑐2 = 𝑥 𝑛 𝑒 −𝑗2𝜋2𝑛/4 = 0, 𝑎𝑛𝑑 𝑐3 = 𝑥 𝑛 𝑒 −𝑗2𝜋3𝑛/4 = 𝑗0.5.
4 4
𝑛=0 𝑛=0
Using periodicity, it follows that:
c-1 = c3 = j0.5, and c-2 = c2 = 0.
11
Prof. Dr. Ehab
Example .1:
b. The amplitude spectrum for the digital signal is sketched in Figure .5.
As we know, the spectrum in the range of -2 to 2 Hz presents the
information of the sinusoid with a frequency of 1 Hz and a peak value of
2|c1|=1, which is converted from two sides to one side by doubling the
spectral value. Note that we do not double the direct-current (DC)
component, that is, c0.
18
Prof. Dr. Ehab
Example. 3:
This example actually verifies the inverse DFT. Applying the MATLAB function ifft() achieves:
≫ x =ifft([10 -2+2j -2 -2-2j])
x=1 2 3 4
Now we explore the relationship between the frequency bin k and its associated frequency.
Omitting the proof, the calculated N DFT coefficients X(k) represent the frequency
components ranging from 0 Hz (or radians/second) to fs Hz (or ws radians/second), hence we
can map the frequency bin k to its corresponding frequency as follows:
𝑘𝜔𝑠
𝜔= 𝑟𝑎𝑑𝑖𝑎𝑛𝑠 𝑝𝑒𝑟 𝑠𝑒𝑐𝑜𝑛𝑑 ,
𝑁
𝒌𝒇𝒔
or in terms of Hz, 𝒇= 𝑯𝒛 .
𝑵
where ws = 2pfs.
We can define the frequency resolution as the frequency step between two consecutive DFT
coefficients to measure how fine the frequency domain presentation is and achieve:
𝝎𝒔
∆𝝎 = 𝒓𝒂𝒅𝒊𝒂𝒏𝒔 𝒑𝒆𝒓 𝒔𝒆𝒄𝒐𝒏𝒅 ,
𝑵
𝒇𝒔
or in terms of Hz, it follows that: ∆𝒇 = 𝑯𝒛 .
𝑵
Let us study the following example.
19
Prof. Dr. Ehab
Example. 4:
In Example .2, given a sequence x(n) for 0 n 3, where x(0) = 1, x(1) = 2,
x(2) = 3, and x(3) = 4, we have computed four DFT coefficients X(k) for
0 k 3 as X(0) = 10, X(1) = -2+j2, X(2) = -2, and X(3) = -2-j2. If the
sampling rate is 10 Hz,
a. Determine the sampling period, time index, and sampling time instant for a
digital sample x(3) in time domain.
b. Determine the frequency resolution, frequency bin number, and mapped
frequency for each of the DFT coefficients X(1) and X(3) in frequency
domain.
Solution:
a. In time domain, we have the sampling period calculated as
T = 1/fs = 1/10 = 0.1 second.
For data x(3), the time index is n = 3 and the sampling time instant is
determined by:
t = nT = 30.1 = 0.3 second.
20
Prof. Dr. Ehab
Example. 4:
b. In frequency domain, since the total number of DFT coefficients is four, the
frequency resolution is determined by:
𝒇𝒔 𝟏𝟎
∆𝒇 = = = 𝟐. 𝟓 𝑯𝒛.
𝑵 𝟒
The frequency bin number for X(1) should be k = 1 and its corresponding
frequency is determined by:
𝑘𝑓𝑠 1×10
𝑓= = = 2.5 𝐻𝑧.
𝑁 4
𝑘𝑓𝑠 3×10
Similarly, for X(3) and k = 3, 𝑓= = = 7.5 𝐻𝑧.
𝑁 4
21
Prof. Dr. Ehab
2.2 Amplitude Spectrum and Power Spectrum
One of the DFT applications is transformation of a finite-length digital
signal x(n) into the spectrum in frequency domain. Figure.7 demonstrates such
an application, where Ak and Pk are the computed amplitude spectrum and the
power spectrum, respectively, using the DFT coefficients X(k).
First, we achieve the digital sequence x(n) by sampling the analog signal
x(t) and truncating the sampled signal with a data window with a length T0=NT,
where T is the sampling period and N the number of data points. The time for
data window is: T0=NT.
22
Figure.7: Applications of DFT/FFT. Prof. Dr. Ehab
2.2 Amplitude Spectrum and Power Spectrum
For the truncated sequence x(n) with a range of n = 0, 1, 2, . . . , N-1, we get:
x(0), x(1), x(2), . . . , x(N-1).
Next, we apply the DFT to the obtained sequence, x(n), to get the N
DFT coefficients:
𝑁−1
23
Prof. Dr. Ehab
2.2 Amplitude Spectrum and Power Spectrum
We can modify the amplitude spectrum to a one-sided amplitude
spectrum by doubling the amplitudes in Equation above, keeping the original
DC term at k = 0. Thus we have:
1
𝑋(0) , 𝑘 = 0.
𝐴𝑘 = 𝑁
2
𝑋(𝑘) , 𝑘 = 1, … , 𝑁/2.
𝑁
We can also map the frequency bin k to its corresponding frequency as:
𝑘𝑓𝑠
𝑓= .
𝑁
Correspondingly, the phase spectrum is given by:
−1
𝐼𝑚𝑎𝑔,𝑋(𝑘)-
𝜑𝑘 = tan , 𝑘 = 0,1,2, … , 𝑁 − 1.
𝑅𝑒𝑎𝑙,𝑋(𝑘)-
Besides the amplitude spectrum, the power spectrum is also used. The DFT
power spectrum is defined as:
1 2
1 2 2
𝑃𝑘 = 2 𝑋(𝑘) = 2 𝑅𝑒𝑎𝑙,𝑋 𝑘 - + 𝐼𝑚𝑎𝑔,𝑋 𝑘 - , 𝑘 = 0,1, … , 𝑁 − 1.
24
𝑁 𝑁
Prof. Dr. Ehab
2.2 Amplitude Spectrum and Power Spectrum
Similarly, for a one-sided power spectrum, we get:
1 2
2
𝑋(0) , 𝑘 = 0.
𝑃𝑘 = 𝑁
2 2
𝑋(𝑘) , 𝑘 = 1, … , 𝑁/2.
𝑁2
𝑘𝑓𝑠
and 𝑓= .
𝑁
Again, notice that the frequency resolution, which denotes the frequency
spacing between DFT coefficients in frequency domain, is defined as:
𝑓𝑠
∆𝑓 = (𝐻𝑧).
𝑁
It follows that better frequency resolution can be achieved by using a longer
data sequence.
25
Prof. Dr. Ehab
Example. 5: Consider the sequence shown in figure.8:
27
Prof. Dr. Ehab
Example. 5:
Figure. 9: Exampl. 5
A) Amplitude spectrum and
phase spectrum.
B) Power density spectrum.
Note that the folding frequency in this example is 50 Hz and the amplitude and power
spectrum values at 75 Hz are each image counterparts (corresponding negative-indexed
frequency components). Thus values at 0, 25, and 50 Hz correspond to the positive-
28
indexed frequency components. Prof. Dr. Ehab
Example. 5:
We can easily find the one-sided amplitude spectrum and one-sided power
spectrum as:
𝐴0 = 2.5, 𝐴1 = 1.4141, 𝐴2 = 1, and
𝑃0 = 6.25, 𝑃1 = 2, 𝑃2 = 1.
We plot the one-sided amplitude spectrum for comparison as shown below:
Note that in the one-sided amplitude spectrum, the negative-indexed
frequency components are added back to the corresponding positive-indexed
frequency components; thus each amplitude value other than the DC term is
doubled. It represents the frequency components up to the folding frequency.
29
Figure. 10: One-sided amplitude spectrum in Example .5. Prof. Dr. Ehab
Homework . 1:
Consider a digital sequence sampled at the rate of 10 kHz. If we use a
size of 1,024 data points and apply the 1,024-point DFT to compute the
spectrum,
a. Determine the frequency resolution.
b. Determine the highest frequency in the spectrum.
Homework . 2:
We use the DFT to compute the amplitude spectrum of a sampled data
sequence with a sampling rate fs = 10 kHz. Given that it requires the
frequency resolution to be less than 0.5 Hz,
a. Determine the number of data points by using the FFT
algorithm, assuming that the data samples are available.
30
Prof. Dr. Ehab
3. Spectral Estimation Using Window Functions
When we apply DFT to the sampled data in the previous section, we
theoretically imply the following assumptions: first, that the sampled data are
periodic to themselves (repeat themselves), and second, that the sampled data
are continuous to themselves and band limited to the folding frequency. The
second assumption is often violated, thus the discontinuity produces undesired
harmonic frequencies. Consider the pure 1-Hz sine wave with 32 samples
shown in Figure .11.
As shown in the figure, if we use a window size of N = 16 samples,
which is a multiple of the two waveform cycles, the second window repeats
with continuity. However, when the window size is chosen to be 18 samples,
which is not a multiple of the waveform cycles (2.25 cycles), the second
window repeats the first window with discontinuity. It is this discontinuity that
produces harmonic frequencies that are not present in the original signal.
Figure .12 shows the spectral plots for both cases using the DFT/FFT directly.
31
Prof. Dr. Ehab
3. Spectral Estimation Using Window Functions
Figure. 11: Sampling a 1-Hz sine wave using (top) 16 samples per
32
cycle and (bottom) 18 samples per cycle. Prof. Dr. Ehab
3. Spectral Estimation Using Window Functions
The first spectral plot contains a single frequency, as we expected,
while the second spectrum has the expected frequency component plus many
harmonics, which do not exist in the original signal. We call such an effect
spectral leakage.
33
Prof. Dr. Ehab
3. Spectral Estimation Using Window Functions
The first spectral plot contains a single frequency, as we expected,
while the second spectrum has the expected frequency component plus many
harmonics, which do not exist in the original signal. We call such an effect
spectral leakage.
The amount of spectral leakage shown in the second plot is due to
amplitude discontinuity in time domain. The bigger the discontinuity, the more
the leakage. To reduce the effect of spectral leakage, a window function can be
used whose amplitude tapers smoothly and gradually toward zero at both ends.
Applying the window function w(n) to a data sequence x(n) to obtain a
windowed sequence xw(n) is better illustrated in Figure .13 using Equation:
𝑥𝑤 (𝑛) = 𝑥 𝑛 𝑤 𝑛 , 𝑓𝑜𝑟 𝑛 = 0, 1, … , 𝑁 − 1.
The top plot is the data sequence x(n); and the middle plot is the
window function w(n): The bottom plot in Figure .13 shows that the windowed
sequence xw(n) is tapped down by a window function to zero at both ends such
that the discontinuity is dramatically reduced.
34
Prof. Dr. Ehab
3. Spectral Estimation Using Window Functions
36 wR(n) =1 0 n N-1
Prof. Dr. Ehab
Example. 6:
39
Figure. 15: Plots of window sequences.
Prof. Dr. Ehab
Example. 7:
Considering the sequence x(0)=1, x(1)=2, x(2)=3, and x(3)=4, and given
fs=100 Hz, T=0.01 seconds, compute the amplitude spectrum, phase spectrum, and
power spectrum
a. Using the triangular window function.
b. Using the Hamming window function.
Solution:
a. Since N = 4, from the triangular window function, we have:
2×0−4+1
𝑤𝑡𝑟𝑖 0 = 1 − = 0.
4−1
2×1−4+1
𝑤𝑡𝑟𝑖 1 =1− = 0.6667.
4−1
Similarly, wtri(2)=0.6667, wtri(3)=0. Next, the windowed sequence is computed as:
𝑥𝑤 0 = 𝑥 0 × 𝑤𝑡𝑟𝑖 0 = 1 × 0 = 0.
𝑥𝑤 1 = 𝑥 1 × 𝑤𝑡𝑟𝑖 1 = 2 × 0.6667 = 1.3334.
𝑥𝑤 2 = 𝑥 2 × 𝑤𝑡𝑟𝑖 2 = 3 × 0.6667 = 2.
40
𝑥𝑤 3 = 𝑥 3 × 𝑤𝑡𝑟𝑖 3 = 4 × 0 = 0.
Prof. Dr. Ehab
Example. 7:
Applying DFT Equation to xw(n) for k = 0, 1, 2, 3, respectively,
𝑋 𝑘 = 𝑥𝑤 0 𝑊4 𝑘×0 + 𝑥𝑤 1 𝑊4 𝑘×1 + 𝑥𝑤 2 𝑊4 𝑘×2 + 𝑥𝑤 3 𝑊4 𝑘×3 .
We have the following results:
X(0)=3.3334, X(1)=-2-j1.3334, X(2)=0.6666, X(3)= -2+j1.3334.
1 1
∆𝑓 = = = 25𝐻𝑧.
𝑁𝑇 4 × 0.01
Applying Equations of Ak, k, Pk, leads to:
1 −1
𝐼𝑚𝑎𝑔,𝑋 0 - −1
0
𝐴0 = 𝑋(0) = 0.8334, 𝜑0 = tan = tan = 00 ,
4 𝑅𝑒𝑎𝑙,𝑋 0 - 3.3334
1
𝑃0 = 2 𝑋(0) 2 = 0.6954.
4
Similarly,
A1= 0.6009, 1=-146.310, P1=0.3611, A2=0.1667, 2= 00, P2=0.0278,
A3=0.6009, 2= 146.310, P3=0.3611.
b. Since N = 4, from the Hamming window function, we have:
2𝜋 × 0
41 𝑤ℎ𝑚 0 = 0.54 − 0.46 cos = 0.08.
4−1 Prof. Dr. Ehab
Example. 7:
Similarly, whm(1)= 0.77, whm(2)= 0.77, whm(3)= 0.08. Next, the windowed
sequence is computed as:
𝑥𝑤 0 = 𝑥 0 × 𝑤ℎ𝑚 0 = 1 × 0.08 = 0.08.
𝑥𝑤 1 = 𝑥 1 × 𝑤ℎ𝑚 1 = 2 × 0.77 = 1.54.
𝑥𝑤 2 = 𝑥 2 × 𝑤ℎ𝑚 2 = 3 × 0.77 = 2.31.
𝑥𝑤 3 = 𝑥 3 × 𝑤ℎ𝑚 3 = 4 × 0.08 = 0.32.
Applying DFT Equation to xw(n) for k = 0, 1, 2, 3, respectively,
𝑋 𝑘 = 𝑥𝑤 0 𝑊4 𝑘×0 + 𝑥𝑤 1 𝑊4 𝑘×1 + 𝑥𝑤 2 𝑊4 𝑘×2 + 𝑥𝑤 3 𝑊4 𝑘×3 .
We yield the following:
X(0)=4.25, X(1)= -2.23-j1.22, X(2)=0.53, X(3)=-2.23+j1.22.
1 1
∆𝑓 = = = 25𝐻𝑧.
𝑁𝑇 4 × 0.01
Applying Equations of Ak, k, Pk, leads to:
A0= 1.0625, 0=00, P0=1.1289, A1= 0.6355, 1=-151.320, P1=0.4308,
A2=0.1325, 2= 00, P2=0.0176, A3=0.6335, 2= 151.320, P3=0.4308.
42
Prof. Dr. Ehab
Homework .3:
Given the sinusoid:
𝑛
𝑥 𝑛 = 2. sin 2000𝜋 .
8000
obtained by using a sampling rate of fs = 8,000 Hz, use the DFT to
compute the spectrum with the following specifications:
a. Compute the spectrum of a triangular window function with a window
size = 50.
b. Compute the spectrum of a Hamming window function with a window
size = 100.
c. Compute the spectrum of a Hanning window function with a window size
= 150 and one-sided spectrum.
43
Prof. Dr. Ehab
4. Application to Speech Spectral Estimation
The following plots show the comparisons of amplitude spectral
estimation for speech data (we.dat) with 2,001 samples and a sampling
rate of 8,000 Hz using the rectangular window (no window) function and
the Hamming window function. As demonstrated in Figure .15 (two-
sided spectrum) and Figure.16 (one-sided spectrum), there is little
difference between the amplitude spectrum using the Hamming window
function and the spectrum without using the window function. This is due
to the fact that when the data length of the sequence (e.g., 2,001 samples)
increases, the frequency resolution will be improved and spectral leakage
will become less significant. However, when data length is short,
reduction of spectral leakage using a window function will come to be
prominent.
𝑋 𝑘 = 𝑥 𝑛 𝑊𝑁 𝑘𝑛 , 𝑓𝑜𝑟 𝑘 = 0, 1, … , 𝑁 − 1.
𝑛=0
2𝜋
−𝑗
Where 𝑊𝑁 = 𝑒 is the twiddle factor, and N = 2, 4, 8, 16, … Equation
𝑁
𝑋 𝑘 = 𝑥 𝑛 𝑊𝑁 𝑘𝑛 + 𝑥 𝑛 𝑊𝑁 𝑘𝑛 .
48 Prof. Dr. Ehab 𝑛=0 𝑛=𝑁/2
5.1 Method of Decimation-in-Frequency
Modifying the second term in Equation above yields:
𝑁/2 −1 𝑁/2 −1
𝑁
𝑋 𝑘 = 𝑥 𝑛 𝑊𝑁 𝑘𝑛 + 𝑊𝑁 (𝑁/2)𝑘 𝑥(𝑛 + ) 𝑊𝑁 𝑘𝑛 .
2
𝑛=0 𝑛=𝑁/2
2𝜋(𝑁/2)
(𝑁/2) −𝑗
Recall 𝑊𝑁 =𝑒 𝑁 = 𝑒 −𝑗𝜋 = −1; then we have:
𝑁/2 −1
𝑁
𝑋 𝑘 = 𝑘
𝑥 𝑛 + (−1) +𝑥 𝑛 + 𝑊𝑁 𝑘𝑛 .
2
𝑛=0
Now letting k=2m as an even number achieves:
𝑁/2 −1
𝑁
𝑋 2𝑚 = 𝑥 𝑛 +𝑥 𝑛+ 𝑊𝑁 2𝑛𝑚
2
𝑛=0
while substituting k = 2m+1 as an odd number yields:
𝑁/2 −1
𝑁
𝑋 2𝑚 + 1 = 𝑥 𝑛 −𝑥 𝑛+ 𝑊𝑁 𝑛 𝑊𝑁 2𝑛𝑚 .
2
49 Prof. Dr. Ehab 𝑛=0
5.1 Method of Decimation-in-Frequency
2𝜋×2 2𝜋
2 −𝑗 −𝑗
Using the fact that 𝑊𝑁 = 𝑒 𝑁 =𝑒 (𝑁/2) = 𝑊𝑁/2 , it follows that:
(𝑁/2)−1
Figure.19: The second iteration of the Figure.20: Block diagram for the eight-
eight-point FFT. point FFT (total twelve multiplications).
52 Prof. Dr. Ehab
5.1 Method of Decimation-in-Frequency
To see the effectiveness of FFT, let us consider a sequence with 1,024
data points. Applying DFT will require 1,0241,024 = 1,048,576 complex
multiplications; however, applying FFT will need only
(1,024/2)log2(1,024)=5,120 complex multiplications. Next, the index (bin
number) of the eight-point DFT coefficient X(k) becomes 0, 4, 2, 6, 1, 5, 3, and
7, respectively, which are not in the natural order. This can be fixed by index
matching. Index matching between the input sequence and the output frequency
bin number by applying reversal bits is described in Table .2.
Table .2: Index mapping for fast Fourier transform.
57
Prof. Dr. Ehab
5.2 Method of Decimation-in-Time
In this method, we split the input sequence x(n) into the even indexed
x(2m) and x(2m+1), each with N data points. Then the DFT equation becomes:
(𝑁/2)−1 (𝑁/2)−1
Solution:
a. Using the block diagram in Figure.27 leads to:
62
Prof. Dr. Ehab
Example. 11:
Given the DFT sequence X(k) for 0 ≤ k 3 computed in Example .10,
a. Evaluate its inverse DFT x(n) using the decimation-in-time FFT method.
Solution:
a. Using the block diagram in Figure .28 yields
63
Prof. Dr. Ehab
6. Summary
1. The Fourier series coefficients for a periodic digital signal can be used to
develop the DFT.
2. The DFT transforms a time sequence to the complex DFT coefficients,
while the inverse DFT transforms DFT coefficients back to the time
sequence.
3. The frequency bin number is the same as the frequency index. Frequency
resolution is the frequency spacing between two consecutive frequency
indices (two consecutive spectrum components).
4. The DFT coefficients for a given digital signal are applied for computing
the amplitude spectrum, power spectrum, or phase spectrum.
5. The spectrum calculated from all the DFT coefficients represents the signal
frequency range from 0 Hz to the sampling rate. The spectrum beyond the
folding frequency is equivalent to the negative-indexed spectrum from the
negative folding frequency to 0 Hz. This two-sided spectrum can be
converted into a one-sided spectrum by doubling alternating- current (AC)
components from 0 Hz to the folding frequency and retaining the DC
component as it is.