Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
testData = Table[N@Sin[500 x], {x, 0, 100}];
ListLinePlot[Abs[Fourier[testData]], PlotRange -> Full]

Gives me

enter image description here

Which I do not expect because the Fourier Transform is FourierTransform[Sin[500 x], x, f],

I Sqrt[[Pi]/2] DiracDelta[-500+f]-I Sqrt[[Pi]/2] DiracDelta[500+f]

I'm not saying that Mathematica's Fourier function is somehow faulty. But could someone please explain why there isn't a peak around 500? This is the frequency of the signal after all...

share|improve this question
1  
This may be relevant: How to make Fourier behave like FourierTransform? – Silvia Jan 19 at 22:18
1  
Aliasing. – Rahul Narain Jan 20 at 0:32

1 Answer

up vote 3 down vote accepted

As mentioned by @Rahul, you have not sampled your sine wave often enough and have introduced artifacts due to aliasing. The frequency of Sin[500 x]=Sin[2 Pi f x] is $f=500/(2\pi)$, which is about 80 Hz. At least two samples per cycle are required to avoid aliasing, hence the default $x$ interval of 1 in {x,0,100} must be reduced to less than about $1/(2*80)=0.006$.

In addition, the discrete fast Fourier transform assumes periodicity. Hence, care must be taken to match endpoints precisely. An interval without an exact integral multiple of the sine wavelengths will return blurred Dirac delta functions.

I set the sampling interval to $(1/f)/4$, which is small enough to avoid aliasing. There are an integral number of wavelengths, 100*(2 Pi/500)/4, and the endpoints are matched.

testData = Table[N@Sin[500 x], 
              {x, 0, 100*(2 Pi/500)/4 - (2 Pi/500)/4, (2 Pi/500)/4}];
ListLinePlot[Abs[Fourier[testData]], PlotRange->Full]
share|improve this answer
Great answer. How do I get the right values on the x-axis? I understand that that the DataRange option would be appropriate. And that first I have to select only the first half of the graph. But then I also need to know what the maximum frequency is... which may be simple in this case but what if I didn't know what function I did the Fourier transform on? – Anon Jan 20 at 8:27
@Anon The maximum frequency will be SamplingFrequency/2 and if you have an arbitrary function where you don't know if the end points line up, you typically use a window function to bring the end-points to zero. It sounds like you're having trouble in the signal processing part than Mathematica. If so, I would suggest Signal Processing for some of the conceptual questions on DSP :) – rm -rf Jan 20 at 16:05
Perhaps it's a bit of both, yes. Anyway a lot of great help here. Thank you a lot. – Anon Jan 20 at 16:20
@rm-rf Indeed, but you have to take care that in order to get the maximum frequency at the end of the scale you have to drop the second half of the list. This also prevents the second peak from showing up. DataRange can be used to get the axis labeling right. Set it to {0, SamplingFrequency/2}. – Sjoerd C. de Vries Jan 20 at 18:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.