import Numeric import FFT import Gnuplot L = 128 U = 1./8 UL = int(L*U) gp = Gnuplot.Gnuplot() gp.title = ('FFT Demo') gp('set xrange [0:%s]' % L) X = range(L) f = Numeric.array([1.0]*UL+[0.0]*(L-UL)) ### folding #f = Numeric.array([1.0]*(UL/2)+[0.0]*(L-UL+1)+[1.0]*(UL/2-1)) ### non-sharp cutoff S = [2./UL*i for i in range(UL/2)] SR = S[:] SR.reverse() #f = Numeric.array([1.0]*(UL/4)+SR+[0.0]*(L-UL-UL/2+1)+S+[1.0]*(UL/4-1)) d = Gnuplot.Data(X,f, with='lines lw 2', title='Original Function') gp.plot(d) raw_input('Press Return') F = FFT.fft(f) Fr = Gnuplot.Data(X,F.real, with='lines lw 2', title='FFT Real part') Fi = Gnuplot.Data(X,F.imag, with='lines lw 2', title='FFT Imaginary part') gp.plot(Fr,Fi) raw_input('Press Return')