# NFourierTransform gives wrong result

This is my code:

Needs["FourierSeries"]

duration = 30;

tau = -100025;
t01 = tau - duration/2;
tf1 = t01 + duration;

intensity = 2.025*^10 ;

omegaL = 1240/78025;

Emax := Sqrt[8*Pi*intensity]

Eopt[t_, tau_] =
Emax*(HeavisideTheta[t - t01] - HeavisideTheta[t - tf1])*
Cos[Pi*(t - (t01 + tf1)/2)/duration]^2*
Exp[I*omegaL*(t - (t01 + tf1)/2)];
Plot[Re[Eopt[t, tau]], {t, t01, tf1}, PlotRange -> All,
PlotPoints -> 1000] Eopt[t,tau] is a pulse with center frequency omegaL and it starts from t01 and end at tf1. I tried to get it's spectrum by NFourierTransform:

NFourierTransform[Eopt[t, tau], t, omega21, WorkingPrecision -> 10,
AccuracyGoal -> 10]


Here, the omega21 could be any value!

Then the NFourierTransform always gives zero! I don't know why. The spectrum of the pulse should not be zero! By the way, I want to ask that how does the function FourierTransform work inside? I find it has few options and I can't understand it's mechanism. If it can give me good result, I'd like to accept it.

• Why are passing tau_ as argument to your Eopt function, but inside the function, there is no tau to be seen? Oct 20 '17 at 2:48
• This is the test code, fow now the tau is fixed for simplicity. If this code works, then I will calculate results for different values of tau. The tau is very import in the next step of my code. Oct 20 '17 at 2:51
• This is the test code Ok,. In this case, all what you have to do to see the problem is to plot your function Eopt against t and you'll see it is all zero. So I do not know why you are surprised that its fourier transform is zero. Oct 20 '17 at 3:00
• Uh, actually, the value of Eopt[t,tau] is complex, so we should plot it's real part, i.e. it's physical import part. Oct 20 '17 at 3:04
• I get zero for real part and zero for complex part and zero for the magnitude. Could you please show a plot of Eopt[t] showing it is not zero including code you used to plot it? Oct 20 '17 at 3:07

It's HeavisideTheta that causes trouble. As mentioned in the Possible Issues of its document:

Numerical routines can have problems with discontinuous functions.

After replacing HeavisideTheta with UnitStep, the numeric transform works well:

NFourierTransform[Eopt[t, tau] /. HeavisideTheta -> UnitStep, t, -1]

(* -21288.1 - 31300.4 I *)

• Thanks, it works! Oct 20 '17 at 7:11
• @Bettertomo Thanks for accepting. Actually you don't need to accept so fast, you can wait for 24 hours or even longer to see if someone will come up with a better answer. :) Oct 20 '17 at 7:25
• Once more, with feeling: "use HeavisideTheta[] for symbolic work, and UnitStep[] for numerical work". (@Bettertomo) Oct 26 '17 at 13:19
• @J. M. Thanks! I'll remember it. Oct 26 '17 at 14:35

Get rid of the extraneous tau value in the function definition. Then use FourierTransform to get a symbolic answer, and then plot. With the constants as defined by the OP:

Eopt[t_] =
Emax*(HeavisideTheta[t - t01] - HeavisideTheta[t - tf1])*
Cos[Pi*(t - (t01 + tf1)/2)/duration]^2*
Exp[I*omegaL*(t - (t01 + tf1)/2)];

ft[w_] = FourierTransform[Eopt[t], t, w]

Plot[Re[ft[w]], {w, -3, 0}, PlotRange -> All, PlotPoints -> 1000] ft[-1]

• I've tried FourierTransform, it even works if I keeps the parameter tau of Eopt. But FourierTransform gives out a function that seems to be a superposition of trigonometric function with coefficient expressed by series of w, i.e. the variable in spectra domain. I don't know the precision of this approximation, so I hesitate to use it. Oct 20 '17 at 4:21
• @Bettertomo FourierTransform finds the analytic solution for Fourier transform i.e. it's not making any approximation. You might encounter bugs though. Oct 20 '17 at 13:32