Download - DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Transcript
Page 1: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

MATLAB(04)

The Discrete Fourier Transform

(DFT)

Assist. Prof. Amr E. Mohamed

Page 2: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Introduction

The discrete-time Fourier transform (DTFT) provided the frequency-domain (ω) representation for absolutely summable sequences.

The z-transform provided a generalized frequency-domain (z)representation for arbitrary sequences.

These transforms have two features in common.

First, the transforms are defined for infinite-length sequences.

Second, and the most important, they are functions of continuous variables(ω or z).

In other words, the discrete-time Fourier transform and the z-transformare not numerically computable transforms.

The Discrete Fourier Transform (DFT) avoids the two problemsmentioned and is a numerically computable transform that is suitablefor computer implementation.

2

Page 3: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Periodic Sequences

Let 𝑥(𝑛) is a periodic sequence with period N-Samples (the fundamental

period of the sequence).

Notation: a sequence with period N is satisfying the condition

where r is any integer.

3

),...1(),...,1(),0(),1(),...,1(),0(...,)(~ NxxxNxxxnxx(n) x(n)

)(~)(~ rNnxnx

Page 4: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Periodic Sequences

From Fourier analysis we know that the periodic functions can be synthesized

as a linear combination of complex exponentials whose frequencies are

multiples (or harmonics) of the fundamental frequency (which in our case is

2π/N).

The discrete version of the Fourier Series can be written as

where { 𝑋(𝑘), 𝑘 = 0,± 1, . . . , ∞} are called the discrete Fourier series

coefficients.

Note That, for integer values of m, we have

(it is called Twiddle Factor)

4

k

kn

N

k

N

knj

k

knN

j

k WkXN

ekXN

eXnx )(~1

)(~1

)(~ 22

nmNk

NN

nmNkj

N

knj

kn

N WeeW )(

)(22

Page 5: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Synthesis and Analysis (DFS-Pairs)

5

Notation)/2( Nj

N eW

Synthesis

1

0

)(~1

)(~N

k

kn

NWkXN

nx

Analysis

)(~

)(~ kXnx DFS

Both havePeriod N

1

0

)(~)(~ N

k

kn

NWnxKX

Page 6: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Matlab Implementation An efficient implementation in MATLAB would be to use a matrix-vector

multiplication.

Let X and X denote column vectors corresponding to the primary periods of

sequences 𝑥(𝑛) and 𝑋(𝑘) , respectively.

where the matrix 𝑾𝑁 is given by

6

Page 7: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Matlab Implementation (Cont.)

The following MATLAB function dfs implements this procedure.

7

Page 8: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Matlab Implementation (Cont.)

Example: The DFS of 𝑥 𝑛 = { . . . , 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, . . . } can be

computed using MATLAB as

8

Page 9: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Matlab Implementation (Cont.)

The following idfs function implements the synthesis equation.

9

Page 10: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

EXAMPLE

10

Page 11: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution

A plot of this sequence for L = 5 and N = 20 is shown in the Figure

11

Page 12: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

a. By applying the DFS analysis equation

The last expression can be simplified to

12

Page 13: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

or the magnitude of 𝑿(𝑘) is given by

b. The MATLAB script for L = 5 and N = 20:

13

Page 14: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.) The plots for this and all other cases are shown in the Figure.

Note that since 𝑿(𝑘) is periodic, the plots are shown from − N/2 to N/2.

14

Page 15: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

C. Several interesting observations can be made from plots in the above

Figure. The envelopes of the DFS coefficients of square waves look like

“sinc” functions. The amplitude at k = 0 is equal to L, while the zeros

of the functions are at multiples of N/L, which is the reciprocal of the

duty cycle.

15

Page 16: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Discrete Fourier Transform(DFT)

16

Page 17: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

The DFT Pair

17N

j

N

N

k

kn

N

N

k

N

knj

N

n

kn

N

N

n

N

knj

eWwhere

NnWkXN

x

ekXN

xSynthesis

NkWnxX

enxXAnalysis

2

1

0

1

0

2

1

0

1

0

2

1,...,1,0)(1

n)(

)(1

n)(

1,...,1,0)(k)(

)(k)(

Page 18: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Matlab Implementation

The MATLAB has

the dft function to calculate Discrete Fourier Transform, and

the idft function to calculate the inverse Discrete Fourier Transform.

Or, we can use the following code

18

Page 19: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Example

19

Page 20: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution

a. The discrete-time Fourier transform is given by

20

Page 21: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.) The plots of magnitude and phase are

21

Page 22: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)b. Let us denote the 4-point DFT by X 4 (k). Then

We can also use MATLAB to compute this DFT.

Note that when the magnitude sample is zero, the corresponding angle

is not zero. This is due to a particular algorithm used by MATLAB to

compute the angle part. Generally these angles should be ignored. 22

Page 23: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

23

Page 24: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Zero-Padding Operation

In previous Example, How can we obtain other samples of the DTFT

𝑋(𝑒𝑗𝜔)?

Solution: This we can achieve by treating x(n) as an 8-point sequence by

appending 4 zeros.

MATLAB script:

24

Page 25: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Zero-Padding Operation (Cont.) Hence

25

Page 26: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Zero-Padding Operation (Cont.)

1. Zero-padding is an operation in which more zeros are appended to the

original sequence. The resulting longer DFT provides closely spaced

samples of the discrete-time Fourier transform of the original

sequence.

2. The zero-padding gives us a high-density spectrum and provides a

better displayed version for plotting. But it does not give us a high-

resolution spectrum because no new information is added to the signal;

only additional zeros are added in the data.

3. To get a high-resolution spectrum, one has to obtain more data from.

26

Page 27: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Example

27

Page 28: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution

a. We can first determine the 10-point DFT of x(n) to obtain an estimate

of its discrete-time Fourier transform. MATLAB Script:

28

Page 29: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

The plots in Figure show

there aren’t enough samples

to draw any conclusions.

Therefore we will pad 90

zeros to obtain a dense

spectrum.

29

Page 30: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

MATLAB Script:

30

Page 31: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

Now the plot in Figure shows

that the sequence has a

dominant frequency at

ω=0.5π.

This fact is not supported by

the original sequence, which

has two frequencies.

The zero-padding provided a

smoother version of the

spectrum.

31

Page 32: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

b. To get better spectral information, we will take the first 100 samples of

x(n) and determine its discrete-time Fourier transform.

MATLAB Script:

32

Page 33: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Solution (Cont.)

Now the discrete-time Fourier

transform plot in Figure

clearly shows two frequencies,

which are very close to each

other.

This is the high-resolution

spectrum of x(n).

Note that padding more zeros

to the 100-point sequence will

result in a smoother rendition

of the spectrum.

33

Page 34: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Circular Convolution

34

Page 35: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Circular Convolution

A convolution operation that contains a circular shift is called the

circular convolution and is given by

Note that the circular convolution is also an N-point sequence.

It has a structure similar to that of a linear convolution. The differences

are in the summation limits and in the N-point circular shift. Hence it

depends on N and is also called an N-point circular convolution.

Therefore the use of the notation 𝑁 is appropriate. The DFT property

for the circular convolution is

35

Page 36: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

MATLAB Implementation

The following circonvt

function is a MATLAB

function that

calculates the circular

convolution.

36

Page 37: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

MATLAB Implementation (Cont.)

Perform the circular convolution for the following two sequences

MATLAB script:

Hence

37

Page 38: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Linear Convolution Using The DFT

In fact, FIR filters are generally implemented in practice using this

linear convolution. On the other hand, the DFT is a practical approach

for implementing linear system operations in the frequency domain.

The DFT is also an efficient operation in terms of computations.

However, there is one problem. The DFT operations result in a circular

convolution (something that we do not desire), not in a linear

convolution that we want.

How to make a circular convolution identical to the linear

convolution???

Let 𝑥1(𝑛) and 𝑥2(𝑛) a two sequences with length 𝑁1 𝑎𝑛𝑑 𝑁2 , then the

circular convolution is identical to the linear convolution. If we pad both

sequence to have a length equal to 𝑁 = (𝑁1+𝑁2 − 1) point.

38

Page 39: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

Example

Solution:

39

Page 40: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

THE FAST FOURIER TRANSFORM

40

Page 41: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

MATLAB IMPLEMENTATION

MATLAB provides a function called fft to compute the DFT of a vector x.

It is invoked by X = fft(x,N), which computes the N-point DFT.

If the length of x is less than N, then x is padded with zeros. If the

argument N is omitted, then the length of the DFT is the length of x.

If x is a matrix, then fft(x,N) computes the N-point DFT of each column

of x.

This fft function is written in machine language and not using MATLAB

commands (i.e., it is not available as a .m file). Therefore it executes

very fast. It is written as a mixed-radix algorithm.

The inverse DFT is computed using the ifft function, which has the same

characteristics as fft.

41

Page 42: DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

42