Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fourier transform a trig function in Sympy returns unexpected result

I think Sympy makes a mistake in calculating the Fourier transform of a trig function. For example:

from sympy import fourier_transform, sin
from sympy.abc import x, k
print fourier_transform(sin(x), x, k)

The expected answer via Mathematica is

enter image description here

but Sympy returns 0. Sometimes the function works very well since fourier_transform(Heaviside(t)*cos(t),t,omega) and fourier_transform(Heaviside(t)*sin(t),t,omega) return the correct answer. I think Sympy may be using Laplace transform to calculate Fourier transform.

like image 372
Kattern Avatar asked Jan 18 '14 09:01

Kattern


2 Answers

SymPy computes the Fourier transform by literally computing the integral. I would consider this to be a bug, so feel free to open an issue for it.

like image 139
asmeurer Avatar answered Oct 06 '22 19:10

asmeurer


You can add noconds=False to the transform routines to find under which conditions the transformation integral converges. As asmeurer says, we literally compute the defining integral, so you will never see delta functions coming up. In the case of the fourier transform of cos, the conditions are a convoluted way of saying "never", which unfortunately sympy does not recognise. (I.e. the algorithm says something like "the integral is zero if blah", and blah never holds.)

For the fourier transform of the step function, the conditions seem to be saying that this works if z has negative argument (angle), not too big. Note that this is indeed when the transform integral converges (b/c you need to pick up a falling exponential term over the positive reals). I don't have time to think about whether the computation is correct in this case.

like image 39
Tom Bachmann Avatar answered Oct 06 '22 20:10

Tom Bachmann