# Frequencies doubled in fourier transform [duplicate]

With this code I get a nice plot of the Fourier transform, but the frequencies are doubled. By this I mean that when using a sine wave I generated at 220 Hz, the plot gives me a single peak at 440 Hz. I've tried searching around, but I'm stuck.

 data = Import[
"ExampleFilePath", "Data"];

length = Length[data];

samplerate = 44100;

increment = samplerate/length;

frequency =
Table[f, {f, 0, (samplerate - increment), increment}] //
N;

power = Abs[Fourier[data, FourierParameters -> {-1, 1}]]^2;

powerdata = Transpose[{frequency, power}];


## marked as duplicate by MarcoB, yohbs, bbgodfrey, Michael E2, glSMay 12 '17 at 10:48

• frequency = Table[f, {f, 0, (samplerate - increment), increment}] // N; is not right. This mistake is not related to Mathematica. – Kattern Apr 26 '17 at 2:13
• I think your frequency specification is correct. I am assuming you want the frequency in Hz. I am unclear where you are getting your data from. Is this part of Wolfram example data? – Hugh Apr 26 '17 at 13:42
• Some solutions discussed here: mathematica.stackexchange.com/questions/1714/… – yohbs May 2 '17 at 2:39

You may wish to look here to find some general information on Fourier.

Starting again by making some data we have

samplerate = 44100;
n = 44100;
data = Table[
Cos[2 π 220 t], {t, 0, (n - 1) 1/samplerate, 1/
samplerate}] // N;
ListLinePlot[data[[1 ;; 500]]]


This has about 200 samples in one cycle so the approximate frequency is

    samplerate 1/200.

(* 220.5 *)


which is about what you were after.

Now we run your code and get

length = Length[data];
increment = samplerate/length;
frequency = Table[f, {f, 0, (samplerate - increment), increment}] // N;
power = Abs[Fourier[data, FourierParameters -> {-1, 1}]]^2;
powerdata = Transpose[{frequency, power}];
ListLinePlot[powerdata, PlotRange -> All]


Which shows you have a very low frequency, compared to the sample rate. The usual mirror image is at the other end of the spectrum.

If we just plot the first 500 points of your spectrum we have

ListLinePlot[powerdata[[1 ;; 500]], PlotRange -> All]


Which is correct. Note that the PlotRange-> All is essential since the relevant data will otherwise be ignored.

Hope that helps.