2
$\begingroup$

For $t\in\mathbb{R}_{\ge 0}$ and $s\in\mathbb{R}$, let

$$f(t)=\begin{cases}\int_{0}^{t}\exp\left(-\frac{1}{1-s^{2}}\right)\,ds,&|s|<1, \\ 0,&|s|\ge 1\end{cases}$$

I plotted this without problems using

Plot[NIntegrate[
Piecewise[{{Exp[-1/(1 - s^2)], Abs[s] < 1}, {0, Abs[s] >= 1}}], {s, 
0, t}], {t, 0, 2}]

However, I am having troubles plotting $\hat{f}(\omega)$. I tried

Needs["FourierSeries`"]

Plot[NFourierTransform[
NIntegrate[
Piecewise[{{Exp[-1/(1 - s^2)], Abs[s] < 1}, {0, Abs[s] >= 1}}], {s,
0, t}], t, ω], {ω, -20, 20}]

without success. I can see that the problem is the t. However, since that is the variable I am taking the Fourier transform with respect to, I cannot arbitrarily assign it a numerical value. Any help would be appreciated.

$\endgroup$
  • $\begingroup$ Have you tried sampling your $f(t)$ and then perform FFT with Fourier? $\endgroup$ – BlacKow Dec 8 '16 at 14:11
  • $\begingroup$ @BlacKow Well, I actually have a problem using the DTFT, namely Plot[FourierSequenceTransform[ NIntegrate[ Piecewise[{{Exp[-1/(1 - s^2)], Abs[s] < 1}, {0, Abs[s] >= 1}}], {s, 0, n*0.1}, AccuracyGoal -> 20], {n, -20, 20}, \[Omega]], {\[Omega], -20, 20}], then n is not in the FourierSequenceTransform argument. $\endgroup$ – Jason Born Dec 8 '16 at 20:47
  • $\begingroup$ Why not use the integration property of the Fourier transform? If I've done the algebra right, what you want works out to be I NFourierTransform[Piecewise[{{Exp[-1/(1 - s^2)], -1 < s < 1}}], s, ω]/ω. $\endgroup$ – J. M. will be back soon Dec 9 '16 at 20:15
3
$\begingroup$

One thing that can be problematic is to use functions that can deal only (or better) with numerical input values as arguments (the limits to NIntegrate in this example) to functions that do symbolic manipulations of their inputs (like Plot). What helps most of the time is to wrap things like taking numerical integrals in a function that only evaluates if their inputs are numerical but stay unevaluated for symbolic inputs.

For your example you can e.g. try something like this:

f[s_?NumericQ] = Piecewise[{{Exp[-1/(1 - s^2)], -1 < s < 1}}];
fintegral[t_?NumericQ] := NIntegrate[f[s], {s, 0, t},
                            AccuracyGoal -> 5,
                            Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule"}
                          ];
Plot[fintegral[t], {t, -2, 2}]
Needs["FourierSeries`"];
fintegralfourier[\[Omega]_?NumericQ] := NFourierTransform[fint[t], t, \[Omega],
                                          AccuracyGoal -> 5]
Off[NIntegrate::deoncon, NIntegrate::deondiv, NIntegrate::deorel]
Plot[Im@fintegralfourier[\[Omega]], {\[Omega], -20, 20}, 
  MaxRecursion -> 0, PlotPoints -> 10, PlotRange -> All
]

f integral

Here i used ?NumericQ in the definition of the helper functions to let them stay unevaluated for symbolic input. This makes fintegral more safe to use as in Plot and NFourierTransform. Also i used a cheaper method as option for NIntegrate since we know that our integrand is very smooth and easy to integrate.

Now the next problem is, that since NFourierTransform internally also uses numerical integration, we do nested NIntegrate calls, which is very slow.

The third problem is that the function fint is similar to a step function, where we know that the fourier transform has a pole at zero. See for example

g = Piecewise[{{3 x - 4 x^3, -1/2 < x < 1/2}}, Sign[x]]
Plot[g, {x, -1, 1}]

smoothstep

where FourierTransform knows the exact transform result

gfourier=FourierTransform[Piecewise[{{3 x - 4 x^3, -1/2 < x < 1/2}}, Sign[x]], x, \[Omega]]

gfourier formula

which has a pole at zero:

Plot[Im@gfourier, {\[Omega], -10, 10}]

gfourier plot

So now it's understandable that NFourierTransform will have problems with numerical integrations near $\omega\approx 0$.

$\endgroup$

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.