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

date post

21-Apr-2017Category

## Engineering

view

166download

7

Embed Size (px)

### Transcript of DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

MATLAB(04)

The Discrete Fourier Transform

(DFT)

Assist. Prof. Amr E. Mohamed

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

Periodic Sequences

Let () is a periodic sequence with period N-Samples (the fundamentalperiod 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

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 seriescoefficients.

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

)(~2

2

nmNk

NN

nmNkj

N

knj

kn

N WeeW)(

)(22

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

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 ofsequences () and () , respectively.

where the matrix is given by

6

Matlab Implementation (Cont.)

The following MATLAB function dfs implements this procedure.

7

Matlab Implementation (Cont.)

Example: The DFS of = { . . . , 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, . . . } can becomputed using MATLAB as

8

Matlab Implementation (Cont.)

The following idfs function implements the synthesis equation.

9

EXAMPLE

10

Solution

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

11

Solution (Cont.)

a. By applying the DFS analysis equation

The last expression can be simplified to

12

Solution (Cont.)

or the magnitude of () is given by

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

13

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

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 likesinc 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

Discrete Fourier Transform(DFT)

16

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)(

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

Example

19

Solution

a. The discrete-time Fourier transform is given by

20

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

21

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

Solution (Cont.)

23

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

Zero-Padding Operation (Cont.) Hence

25

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

Example

27

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

Solution (Cont.)

The plots in Figure show

there arent enough samples

to draw any conclusions.

Therefore we will pad 90

zeros to obtain a dense

spectrum.

29

Solution (Cont.)

MATLAB Script:

30

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

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

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

Circular Convolution

34

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 differencesare 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 propertyfor the circular convolution is

35

MATLAB Implementation

The following circonvt

function is a MATLAB

function that

calculates the circular

convolution.

36

MATLAB Implementation (Cont.)

Perform the circular convolution for the following two sequences

MATLAB script:

Hence

37

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

Example

Solution:

39

THE FAST FOURIER TRANSFORM

40

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