<< Chapter < Page Chapter >> Page >
ω = 2 π k / N

for k = 0 , 1 , ... ( N - 1 ) in [link] , we find that

X tr ( e j ω ) ω = 2 π k N = n = 0 N - 1 x ( n ) e - j ω n ω = 2 π k N = n = 0 N - 1 x ( n ) e - j 2 π k n / N = X N ( k ) .

In short, the DFT values result from sampling the DTFT of the truncated signal.

X N ( k ) = X tr ( e j 2 π k / N )

Windowing effects

Download DTFT.m for the following section.

We will next investigate the effect of windowing when computing the DFT of the signal x ( n ) = cos π 4 n truncated with a window of size N = 20 .

  1. In the same figure, plot the phase and magnitude of W ( e j ω ) , using equations [link] and [link] .
  2. Determine an expression for X ( e j ω ) (the DTFT of the non-truncated signal).
  3. Truncate the signal x ( n ) using a window of size N = 20 and then use DTFT.m to compute X tr ( e j ω ) . Make sure that the plot contains a least 512 points.
    Use the command [X,w] = DTFT(x,512) .
  4. Plot the magnitude of X tr ( e j ω ) .
The plot of a Hamming window (left) and its DTFT (right).

Inlab report

  1. Submit the plot of the phase and magnitude of W ( e j ω ) .
  2. Submit the analytical expression for X ( e j ω ) .
  3. Submit the magnitude plot of X tr ( e j ω ) .
  4. Describe the difference between | X tr ( e j ω ) | and | X ( e j ω ) | . What is the reason for this difference?
  5. Comment on the effects of using a different window for w ( n ) . For example, what would you expect your plots to look like if youhad used a Hamming window in place of the truncation (rectangular) window?(See [link] for a plot of a Hamming window of length 20 and its DTFT.)

The discrete fourier transform

Computing the dft

We will now develop our own DFT functions to help our understanding of how the DFT comes from the DTFT.Write your own Matlab function to implement the DFT of equation [link] . Use the syntax

X = DFTsum(x)

where x isan N point vector containing the values x ( 0 ) , , x ( N - 1 ) and X is the corresponding DFT.Your routine should implement the DFT exactly as specified by [link] using for-loops for n and k , and compute the exponentials as they appear.Note: In Matlab, "j" may be computed with the command j=sqrt(-1) . If you use j = - 1 , remember not to use j as an index in your for-loop .

Test your routine DFTsum by computing X N ( k ) for each of the following cases:

  1. x ( n ) = δ ( n ) for N = 10 .
  2. x ( n ) = 1 for N = 10 .
  3. x ( n ) = e j 2 π n / 10 for N = 10 .
  4. x ( n ) = cos ( 2 π n / 10 ) for N = 10 .

Plot the magnitude of each of the DFT's. In addition, derive simple closed-form analytical expressions for theDFT (not the DTFT!) of each signal.

Inlab report

  1. Submit a listing of your code for DFTsum .
  2. Submit the magnitude plots.
  3. Submit the corresponding analytical expressions.

Write a second Matlab function for computing the inverse DFT of [link] . Use the syntax

x = IDFTsum(X)

where X is the N point vector containing the DFT and x is the corresponding time-domain signal. Use IDFTsum to invert each of the DFT's computed in the previous problem. Plot the magnitudes of the inverted DFT's,and verify that those time-domain signals match the original ones. Use abs(x) to eliminate any imaginary parts which roundoff error may produce.

Inlab report

  1. Submit the listing of your code for IDFTsum .
  2. Submit the four time-domain IDFT plots.

Matrix representation of the dft

The DFT of [link] can be implemented as a matrix-vector product. To see this, consider the equation

X = A x

where A is an N × N matrix, and both X and x are N × 1 column vectors. This matrix product is equivalent to the summation

X k = n = 1 N A k n x n .

where A k n is the matrix element in the k t h row and n t h column of A .By comparing [link] and [link] we see that for the DFT,

A k n = e - j 2 π ( k - 1 ) ( n - 1 ) / N

The - 1 's are in the exponent because Matlab indices start at 1, not 0. For this section, we need to:

  • Write a Matlab function A = DFTmatrix(N) that returns the NxN DFT matrix A.
    Remember that the symbol * is used for matrix multiplication in Matlab, and that . ' performs a simple transpose on a vector or matrix. An apostrophe without the period is a conjugate transpose.
  • Use the matrix A to compute the DFT of the followingsignals. Confirm that the results are the same as in the previous section.
    1. x ( n ) = δ ( n ) for N = 10
    2. x ( n ) = 1 for N = 10
    3. x ( n ) = e j 2 π n / N for N = 10

Inlab report

  1. Print out the matrix A for N = 5 .
  2. Hand in the three magnitude plots of the DFT's.
  3. How many multiplies are required to compute an N point DFT using the matrix method?(Consider a multiply as the multiplication of either complex or real numbers.)

As with the DFT, the inverse DFT may also be represented as a matrix-vector product.

x = B X

For this section,

  1. Write an analytical expression for the elements of the inverse DFT matrix B , using the form of [link] .
  2. Write a Matlab function B = IDFTmatrix(N) that returns the NxN inverse DFT matrix B.
  3. Compute the matrices A and B for N = 5 . Then compute the matrix product C = B A .

Inlab report

  1. Hand in your analytical expression for the elements of B .
  2. Print out the matrix B for N = 5 .
  3. Print out the elements of C = B A . What form does C have? Why does it have this form?

Computation time comparison

Click here for help on the cputime function.

Although the operations performed by DFTsum are mathematically identical to a matrix product, the computation times for these two DFT's in Matlab are quite different.(This is despite the fact that the computational complexity of two procedures is of the same order!)This exercise will underscore why you should try to avoid using for loops in Matlab, and wherever possible, try to formulate your computations using matrix/vector products.

To see this, do the following:

  1. Compute the signal x ( n ) = cos ( 2 π n / 10 ) for N = 512 .
  2. Compute the matrix A for N = 512 .
  3. Compare the computation time of X = DFTsum(x) with a matrix implementation X = A*x by using the cputime function before and after the program execution. Do not include the computation of A in your timing calculations.
Report the cputime required for each of the two implementations. Which method is faster? Which method requires less storage?

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Purdue digital signal processing labs (ece 438). OpenStax CNX. Sep 14, 2009 Download for free at http://cnx.org/content/col10593/1.4
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Purdue digital signal processing labs (ece 438)' conversation and receive update notifications?

Ask