This is my code:


duration = 30;

tau = -1000`25;
t01 = tau - duration/2;
tf1 = t01 + duration;

intensity = 2.0`25*^10 ;

omegaL = 1240/780`25;

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]

enter image description here

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.

Thanks in advance!

  • $\begingroup$ Why are passing tau_ as argument to your Eopt function, but inside the function, there is no tau to be seen? $\endgroup$ – Nasser Oct 20 '17 at 2:48
  • $\begingroup$ 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. $\endgroup$ – Bettertomo Oct 20 '17 at 2:51
  • $\begingroup$ 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. $\endgroup$ – Nasser Oct 20 '17 at 3:00
  • $\begingroup$ 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. $\endgroup$ – Bettertomo Oct 20 '17 at 3:04
  • $\begingroup$ 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? $\endgroup$ – Nasser 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 *)
  • $\begingroup$ Thanks, it works! $\endgroup$ – Bettertomo Oct 20 '17 at 7:11
  • $\begingroup$ @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. :) $\endgroup$ – xzczd Oct 20 '17 at 7:25
  • 1
    $\begingroup$ Once more, with feeling: "use HeavisideTheta[] for symbolic work, and UnitStep[] for numerical work". (@Bettertomo) $\endgroup$ – J. M. will be back soon Oct 26 '17 at 13:19
  • $\begingroup$ @J. M. Thanks! I'll remember it. $\endgroup$ – Bettertomo 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]

enter image description here

For comparison with xzczd's answer:

-21288.1043 - 31300.4139 I
  • $\begingroup$ 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. $\endgroup$ – Bettertomo Oct 20 '17 at 4:21
  • $\begingroup$ @Bettertomo FourierTransform finds the analytic solution for Fourier transform i.e. it's not making any approximation. You might encounter bugs though. $\endgroup$ – xzczd Oct 20 '17 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.