Random data to fit with a fourier transform
data fit with the FFT
1 # some Discrete and Fast fourier transforms in sage following 2 # a Gilbert Strang Mit Linear Algebra lecture. 3 4 #http://www.youtube.com/watch?v=M0Sa8fLOajA 5 #not sure why strang's and everybody else's versions are negative/conjugate of each other, must be a change in convention... 6 7 spacetime_domain = 8 9 10 rows = 11 for i in : 12 row = 13 for j in : 14 15 16 return (1/ )* 17 18 19 rows = 20 for i in : 21 row = 22 for j in : 23 24 25 return 26 27 28 #basis vectors 29 30 31 return e^(i*((2*pi)*t)) 32 #fbasis(x, y, z)=(w((-1)*(1/(x*y))*z));#*(1/z) 33 34 return 35 36 # sage fast dft 37 38 39 print "spacetime_domain data" 40 print spacetime_domain 41 n = 42 #frequency_domain=vector(map(conjugate, vector(CDF, spacetime_domain).fft().list())).transpose(); 43 frequency_domain= . . 44 print "real frequency domain " 45 print 46 #invdft = vector(map(conjugate, vector(map(conjugate, frequency_domain.list())).fft(direction='backward'))).transpose() 47 invdft = . . 48 reconstructed = 49 plota = 50 plotb = 51 print "perfect point reconstruction" 52 53 54 print axis 55 basisVector = 56 print 57 #simplify/round frequency_domain for speedy plotting 58 #frequency_domain = vector([round(frequency_domain.list()[l].real_part(), 10) + i*round(frequency_domain.list()[l].imag_part(), 10) for l in range(len(frequency_domain.list()))]).transpose() 59 allBasesWithWeights=(basisVector*frequency_domain*(1/n)). . 60 allBasesNoWeights= . 61 plotc = 62 plotd = 63 print "perfect point curve fitting" 64 65 66 67 68 69 70 # strang slow DFT 71 72 73 print "spacetime_domain data" 74 print spacetime_domain 75 n= 76 myDFT= 77 frequency_domain=myDFT*( . ) 78 print "real frequency domain " 79 print 80 myDFTH = 81 invdft=(myDFTH*frequency_domain*(1/n)) 82 reconstructed = 83 print "perfect point reconstruction" 84 #print reconstructed 85 plota = 86 plotb = 87 88 89 print axis 90 basisVector = 91 print 92 #simplify/round frequency_domain for speedy plotting 93 #frequency_domain = vector([(round(frequency_domain.list()[x].real_part(), 10) + i*round(frequency_domain.list()[x].imag_part(), 10)) for x in range(len(frequency_domain.list()))]).transpose() 94 allBasesWithWeights=(basisVector*frequency_domain*(1/n)). . 95 allBasesNoWeights= . 96 plotc = 97 plotd = 98 print "perfect point curve fitting" 99 100 101 102 #performDFT(spacetime_domain)