Fun with Fourier! Using the supplied Mathematica code, answer each question (Q) on a separate sheet of paper. There is no need to print off any Mathematica results. Start with a pure tone that has exactly twenty cycles in the sampling interval. Notice that the Fourier has peaks at approximately 20 and 256-20... Q1: Why the Abs[] in the plot? A1: can't plot complex numbers; could plot, say, real part of complex, but Abs[] is related to actual wave amplitude, the real part would be affected by phase of wave. Q2: Why are there two peaks for one frequency? A2: real-valued data are a combination of + & - frequencies as in sin(theta)=(exp(I theta)-exp(-I theta))/(2 I) The negative frequencies are "aliased-up" by adding N1=256 so -20+256+(+1 cuz of how Mathematica stores stuff)=237 N1=256 data = Table[N[Sin[20 2 Pi k/N1] ], {k, N1}]; ListLinePlot[data] Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->All] Q3: But where are those Fourier peaks exactly? A3: 21 & 237 (really 20 &256-20=236, but Mathematica stores results +1) ListLinePlot[Abs[Data],PlotRange->{{1,30},All}] ListLinePlot[Abs[Data],PlotRange->{{230,260},All}] Q4: The input wave had an amplitude of 1, what is the magnitude of the resulting Fourier transform? (Note it's not 1-to-1; different versions of "Fourier" will produce different scaling factors.) A4: data[[21]]=8 What happens if we have a constant added to the wave (so called DC Offset)? data = Table[N[Sin[20 2 Pi k/N1] +1 ], {k, N1}]; ListLinePlot[data] Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->{{1,30},All}] Q5: The input wave had an amplitude of 1 and a DC Offset of 1, what are the magnitudes of the resulting Fourier coefficients? (Note it's not 1-to-1; different versions of "Fourier" will produce different scales and the DC Offset scale is different from the sinusoidal amplitude scale.) A5: data[[21]]=8, data[[1]]=16 If you want the harmonic number to exactly match where the data is: Data2=RotateLeft[Data,1] ListLinePlot[Abs[Data2],PlotRange->{{1,30},All}] This has the added benefit of moving the usually uninteresting DC Offset to the end of the list. If we make a complex wave we can have just one peak: data = Table[N[Exp[I 20 2 Pi k/N1] ], {k, N1}]; ListLinePlot[Re[data]] ListLinePlot[Im[data]] ListLinePlot[{Re[data],Im[data]},PlotRange->{{1,30},All}] COMMENT: Mathematica actually uses a slightly different sign convention then we used in class. With the in-class sign convention Exp[I 20 2 Pi k/N1] would have a peak at 20 not 256-20. This difference rarely matters, but if you want Mathematica to reproduce our signs: Data2=Fourier[data, FourierParameters->{1,-1}]; Note: Re[] takes the real part of a complex number, Im[] the imaginary Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->All] data = Table[N[Exp[-I 20 2 Pi k/N1] ], {k, N1}]; Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->All] Q6: Which one had the peak at about 20? A6: Exp[-I 20 2 Pi k/N1] InverseFourier takes the inverse Fourier transform: data = Table[N[Sin[20 2 Pi k/N1] ], {k, N1}]; Data=Fourier[data]; data2=InverseFourier[Data] Max[Abs[data2-data]] Q7: What is the maximum difference between data and InverseFourier[Fourier[data]]? This difference is "round off error" due to the limited precision of computer calculations. A7: -16 Out[19]= 3.7238 10 In real life signals usually come with noise...here we add some random noise to the sinusoidal: data = Table[N[Sin[20 2 Pi k/N1] + (RandomReal[] - 1/2)], {k, N1}]; it looks rough (and real, i.e., usual); now Fourier Transform: Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->{{1,30},All}] We added random noise with amplitude +-.5 to a sinusoidal of amplitude 1, nevertheless the peak stands out. We can estimate the noise where the signal is not: Mean[Abs[Part[Data,25;;230]]] Q8: What is the ratio: signal/noise in the Fourier transformed Data? A8: Mean=0.256797, so S/N=8/0.256797=31.153 We can make a combination of frequencies: data = Table[N[Sin[10 2 Pi k/N1] + 2 Sin[15 2 Pi k/N1] + 3 Sin[20 2 Pi k/N1] ], {k, N1}]; ListLinePlot[data] Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->{{1,30},All}] Data2=RotateLeft[Data,1]; Q9: Are the amplitudes of these frequencies as expected? What is the proportionality factor between amplitude and Fourier coefficient? Abs[{Data2[[10]],Data2[[15]],Data2[[20]]}] A9: Out[30]= {8., 16., 24.}, so FFT amplitude = 8x sinusoidal amplitude Here is a more complex combination: data = Table[N[Sin[10 2 Pi k/N1] + 1/3 Sin[3 10 2 Pi k/N1] + 1/5 Sin[5 10 2 Pi k/N1] + 1/7 Sin[7 10 2 Pi k/N1]], {k, N1}]; ListLinePlot[data] ListLinePlot[data,PlotRange->{{1,50},All}] Q10: Describe (words) what this input wave looks like. A10: square wave with bumps on top Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->{{1,80},All}] ListLinePlot[Abs[Data],PlotRange->{{160,260},All}] Q11: report each harmonic number & corresponding Fourier coefficient A11: Data2=RotateLeft[Data,1]; Abs[{Data2[[10]],Data2[[30]],Data2[[50]],Data2[[70]]}] Out[35]= {8., 2.66667, 1.6, 1.14286} 1/% 8 Out[36]= {1., 3., 5., 7.} here is a "sawtooth" wave: data = Table[N[Mod[k,20]-2416/256], {k, N1}]; ListLinePlot[data]; Data=Fourier[data]; ListLinePlot[Abs[Data],PlotRange->{{1,80},All}] ListLinePlot[Abs[Data],PlotRange->All] Q12: report the first four harmonic number & corresponding Fourier coefficient A12: Abs[Part[Data,1;;80]] ... pick out: 14 47.5454 27 20.0831 39 12.4721 52 11.8403 65 10.6301 78 8.94432 Data2=RotateLeft[Data,1]; Abs[{Data2[[13]],Data2[[26]],Data2[[38]],Data2[[51]],Data2[[64]],Data2[[77]],Data2[[90]],Data2[[102]]}] Out[44]= {47.5454, 20.0831, 12.4721, 11.8403, 10.6301, 8.94432, 6.9433, 5.78975} REMARK: with a period of 20 there are 12.8 cycles in 256 Below is a "running average" of five successive data points Q13: describe how the data2 and Data2 differ from data and Data A13: discontinuous drop is particularly smoothed; becoming more triangular ListLinePlot[{data2,data},PlotRange->{{1,80},All}]; data2=Table[Sum[data[[k]],{k,Max[1,i-5],i}]/5,{i,N1}]; ListLinePlot[data2]; Data2=Fourier[data2]; ListLinePlot[Abs[Data2],PlotRange->All]; Heterodyne: Lets take our basic tone and multiple it by another tone (this one complex) data = Table[N[Sin[20 2 Pi k/N1] ], {k, N1}]; data2 = Table[N[Sin[20 2 Pi k/N1] Exp[-I 5 2 Pi k/N1] ], {k, N1}]; Data=Fourier[data]; Data2=Fourier[data2]; ListLinePlot[Abs[Data],PlotRange->{{1,30},All}] ListLinePlot[Abs[Data2],PlotRange->{{1,30},All}] ListLinePlot[Abs[Data],PlotRange->{{230,260},All}]; ListLinePlot[Abs[Data2],PlotRange->{{230,260},All}]; Q14: What is the result? A14: shifted right 5 units If we use a real tone: data = Table[N[Sin[20 2 Pi k/N1] ], {k, N1}]; data2 = Table[N[Sin[20 2 Pi k/N1] Sin[ 5 2 Pi k/N1] ], {k, N1}]; Data=Fourier[data]; Data2=Fourier[data2]; ListLinePlot[Abs[Data],PlotRange->{{1,30},All}] ListLinePlot[Abs[Data2],PlotRange->{{1,30},All}] ListLinePlot[Abs[Data],PlotRange->{{230,260},All}]; ListLinePlot[Abs[Data2],PlotRange->{{230,260},All}]; Q15: What is the result? A15: shifted both left and right by 5 (peak at 21 -> half-height peaks at 16 & 26) FYI: perhaps the trig identity: 2 sin(A) sin(B)= cos(A-B) - cos(A+B) is a familiar form of these results FYI2: You might recall "beats"...same story Q16: Assume you sampled every 0.1ms (i.e. Delta =10^-4 sec) for N=1024 total samples, so the total time sampling was about 0.1 sec, and then made a Fourier Transform (FFT). What is the actual frequency (in Hz) of the first non-DC FFT component, i.e., the one Mathematica reports in Data[[2]]. A16: 1 cycle in 1024E-4 seconds, about 10 Hz