# Need help for Discrete Fourier Transform on an experimental data

I have an experimental data, which is basically a time-domain triangle function.

Part I: In theory

The time-domain figure is shown in Fig. 1(a), and the corresponding frequency-domain figure is shown in Fig. 1(b). The codes are shown below

    f1[x_] := Piecewise[{{1*Abs[x], Abs[x] < 2.5}, {1*Abs[2.5], Abs[x] >= 2.5}}];
Plot[f1[x], {x, -10, 10}, Axes -> False, Frame -> True,  PlotRange -> All, AspectRatio -> .67,  LabelStyle -> Directive[Black, FontSize -> 18],  FrameLabel -> {{"Intensity", None}, {"Time (s)", None}},  ImageSize -> {300, 200}]

Chop@FourierTransform[f1[x], x, \[Omega]];
Plot[-(0.7978/\[Omega]^2) + (0.7978 Cos[2.5 \[Omega]])/\[Omega]^2 +  6.266 DiracDelta[\[Omega]], {\[Omega], -10, 10}, Frame -> True,  Axes -> False, PlotRange -> All, AspectRatio -> .67, Axes -> False,  LabelStyle -> Directive[Black, FontSize -> 18], FrameLabel -> {{"Intensity", None}, {"Frequency (Hz)", None}}, ImageSize -> {300, 200}]


Part II: In experiment

Then, I consider the case in experiment, using the data sampled from the same function. The time-domain figure is shown in Fig. 2(a), and the frequency-domain figure is shown in Fig. 2(b). The corresponding codes are shown below

    data = Table[{x, f1[x]}, {x, -10, 10, 0.1}];
ListLinePlot[data, PlotRange -> All, PlotStyle -> {Red},  Joined -> False, Frame -> True, AspectRatio -> .67, Axes -> False,  LabelStyle -> Directive[Black, FontSize -> 18], FrameLabel -> {{"Intensity", None}, {"Time (s)", None}},  ImageSize -> {300, 200}]

{times, vals} = Transpose[data];
IFT[(w_)?NumberQ, vals_, times_] :=  Total[vals*Exp[(-I)*2 \[Pi]*w*times]]/Length[times];
Plot[Abs[IFT[w, vals, times]], {w, -0.5, 0.5}, PlotRange -> All,   Frame -> True, Axes -> False,   LabelStyle -> Directive[Black, FontSize -> 18], PlotStyle -> {Red},  AspectRatio -> .67, ImageSize -> {300, 200},  FrameLabel -> {{"Amplitude", None}, {"Frequency (Hz)", None}}]


Now, Let us compare Fig.1(b) and Fig.2(b). They are different!! I hope Fig. 1(b) should be the same as Fig. 2(b), especially, (1) remove the side lobes in Fig 2 (b); (2) the width of Fig 2 (b) should be the same as Fig 1 (b). How can I do this? Any help or suggestion is highly appreciated.

• There are two problems : 1) there shouldn't be 2 Pi in your calculus of IFT[...]=... 2) substract 2.5 to your data, such that your data are considered to be 0 outside the time interval [-10,10] (otherwise the integration Total[ ...times]]should extend time from -Infinity to +Infinity, which is impraticable) – andre314 Apr 3 '16 at 19:22
• For information : the spike is the HeavisideLambda distribution (= the triangle distribution), equal to the convolution of two identical HeavisidePi distributions (= the box distribution). The Fourier transform is therefore exactly a squared sinus cardinal (Sinc[]^2) – andre314 Apr 3 '16 at 19:53
• @ bill s, I think Fig.1(b) is reasonable for two reasons: 1, it was calculated rigorously by using Mathematica codes ( Chop@FourierTransform[f1[x], x, [Omega]]), as shown above. So the result should be correct. 2, The physical meaning (of no side lobe) is correct. – user14634 Apr 4 '16 at 1:13
• @andre, Your comments are very helpful! After subtracting 2.5 to the data, the side lobes disappear! – user14634 Apr 4 '16 at 2:39

There are a couple of minor things that need to be changed. Following Andre's suggestion, here is the first part:

f1[x_] :=
Piecewise[{{1*Abs[x], Abs[x] < 2.5}, {1*Abs[2.5],
Abs[x] >= 2.5}}] - 2.5;
Plot[f1[x], {x, -10, 10}, Axes -> False, Frame -> True,
PlotRange -> All, AspectRatio -> .67,
LabelStyle -> Directive[Black, FontSize -> 18],
FrameLabel -> {{"Intensity", None}, {"Time (s)", None}},
ImageSize -> {300, 200}]

ft[ω_] = Chop@FourierTransform[f1[x], x, ω];
Plot[Abs[ft[ω]], {ω, -10, 10}, Frame -> True,
Axes -> False, PlotRange -> All, AspectRatio -> .67, Axes -> False,
LabelStyle -> Directive[Black, FontSize -> 18],
FrameLabel -> {{"Intensity", None}, {"Frequency (Hz)", None}},
ImageSize -> {300, 200}]


This shifts the function and also plots the magnitude of the Fourier transform. In the second part:

data = Table[{x, f1[x]}, {x, -10, 10, 0.1}];
ListLinePlot[data, PlotRange -> All, PlotStyle -> {Red},
Joined -> False, Frame -> True, AspectRatio -> .67, Axes -> False,
LabelStyle -> Directive[Black, FontSize -> 18],
FrameLabel -> {{"Intensity", None}, {"Time (s)", None}},
ImageSize -> {300, 200}]

{times, vals} = Transpose[data];
IFT[(w_)?NumberQ, vals_, times_] :=
Total[2* Pi*vals*Exp[(-I)*w*times]]/Length[times];
Plot[Abs[IFT[w, vals, times]], {w, -10, 10}, PlotRange -> All,
Frame -> True, Axes -> False,
LabelStyle -> Directive[Black, FontSize -> 18], PlotStyle -> {Red},
AspectRatio -> .67, ImageSize -> {300, 200},
FrameLabel -> {{"Amplitude", None}, {"Frequency (Hz)", None}}]


The 2*Pi has been relocated and the plot is from -10 to +10 (to align with the plot above). Now they are the same! • Many thanks to bill s for this good answer! – user14634 Apr 4 '16 at 5:39