Worksheet 12#

To accompany Unit 6.1 The Discrete Fourier Transform#

We will step through this worksheet in class.

You are expected to have at least watched the video presentation of Unit 6.1: The Discrete Fourier Transform of the notes before coming to class.

If you haven’t watch it afterwards!

List of Abbreviations#

  • CT – Continuous Time

  • DT – Discrete Time

  • DF - Discrete frequency

  • DFT – Discrete (Time) Fourier Transform

  • FFT – Fast Fourier Transform

Notation#

In the following we shall denote a DT signal as x[n] and its discrete frequency function as X[m].

Z-Transform#

Recall that

F(z)=Zf[n]=n=0f[n]zn.

The value of this function on the unit circle in the Z-plane will be

F(exp(jωT))=n=0f[n]exp(jnωT).

This is an infinite sum. So to compute it, we need to truncate it.

The Discrete-time Fourier Transform#

Let’s assume that instead of an infinite number of points, we have N points, equally distributed around the unit circle, then the truncated version will be:

X[m]=n=0N1x[n]exp(j2πmnN)

where

ω=(2πN)nm

and m=0,1,2,,N1 and n=0,1,2,,N1.

We refer to the equation

X[m]=n=0N1x[n]exp(j2πmnN)

as the N-point Discrete-time Fourier Transform (DFT) of x[n].

The inverse DFT is defined as

x[n]=1Nm=0N1X[m]exp(j2πmnN)

for n=0,1,2,,N1.

Note the symmetry of the DFT and the Inverse DFT!

In general, the DFT is complex, and thus it can be expressed as

X[m]={X[m]}+{X[m]}

for m=0,1,2,,N1.

Since

exp(j2πmnN)=cos(2πmnN)jsin(2πmnN)

the DFT can be expresssed as

X[m]=n=0N1x[n]exp(j2πmnN)=n=0N1x[n]cos(2πmnN)jn=0N1x[n]sin(2πmnN).

For n=0 this reduces to

X[m]=x[0].

Then the real part of X[m] is

{X[m]}=x[0]+n=1N1x[n]cos(2πmnN)form=0,1,2,,N1

and the imaginary part is

{X[m]}=n=1N1x[n]sin(2πmnN)form=0,1,2,,N1.

Note that the summations are from 1 to N1 because n=0 is covered in the real term, and as x[0] is real, it is zero in the corresponding imaginary term.

In Class Example 1#

A discrete time signal is defined by the sequence

x[0]=1, x[1]=2, x[2]=2, x[3]=1, and x[n]=0 for all other values of n.

Compute the frequency components X[m].

Solution 1#

  • Compute the N point DFT for {X[m]}.



















  • Compute the four point DFT for {X[m]}.



















  • Add these together to find X[m].



















In Class Example 2#

Use the inverse DFT to compute the discrete-time sequence x[n] from X[m].

Solution 2#

  • Write down the expression x[n] in terms of X[m].



















  • Compute x[0] from this result.



















  • Repeat for x[1], x[2] and x[3].



















MATLAB model of the DFT#

Karris Example 10.1. To successfully run this script you will need to download the functions dft.m and idft.m and make them available on your MATLABPATH.

xn = [2 0 0 8 9 7 5 0];
open dft
Xm = dft(xn,8)
Xm =
  Columns 1 through 4
  31.0000 + 0.0000i -17.6066 + 4.2929i   6.0000 + 1.0000i   3.6066 - 5.7071i
  Columns 5 through 8
   1.0000 + 0.0000i   3.6066 + 5.7071i   6.0000 - 1.0000i -17.6066 - 4.2929i
open idft
xn = idft(Xm,8)
xn =
  Columns 1 through 4
   2.0000 - 0.0000i  -0.0000 - 0.0000i  -0.0000 - 0.0000i   8.0000 - 0.0000i
  Columns 5 through 8
   9.0000 - 0.0000i   7.0000 + 0.0000i   5.0000 + 0.0000i   0.0000 + 0.0000i

A useful compact notation#

The term

exp(j2πN)

is a rotating vector where the range 0<=θ<=2π is divided into N equal segments where N is usually taken to be a power of 2.

It is convenient to represent this as WN, that is

WN=exp(j2πN)

and consequently,

WN1=exp(j2πN).

In Class Example 3#

Compute the complex numbers represented by the rotating vector W8

Solution 3#

  • Rewrite W8 in exponential form









  • Visualize on unit circle

Visualization of the function unction

  • Complete this table

n

θ

Real

Imaginary

W8n

0

0

1

0

1






















Using this notation, the DFT and inverse DFT pairs are represented as:

