简体   繁体   中英

Symbolic Hilbert transform in sympy

Is there an easy way to implement a symbolic Hilbert transform in sympy such that inputting cos(x), for example, would spit out sin(x)?

Sympy does not seem to define the Hilbert transform as a symbolic integral ( docs ).

I tried defining it according to its limit form (from Wikipedia ). I would add the equation here but I don't have enough rep to do so.

My attempt in sympy gives me a "Not implemented error":

from sympy import *
t, eps, tau = symbols('t eps tau')
limit(integrate( (sin(t+tau) - sin(t-tau))/tau, (tau, eps, oo) ), eps, 0)

Is there a way to do this in sympy? Alternatively, are there other open-source alternatives that could accomplish this?

Update:

Adding constraints to the symbolic variables as per Stelios does solve the trivial case of sin(x), but runs into problems for anything more complex.

import sympy as sp

t, tau = sp.symbols('t, tau', real = True)
eps = sp.symbols('epsilon', positive = True)

u1 = lambda x: sp.sin(x)/x
u2 = lambda x: 1/(x**2 + 1)

sp.limit(sp.integrate( (u1(t+tau) - u1(t-tau))/tau, (tau, eps, sp.oo) ), eps, 0)
sp.limit(sp.integrate( (u2(t+tau) - u2(t-tau))/tau, (tau, eps, sp.oo) ), eps, 0)

With u1, the computations hangs for a while before issuing the same "Not implemented error" and with u2, it outputs 0. Is there a more generic way to implement the transform?

Apparently, sympy fails to perform the integration for a "general" eps . However, if you specify eps as a positive variable, the integral can be evaluated (at least for the specific function you are considering)

import sympy as sp

t, tau = sp.symbols('t, tau', real = True)
eps = sp.symbols('epsilon', positive = True)

u = sp.sin
sp.limit(sp.integrate( (u(t+tau) - u(t-tau))/tau, (tau, eps, sp.oo) ), eps, 0)

pi*cos(t)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM