Loren on the Art of MATLAB

February 2nd, 2009

A Pedagogical Tool for Fourier Transforms

I recently attended the DSP Workshop sponsored by the IEEE Signal Processing Society. It focues on both signal processing and signal processing education. I spoke to a lot of the attendees. Some of the professors and instructors mentioned how important it is to teach the basics solidly first, before going into more depth. If the students don't get the fundamentals, then going further doesn't help.

Contents

Pedagogical Tool - dftmtx

With that context, I asked how they teach Fourier transforms, especially once they go from the analog domain to the digital. It turns out that most of them were unaware of some of the tools in Signal Processing Toolbox, such as dftmtx.

Here's the help.

h = help('dftmtx');
disp(h(1:744))
 DFTMTX Discrete Fourier transform matrix.
    DFTMTX(N) is the N-by-N complex matrix of values around
    the unit-circle whose inner product with a column vector
    of length N yields the discrete Fourier transform of the
    vector.  If X is a column vector of length N, then
    DFTMTX(N)*X yields the same result as FFT(X); however, 
    FFT(X) is more efficient.
 
    The inverse discrete Fourier transform matrix is
    CONJ(DFTMTX(N))/N.
 
    An interesting example is 
 
      D = dftmtx(4)
 
    which returns
 
      D = [1   1   1   1
           1  -i  -1   i     
           1  -1   1  -1
           1   i  -1  -i]
 
    which illustrates why no multiplications are necessary for
    4-point DFTs.
 
    See also FFT and IFFT.


The help also mentions fft, the discrete Fourier transform, computed with a fast Fourier transform (fft) algorithm. With the information given for dftmtx, let's compare results with those of fft.

More on dftmtx

On further inspection, you may notice that there are comments in the file outlining the calculation. As an aside, the computation is actually done using the function fft in MATLAB.

Here's a brief description of the non-|fft| algorithm. Basically calculate frequencies on the unit circle and multiply by sqrt(-1) (w). Multiply these by integral steps for the number of points in the transform (w*x). And then calculate all the sin and cos terms using exp.

Explicitly, the calculation is:

 f = 2*pi/n;                 % Angular increment.
 w = (0:f:2*pi-f/2).' * i;   % Column.
 x = 0:n-1;                  % Row.
 D = exp(-w*x);              % Exponentiation of outer product.

Compare fft and Discrete Transform Matrix Methods

n = 1024;
X = eye(n);
Xf = fft(X);       % fft result
f = 2*pi/n;
w = (0:f:2*pi-f/2).' * 1i;
x = 0:n-1;
Xd = exp(-w*x);     % matrix representation
norm(Xf-Xd)
ans =
  1.6769e-011

Do You Have Good Links for Fourier Transform Teaching Material?

If you know of web sites with good material for teaching discrete Fourier transforms, would you please post them here? Thanks.


Get the MATLAB code

Published with MATLAB® 7.7

2 Responses to “A Pedagogical Tool for Fourier Transforms”

  1. Quan replied on :

    Hey Loren,

    I wrote a little bit about Fourier last year on my blog. Some people have found it useful, and hopefully your readers will too!

    http://blinkdagger.com/fourier

    Quan

  2. Kamil Wojcicki replied on :

    Hi Loren,

    In the recent years open courseware (OCW) has become very popular. Thanks to OCW anyone can freely access pedagogical materials in the form of video lectures from top universities presented by experienced and achieved researchers.

    I can recommend the following very useful resources for learning about Fourier transforms (as well as many other topics):

    The http://ocw.mit.edu/ and in particular linear algebra lectures by Prof. Gilbert Strang (see lecture 26 for discussion about complex matrices and the fast Fourier transform).

    The OCW from Standord University and in particular: the Fourier transform and its applications lectures.

    Another popular resource is located at videolectures.net.

    Hope this is useful to others, happy learning :)

    Kamil

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Loren Shure works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics.

  • Jun: I totally can not believe it, Loren. You are really helpful. Thank you so much, MATLAB master!
  • Loren: Wow folks- Always lots of interest when there’s a quickie to try out! I will only make 2 general...
  • Loren: Jun- ismember is your friend here: >> [aa,ind] = ismember(Array2,Arra y1) aa = 1 1 1 1 1 1 1 ind = 1 2 1 4 4 3...
  • Dan: I like the first way better than the second way. Combining the arrays into one and running any is nice, although...
  • James Myatt: How about I = (a == 0 | b == 0); a(I) = []; b(I) = [];
  • Tunc: Hello Loren, love your blog because of such inspiring and challenging comments to such ’small’...
  • Pekka Kumpulainen: Here is my tradeoff. I usually want to keep the original variables as they are most probably...
  • Iain: Followup: Of course, to allow NaNs (counting them as non-zero): mask = (a~=0) & (b~=0); The mask says “a...
  • Matt Fig: I would usually go with something like this: y = a&b; x = a(y); y = b(y); But I was surprised to find...
  • kk: c=all([a;b]) a(c) a(b)

These postings are the author's and don't necessarily represent the opinions of The MathWorks.