Need help with Fourier transform

243 views
Skip to first unread message

aTPer

unread,
Apr 20, 2021, 4:38:08 AM4/20/21
to sympy
I am trying to compute the integral fourier transform of sin(t),cos(t),-1/t^2 and 2/t^3(look at screenshot). This for checking answers for maths homework/tutorials.
So, I went to the Sympy documentation page and learned the code from there to compute the FTs of the functions defined above but none of it actually works. Then, I tried using the noconds=False This is my code:

from sympy import fourier_transform, exp, cos, sin
from sympy.abc import t,w,o 
fourier_transform(sin(o*t), t, w, noconds=False) 
fourier_transform(cos(o*t), t, w, noconds=False)
 fourier_transform(-1/t**2, t, w, noconds=False)
 fourier_transform(2/t**3, t, w, noconds=False)

Kalevi Suominen

unread,
Apr 20, 2021, 7:01:13 AM4/20/21
to sympy
Fourier transform is currently implemented in SymPy only for integrable functions. None of those functions is integrable so SymPy cannot be used find the transform.

Kalevi Suominen

aTPer

unread,
Apr 20, 2021, 9:05:49 AM4/20/21
to sympy
Thanks Kalevi!
When will Sympy get updated and be able to compute fourier transform of difficult functions? I tried this in matlab and it can do it no prob using the symbolic toolbox. 

emanuel.c...@gmail.com

unread,
Apr 21, 2021, 12:29:50 PM4/21/21
to sympy
Le mardi 20 avril 2021 à 13:01:13 UTC+2, jks...@gmail.com a écrit :
Fourier transform is currently implemented in SymPy only for integrable functions. None of those functions is integrable

I beg your pardon ?

>>> from sympy import fourier_transform, exp, cos, sin, integrate
>>> from sympy.abc import t,w,o 
>>> integrate(sin(o*t),t)
Piecewise((-cos(o*t)/o, Ne(o, 0)), (0, True))
>>> integrate(cos(o*t),t)
Piecewise((sin(o*t)/o, Ne(o, 0)), (t, True))
>>> integrate(1/t**2,t)
-1/t
>>> integrate(2/t**3,t)
-1/t**2

so SymPy cannot be used find the transform.

Please…

>>> from sympy import fourier_transform, exp, cos, sin, integrate, I, pi, oo, latex
>>> from sympy.abc import t,w,o 
>>> integrate(sin(o*t)*exp(-2*I*pi*w*t),(t,-oo,oo))
Piecewise((o/(4*pi**2*w**2*(-o**2/(4*pi**2*w**2) + 1)) + 1/(o*(1 - 4*pi**2*w**2/o**2)), Eq(2*Abs(arg(o)), 0) & (Abs(2*arg(w) + pi) < pi) & (Abs(2*arg(w) - pi) < pi)), (Integral(exp(-2*I*pi*t*w)*sin(o*t), (t, -oo, oo)), True))
>>> integrate(cos(o*t)*exp(-2*I*pi*w*t),(t,-oo,oo))
Piecewise((I/(2*pi*w*(-o**2/(4*pi**2*w**2) + 1)) + 2*I*pi*w/(o**2*(1 - 4*pi**2*w**2/o**2)), Eq(2*Abs(arg(o)), 0) & (Abs(2*arg(w) + pi) < pi) & (Abs(2*arg(w) - pi) < pi)), (Integral(exp(-2*I*pi*t*w)*cos(o*t), (t, -oo, oo)), True))
>>> integrate(1/(t**2)*exp(-2*I*pi*w*t),(t,-oo,oo))
Integral(exp(-2*I*pi*t*w)/t**2, (t, -oo, oo))
>>> integrate(2/(t**3)*exp(-2*I*pi*w*t),(t,-oo,oo))
2*Integral(exp(-2*I*pi*t*w)/t**3, (t, -oo, oo))

So sympy can compute at least the first two, but not via fourier_transform.

BTW, according to Wolfram Alpha,

  • sin(o*t) has transform -I*sqrt(1/2)*sqrt(pi)*(dirac_delta(o + w) - dirac_delta(-o + w))
  • cos(o*t) has transform sqrt(1/2)*sqrt(pi)*(dirac_delta(o + w) + dirac_delta(-o + w))
  • t^(-2) has transform sqrt(1/2)*sqrt(pi)*w*sgn(w)
  • 2/t^3 has transform -I*sqrt(1/2)*sqrt(pi)*w^2*sgn(w)

HTH,

Kalevi Suominen

unread,
Apr 21, 2021, 1:53:15 PM4/21/21
to sympy
A function f on the real line is said to be integrable if the improper integral of its absolute value from -oo to oo is finite. It does not mean that it has an antiderivative.

Note also that the piecewise result above is undefined for real values of w so it does not give a Fourier transform.

Kalevi Suominen

emanuel.c...@gmail.com

unread,
Apr 23, 2021, 8:58:33 AM4/23/21
to sympy
Le mercredi 21 avril 2021 à 19:53:15 UTC+2, jks...@gmail.com a écrit :
A function f on the real line is said to be integrable if the improper integral of its absolute value from -oo to oo is finite. It does not mean that it has an antiderivative.

Ouch ! Language has failed me. Apologies...

aTPer

unread,
Apr 23, 2021, 10:51:57 AM4/23/21
to sympy
Ah yes, thanks for this. Will the Sympy include these symbolic fourier transform results?

The last two: -1/t^2 and 2/t^3 can be solved using the time differentiation and the 'duality' property of Fourier transform. In matlab this can be done by 
syms t w
fourier(-1/t^2) 
I used Maple but it does not work either, only for sin and cos which is just 0.5 amplitude dirac delta pulses. 

S.Y. Lee

unread,
Apr 24, 2021, 4:38:43 AM4/24/21
to sympy
I think that we need to improve the integrator capability, but usually that is one of the most difficult thing to do.
For Fourier transformation to give general functional results (DiracDelta) than improperly integrable functions, I'm not sure meijerint is sufficient for that.
But if that is possible, then this can be one of the reason why we should have separate implementation for `fourier_transform` than `integrate(f(t)*exp(I*w*t), (t, -oo, oo))`.
Reply all
Reply to author
Forward
0 new messages