Fourier[Fourier[{1,2,3,4}]]
gives {1,4,3,2}
instead of a mirror image {4,3,2,1}
. Is there a way to modify the Fourier transform so that this additional shift does not happen?
The formula used for FFT is as follows:
{a, b} = {0, 1};
data = {1, 2, 3, 4};
n = Length[data]; s = Range[n];
f1 = 1/n^((1 - a)/2) Sum[ data[[r]] Exp[2 \[Pi] I b (r - 1) (s - 1)/n], {r, 1, n}]
f2 = 1/n^((1 - a)/2) Sum[ f1[[r]] Exp[2 \[Pi] I b (r - 1) (s - 1)/n], {r, 1, n}]
And it does produce the shift. Is it inevitable for discrete Fourier transform?
The question arose from my attempts to match the discrete Fourier transform of a sampled sequence with an analytical expression obtained for an infinite interval. None of the answers I tried gave a really accurate result. I did some guessing and came up with something like this:
dt = 0.2; L = 20;
pulse[t_] := Sin[t] Exp[-0.1 (t - 2)^2] + Exp[-t^2] - 0.5 Exp[-(t + 2)^2];
TS = Table[{t, pulse[t]}, {t, -L + dt, L, dt}];
fftshift[flist_] := RotateRight[flist, (Length@flist)/2 - 1];
FOURIER[LIST_] := Module[{dt, df, L, \[Mu], num, ord, timelist, ftlist},
dt = LIST[[2, 1]] - LIST[[1, 1]];
L = LIST[[-1, 1]] - LIST[[1, 1]];
num = Length[LIST];
\[Mu] = (L + dt)/Sqrt[2 \[Pi] (num)]; (* this +dt increases the accuracy significantly *)
df = 2 \[Pi]/(num dt);
timelist = RotateLeft[LIST[[All, 2]], num/2 - 1];
ftlist = \[Mu] fftshift[Fourier[timelist, FourierParameters -> {0, 1}]];
Transpose[{df (Range[num] - num/2), ftlist}]
]
f[w_] = FullSimplify[FourierTransform[pulse[t], t, w]]
fft = FOURIER[TS];
Show[ListLinePlot[
Transpose[{fft[[All, 1]], Abs[fft[[All, 2]] - f[fft[[All, 1]]]]}], PlotRange -> {{-20, 20}, All}]]
ListLinePlot[{Transpose[{fft[[All, 1]], Re[fft[[All, 2]]]}], Transpose[{fft[[All, 1]], Re[f[fft[[All, 1]]]]}]}, PlotRange -> {{-10, 10}, All}]
This gives a very good accuracy of ~10^-15. However, when applied twice, this transformation doesn't produce f(-t), as it should in the case of the analytical Fourier, but f(-t-dt), where dt is the sampling step, just like the Fourier[] itself, so can it even be fixed?
ListLinePlot[{Transpose[{TS[[All, 1]], Reverse[TS[[All, 2]]]}], FOURIER[FOURIER[TS]]}, PlotRange -> All]
I have a feeling that something is missing.
InverseFourier[Fourier[{1, 2, 3, 4}]]
returns{1,2,3,4}
. $\endgroup$Fourier
works? $\endgroup$