Jim's
Tutorials

Fall 2014
course
navigation

Nov 7

Last week's DFT (discrete fourier transform) homework didn't really get done ... so here is what we did in class, with Jim starting to set things up.
This isn't finished or pretty, but there is a DFT matrix definition, a plot of a few of its rows, a transform (dot matrix multiplication), and a plot of the output spectrum.
Here are the bits that count :
# First install Anaconda's ipython with notebook support! # Launch in browser with # # $ ipython notebook %matplotlib inline from numpy import fromfunction, exp, pi from matplotlib.pyplot import plot # number of points N = 8 # (N x N) discrete fourier transform matrix # In numpy, sqrt(-1) is spelled (0+1j) or just 1j . DFT = fromfunction(lambda k,n: exp(2 * pi * 1j * k * n / N), (N,N) ) # some points to transform, with len(x)=N x = [0,0,1,1,-1,-1,0,0] # fourier transform X = dot(M, x) # see row 2 of matrix (sinusoid) # Note that the ':' means 'all' of that index, # similar to thing[a:b], thing[:b], thing[:] plot(DFT[2, :]) # see original function (N points) plot(x) # see power spectrum of transform (N/2 points) plot(abs(y[:N/2])**2) # |y|**2 power from 0 freq to highest freq
http://cs.marlboro.edu/ courses/ fall2014/jims_tutorials/ fourier/ Nov_7
last modified Friday November 7 2014 12:49 pm EST

attachments [paper clip]

     name last modified size
[TXT]nov7_play.html Nov 7 2014 11:36 am 239kB    nov7_play.ipynb Nov 7 2014 11:36 am 46.3kB