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.

  • Loren: Paul- There *are* issues depending on the sizes of ii and jj. And it’s a bit complicated, but really...
  • Loren: Bob- You don’t say what happens when you run your code. Can you please explain more. It looks like you...
  • Loren: Kishore- It is not clear to me what you are trying to actually achieve. If you want to concatenate the 4...
  • Kishore: sorry, in the previous code mat2cell(c,[19 121],[19 134],[19 84],[19 107])
  • Kishore: Hi Loren, Why does the following not work? data_classwise = [19x121 double] [19x134 double] [19x84 double]...
  • Paul Jackson: Loren, Are there any aspects of empty matrices that may be tricky when they are used as indices into...
  • Bob: Hi Lori, Im trying to process Unicode text files from more than one different locales than the standard latin...
  • Loren: Ben- The reference link in my post documents the behavior of sum([]) and prod([]) (although the prod part only...
  • Ben: Loren/Andrey, A further advantage of having sum([])==0 and prod([])==1 is that it’s consistent with array...
  • Loren: OysterEngineer- I will SO take you up on that offer. Can’t wait for a good reason to visit now....

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