{VERSION 4 0 "APPLE_PPC_MAC" "4.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "" 1 24 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{PSTYLE "Normal " -1 0 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Fixed Width" -1 17 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 0 1 2 2 2 2 2 2 3 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 17 1 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "R3 Fon t 0" -1 256 1 {CSTYLE "" -1 -1 "Helvetica" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "R3 Font 2" -1 257 1 {CSTYLE "" -1 -1 "Courier" 1 14 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Author" -1 258 1 {CSTYLE "" -1 -1 "Times " 1 14 0 0 0 1 1 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }} {SECT 0 {PARA 17 "" 0 "" {TEXT -1 77 " 2001 Oregon State University \+ version November 14, 2001" }}{PARA 17 "" 0 "" {TEXT -1 6 " " }}{PARA 18 "" 0 "" {TEXT 256 31 "Fast Fourier Tran sforms of Data" }}{PARA 258 "" 0 "" {TEXT -1 17 "by David McIntyre" }} {PARA 258 "" 0 "" {TEXT -1 43 "Physics Department, Oregon State Univer sity" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 92 "This is a simple template worksheet you can use to do Fast Fourier Transforms (FFT) on data." }}{PARA 0 "" 0 "" {TEXT -1 73 "The FFT relies on data having been sampled with a fixe d time interval of " }{XPPEDIT 18 0 "Delta" "6#%&DeltaG" }{TEXT -1 17 " and a total of " }{XPPEDIT 18 0 "2^N" "6#)\"\"#%\"NG" }{TEXT -1 41 " points, giving a total time interval of " }{XPPEDIT 18 0 "T=Delta*2^ N" "6#/%\"TG*&%&DeltaG\"\"\")\"\"#%\"NGF'" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 24 "with(stats):with(plots):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "with(linalg):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "There must be " }{XPPEDIT 18 0 "2^N" "6#)\"\"#%\"NG" }{TEXT -1 96 " points in the file. Set N here. The files saved on the PCs with so und cards have 1024 points." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "N:=10;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 109 "Read data from file and put into sequence volt_data. Note use of left quotes (vs right \+ or normal quotes). " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "vol t_data:=importdata(`/home/mathphys/paradigm1/data/x.x`,1):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 39 "For the PC sound cards the sample time " }{XPPEDIT 18 0 "Delta " "6#%&DeltaG" }{TEXT -1 84 " is determined by t he sample rate of 22050 Hz. Use this to build up the time array." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "Delta:=1/22050;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "time_array:=array([seq(k*Delta,k=1. .2^N)]):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 261 "Now put the voltage \+ data in a real array and fill the imaginary array (which is needed for the FFT) with zeroes. Note that the voltage data from the PC sound c ards is really just the digital value after converting the analog sign al. The range is -128 to +128." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "re_data:=array([volt_data(k),k=1..2^N]):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "im_data:=array([seq(0,k=1..2^N)]):" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 74 "To plot data need to convert array s into lists (see Heck Maple book p.215)" }{MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "re_plotdata:=convert(zip((a, b)->[a,b],time_array,re_data),'list'):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 69 "plot(re_plotdata,labels=[`TIME (s)`,VOLTAGE],style=li ne,color=black);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 216 "Now perform \+ FFT on data. Note that the FFT algorithm replaces the original arrays with the transform arrays, so the original data is lost. The transfo rm only gives frequency information up to the Nyquist frequency " } {XPPEDIT 18 0 "f[N]=1/(2 Delta)" "6#/&%\"fG6#%\"NG*&\"\"\"F)*&\"\"#F)% &DeltaGF)!\"\"" }{TEXT -1 145 ", and the resultant transform is repeat ed twice. So, in effect, there are half as many points in the frequen cy spectrum as in the original data." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "FFT(N,re_data,im_data):" }}}{SECT 0 {PARA 0 "" 0 "" {TEXT -1 17 "Details about PSD" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 177 "Now find po wer spectral density (PSD). To do so we need to know what the samplin g interval is. The FFT itself is independent of the sample interval b ut the PSD (which will be " }{XPPEDIT 18 0 "V^2" "6#*$%\"VG\"\"#" } {TEXT -1 53 "/Hz) is dependent on it. The time interval is called " } {XPPEDIT 18 0 "Delta" "6#%&DeltaG" }{TEXT -1 186 ". The factor of 2 a ccounts for fact that FFT gives info from -f to f, and we only want to use a single sided PSD. Plot will also show that info is repeated at higher integer values (i>" }{XPPEDIT 18 0 "2^(N-1)+1" "6#,&)\"\"#,&% \"NG\"\"\"F(!\"\"F(F(F(" }{TEXT -1 67 " actually corresponds to negati ve frequencies). PSD is given by: " }{XPPEDIT 18 0 "PSD[i]=2*Delta/2 ^N*abs(FFT[i])^2" "6#/&%$PSDG6#%\"iG**\"\"#\"\"\"%&DeltaGF*)F)%\"NG!\" \"-%$absG6#&%$FFTG6#F'F)" }{TEXT -1 67 ", except for first and last po ints, where factor of 2 is not there." }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 153 "You can mostly ignore above and consider power as simply re^2 + imag^2. The following statement makes the array PSD out of th e real and imaginary parts." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "PSD:=zip((a,b)->2*(a^2+b^2)*Delta/2^N,re_data,im_data):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "PSD[1]:=PSD[1]/2:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "PSD[2^(N-1)+1]:=PSD[2^(N-1)+ 1]/2:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "Construct array of frequ ency points, each spaced by the frequency interval " }{XPPEDIT 18 0 "1 /Delta/(2^N)" "6#*(\"\"\"F$%&DeltaG!\"\")\"\"#%\"NGF&" }{TEXT -1 7 ", \+ with " }{XPPEDIT 18 0 "2^(N-1)" "6#)\"\"#,&%\"NG\"\"\"F'!\"\"" }{TEXT -1 23 "points in the spectrum." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "fcoords:=array([seq(k/(Delta*2^N),k=0..2^(N-1))]):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 117 "If the DC term is too big, you can set i t to zero with this statment, so you can see the rest of the spectrum \+ easily." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "#PSD[1]:=0:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "psd_plotdata:=convert(zip((a,b)->[a ,b],fcoords,PSD),'list'):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 74 "plot(psd_plotdata,style=line,color=black,labels=[`FREQUENCY (Hz)`, POWER]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 55 "You may want to plot \+ a smaller portion of the spectrum:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "plot(psd_plotdata,h=0..1000,labels=[`FREQUENCY (Hz)`,POWER],style= line,color=black);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 93 "If you want to look at the voltage spectrum, just take the square root of the pow er spectrum:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "VSD:=[seq(sqrt(PSD[ i]),i=1..2^(N-1)+1)]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 112 "p ointplot([seq([fcoords[n],VSD[n]],n=1..2^(N-1)+1)],labels=[`FREQUENCY \+ (Hz)`,VOLTAGE],connect=true,color=black);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 198 "Here are the all the necessary statements repeated to do another FFT on another data set. You will have to enter the new file \+ names and change the final array names to avoid erasing your other dat a." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "volt_data:=importdata (`/home/mathphys/paradigm1/data/x.x`,1):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "re_data:=array([volt_data(k),k=1..2^N]):" }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 34 "im_data:=array([seq(0,k=1..2^N)]):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "re_plotdata:=convert(zip((a,b)->[a,b],tim e_array,re_data),'list'):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "FFT(N, re_data,im_data):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "PSD:=zip((a,b) ->2*(a^2+b^2)*Delta/2^N,re_data,im_data):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "PSD[1]:=PSD[1]/2:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "PSD[2^(N-1)+1]:=PSD[2^(N-1)+1]/2:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "psd_plotdata:=convert(zip((a,b)->[a,b],fcoords,PSD),'list'):" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "VSD:=[seq(sqrt(PSD[i]),i=1..2^(N-1) +1)]:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 22 "Here is plot of signal" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 69 "plot(re_plotdata,labels=[`TIME (s )`,VOLTAGE],style=line,color=black);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 32 "Here is plot of voltage spectrum" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 105 "pointplot([seq([fcoords[n],VSD[n]],n=1..50)],labels=[`FREQUEN CY (Hz)`,VOLTAGE],connect=true,color=black);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "26" 0 }{VIEWOPTS 0 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }