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