Frequency Spectrum of a Noisy Signal

Manipulate[SeedRandom[0];data=Table[Sin[i x]+RandomReal[{-n,n}],{x,1,t}];ListLinePlot[
If[type==="signal",
data,
Take[Abs[Fourier[data]],Round[Length[data]/2]]
],AxesOrigin->{1,0},
PlotRange->If[type==="signal",{-5,5},{0,10}],ImageSize->450,ImagePadding->{{25,25},{25,25}},Joined->joined,Filling->If[filled,Axis,None]],{{i,1,"underlying frequency"},0,π},{{t,100,"sample size"},10,2000,10},{{n,1,"noise"},0,5},
{{type,"signal","plot type"},{"signal","spectrum"}},{{joined,True,"joined"},{True,False}},{{filled,False,"filling"},{True,False}},TrackedSymbols:>{i,t,n,type,filled,joined}]

This Demonstration generates a sine wave signal with random noise. You can visualize a plot of the signal's amplitude or its frequency spectrum. The frequency spectrum is calculated using the discrete Fourier transform of sampled amplitude values.

Contributed by: Jon McLoone