Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous Fourier Transform with Python / Sympy (Analytical Solution)

I recently replaced Matlab with Python because I was real;y excited by Sympy.

But now I have the following problem:

I need a way to reliably calculate continuous fourier transforms with Python. Sympy has problems with solutions including Diracs (Delta-functions) as they for example occur for trig-functions etc.

For example, if I try

fourier_transform(cos(x),x,v)

the output is 0 where it should be based on the Dirac delta function

Does anyone know, if this part of Sympy is going to be improved or if there is another way to analytically find fourier transforms with Python?

Thanks for answers or any advice in advance!

like image 332
oeh Avatar asked Oct 19 '15 07:10

oeh


1 Answers

As far as I know, no one is currently working on this, although contributions are welcome.

Some advice I can give:

  • If you set noconds=False in fourier_transform(), it will include conditions for which 0 is True:

    In [26]: fourier_transform(cos(t),t,x, noconds=False)
    Out[26]:
    ⎛   │                 ⎛ -ⅈ⋅π           2      ⎞│       │                 ⎛ ⅈ⋅π           2      ⎞│    ⎞
    ⎝0, │periodic_argument⎝ℯ    ⋅polar_lift (x), ∞⎠│ < π ∧ │periodic_argument⎝ℯ   ⋅polar_lift (x), ∞⎠│ < π⎠
    

    These conditions aren't very helpful except maybe to show that 0 isn't completely wrong.

  • You can use FourierTransform to represent an unevaluated fourier transform. You can call doit() on it to evaluate it or rewrite(Integral) to get the integral form:

    In [28]: FourierTransform(cos(t),t,x).rewrite(Integral)
    Out[28]:
    ∞
    ⌠
    ⎮   -2⋅ⅈ⋅π⋅t⋅x
    ⎮  ℯ          ⋅cos(t) dt
    ⌡
    -∞
    

My best suggestion for now is to do the Fourier transforms that SymPy currently can't do manually by manipulating either FourierTransform objects or the integrals.

like image 115
asmeurer Avatar answered Sep 22 '22 15:09

asmeurer