Re: graphing frequency & amplitude?
- To: mathgroup at smc.vnet.net
- Subject: [mg79206] Re: graphing frequency & amplitude?
- From: c <flutzpah at gmail.com>
- Date: Sat, 21 Jul 2007 04:22:35 -0400 (EDT)
- References: <f7pnki$msj$1@smc.vnet.net>
On Jul 20, 1:18 am, efi... at fas.harvard.edu wrote: > Hi, > > I am trying to create a graph that graphs frequency versus amplitude of a sound > made by the sum of two sine waves. I tried fourier transforming them and > graphing it, yet it looks to me like the graph is plotting time rather than > frequency. How do I change this? > > Plot[10*Sin[200t] + 10*Sin[100t], {t, 0, 1}] > > data = Table[10*Sin[200t] + 10*Sin[100t], {t, 0, 100}] > > ListPlot[Abs[Fourier[data]], PlotJoined -> True, PlotRange -> All] > > Thank you for the help! > Emily Hi, Emily, Mathematica is plotting the correct transform, but of some poorly sampled data. The Table you give for your data is sampling far too rarely to capture those high frequencies (~16 and 31 Hz). If, instead, you sample 100 times as fast (and still only capture 100 points, as in data = Table[10*Sin[200*t] + 10*Sin[100*t], {t, 0, 1, 0.01}]; ) and then ListPlot the transform, I think things will be much more to your liking. I usually use the following function: DiscreteFourier[data_] := Module[ {ft=Abs[Fourier[data[[All, 2]]]]}, dataNew=RotateRight[ft, Quotient[Length[ft],2]]; freq[t_]:= With[{tau = t[[2]]-t[[1]], n=Length[t]}, Table[-tau/2+i/ (n tau), {i, 0, n-1}]]; Take[ Transpose[ { freq[data[[All, 1]]], RotateRight[ ft, Quotient[Length[data], 1]]} ], Round[Length[ft]/2] ] ] which will give you a discrete Fourier transform of sampled data, but formatted in terms of Hz (rather than radian frequencies) and it gets rid of the "mirror" frequencies that Mathematica gives you. It does require that you feed it a _two_columned_ dataset, where the first column is time, and the second, amplitude. You can get that by explicitly requesting {time, amplitude} pairs from your table: data = Table[{t, 10*Sin[200*t] + 10*Sin[100*t]}, {t, 0, 1, 0.01}]; Good luck!