First a little background: I’ve looked at the following discussions on StackExchange and still racking my head on Fourier
What are the most common pitfalls awaiting new users?
Discrepancy between Matlab and Mathematica Fourier parameters
Comparing ordinates between FourierTransform and Fourier
Let’s Import the data and define a couple of helper functions.
** waveform data link**
waveForm = Import[“filename.csv", "CSV”];
myFFT[a : {{_, _} ...}] :=
Module[{time, y, dt, ft, len, front, back,
freq},(*Extract data and take the Fourier transform*)
time = a[[All, 1]];
y = a[[All, 2]];
dt = time[[2]] - time[[1]];
ft = Abs[Fourier[y, FourierParameters -> {1, -1}]];
(*Identify positive and negative frequencies.Zero frequency mode \
appears at position 1*)
len = If[EvenQ[Length[ft]], Length[ft] + 1, Length[ft]];
front = Take[ft, Ceiling[len/2]];
back = Reverse[Take[ft, -Floor[len/2]]];
ft = front + PadLeft[back, Length[front]];
(*Make frequency units and return FFT*)
freq = Table[i/dt/Length[a], {i, 0, Length[ft] - 1}];
Transpose[{freq, ft}]]
integrateList[t_] := Differences[#1].MovingAverage[#2, 2] & @@
Transpose[t]; (*Trapezoidal Rule *)
Let’s compute the power of the signal
signal = {#1, #2 - 5.1875} & @@@ waveForm; (*Remove DC *)
signalSquared = {#1, #2^2} & @@@ signal;
fft = myFFT[signalSquared];
Let’s now do a Parseval’s Theorem sanity check and compare the area under the curve in time domain and frequency domain to make sure that they are equal
integrateList@signalSquared[[1 ;; All]]
2*integrateList[fft] (*since we are looking at only half the curve *)
I get the following results:
> Time Domain Area Under the Curve = 4.9616 e-6
> Frequency Domain Area Under the Curve = 8.2740 e+8
Clearly a big difference in area! I’ve tried tinkering with the Fourier Parameters but no avail… Any help would be appreciated!
i/dt/Length[a]I suspect you wanti*dt/Length[a]. There may be other issues but that change at least puts things in the correct ballpark. – Daniel Lichtblau Apr 13 '18 at 14:38