X[m]=n=0N1x[n]WNnm

and

x[n]=1Nn=0N1X[m]WNnm

MATLAB implementation of DFT#

Using the W notation, it is very easy to write a function to implement the DFT.

We will demonstrate this in class.

For example, consider dft.m:

function [ Xm ] = dft( xn, N )
% Computes Discrete Fourier Transform
% -----------------------------------
% [Xm]  = dft(xn, N)
% Xm = DFT coeff. array over 0 <= m <= N-1
% xn = N-point finite-duration sequence
%  N = length of DFT
%
n = [0:1:N-1];          % row vector for n
m = [0:1:N-1];          % row vector for m
WN = exp(-j*2*pi/N);    % Wn factor
nm = n'*m;              % creates an N by N matrix of nm values
WNnm = WN .^ nm;        % DFT matrix
Xm = xn * WNnm;         % row vector of DFT coefficients

Similarly for the inverse DFT idft.m:

function [ xn ] = idft( Xm, N )
% Computes Inverse Discrete Fourier Transform
% -------------------------------------------
% [xn]  = idft(Xm, N)
% xn = N-point sequence over 0 <= n <= N-1
% Xm = DFT coeff. array over 0 <= m <= N-1
%  N = length of DFT
%
n = [0:1:N-1];          % row vector for n
m = [0:1:N-1];          % row vector for m
WN = exp(-j*2*pi/N);    % Wn factor
nm = n'*m;              % creates an N by N matrix of nm values
WNnm = WN .^ (-nm);     % DFT matrix
xn = (Xm * WNnm)/N;     % row vector for IDFT values

Notes#

In the remainder of these notes, the correspondence between x[n] and X[m] will be written

x[n]X[m]

In Example 2, we found that, although the DT sequence x[n] was real, the discrete frequency (DF) sequence was complex. However, in most applications we are interested in the magnitude and phase of the DF, that is

|X[m]|

and

X[m].

In Class Example 4#

Use MATLAB to compute the magnitude of the frequency components of the following DT function:

n

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

x[n]

1.0

2

2

2.5

1.5

0.5

-0.5

-1.5

-2.5

-0.5

0.25

1.25

2

1.5

1

0.5

We will compute this in class and make some comments afterwards.

xn = [ 1, 2, 3, 2.5, 1.5, 0.5,...
    -0.5, -1.5, -2.5, -0.5,...
    0.25, 1.25, 2, 1.5, 1, 0.5];
stem([0:15],xn),xlabel('n'),ylabel('x[n]'),title('Discrete Time Sequence')
../../_images/9e0aa350630399823bb833b96b5e8f993fbbbc46dca70bfa8fa15bcb716aae1c.png
Xm = dft(xn,16);
stem([0:15],abs(Xm)),xlabel('m'),ylabel('|X[m]|'),title('Discrete Frequency Sequence')
../../_images/0188e824536a44319b3c81019101e4c959d0b44b6677226d7cf8532e8a2133ff.png

Points to note:

  • X[0]=12 is the DC component of the DT sequence.

  • After the |X[8]|=1.4872 term, the magnitude of the frequency values for the range 9<=m15 are the mirror image of the values for the range 0<=m<=7.

  • This is not a coincidence, in fact if x[n] is an N-point real discrete-time function, only N/2 of the frequency components of |X[m]| are unique.

A summary of the important features of sampling and the DFT#

  • N is the number of samples in frequency.

  • fs sampling frequency, samples per second.

  • Tt period of a periodic DT function.

  • ts interval between the N samples in time period Tt.

  • ff period of a periodic DF function.

  • Fs interval between the N samples in frequency period Tf.

The relationships between these quantities are:

tt=TtN
fs=1tt
tf=TfN
tt=1Tf
ff=1Tt

We will add these quantities to the results of Example 4 in class.

Example 4 (continued)#

Example 4

To reproduce this plot use repeat.m.

In Class Example 5#

The period of a periodic DT function is 0.125 ms and it is sampled at 1024 equally spaced points. It is assumed that with this number of samples, the sampling theorem is satisfied and thus there will be no aliasing.

  1. Compute the interval tt between samples for the periodic signal

  2. Compute the period Tf of the frequency spectrum in kHz

  3. Compute the interval tf between frequency components in kHz

  4. Compute the sampling frequency fs.

  5. Compute the Nyquist frequency fn.

Solution#

To be done in class.

  • Compute the interval tt between samples for the periodic signal









  • Compute the period of the frequency spectrum Tf in kHz









  • Compute the interval tf between frequency components in kHz









  • Compute the sampling frequency fs.









  • Compute the Nyquist frequency fn.