L i ZdZ ddlZdZdZdZd dZdZdZd d Z y#e$rdZY!wxYw) z1 Some signal functions implemented using mpmath. Nc"d}|D]}||z} |S)z:Returns the product of the elements in the sequence `seq`.)seqpelems ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/signal/tests/mpsig.py_prodr s$ A T  HcTt|t|z }|dkr td|S)z Return relative degree of transfer function from zeros and poles. This is simply len(p) - len(z), which must be nonnegative. A ValueError is raised if len(p) < len(z). rzFImproper transfer function. Must have at least as many poles as zeros.)len ValueError)zrdegrees r _relative_degreers6Vc!f_F zFG G Mr cB t||}d|z |Dcgc] } |z |z z }}|Dcgc] } |z |z z }}|jdg|zt fd|D} t fd|D} || z| z } ||| jfScc}wcc}w)zCBilinear transformation to convert a filter from analog to digital.c3(K|] }|z  ywNr).0z1fs2s r z_zpkbilinear..0'r#('c3(K|] }|z  ywrr)rp1rs r rz_zpkbilinear..1rr)rextendr real) rrkfsrrz_zrp_znumerdenomk_zrs @r _zpkbilinearr(!sa #F B$C./ /rC"Hr " /C /-. /rC"Hr " /C /JJtf} 'Q' 'E 'Q' 'E e)e C SXX  0 /s BBct||}|Dcgc]}||z }}|Dcgc]}||z }}|||zz} ||| fScc}wcc}w)z;Transform a lowpass filter to a different cutoff frequency.)r) rrr!worrz_lprp_lpk_lps r _zpklp2lpr.7sda #F BG D  BG D  r6z>D t  ! s > Act| dz|dDcgc]2}tjdtjz|zd|zz  4}}|Scc}w)z Poles of an analog Butterworth lowpass filter. This is the same calculation as scipy.signal.buttap(n) or scipy.signal.butter(n, 1, analog=True, output='zpk'), but mpmath is used, and only the poles are returned. rr?)rangempmathexppi)nr!poless r _butter_analog_polesr7GsR9>qbdAq8I J1fjjFIIa1-. . JE J L Ks7Acg}t|}d}d}d|ztjtj|z|z z}t ||||\}}}t ||||\}}}|||fS)z Lowpass Butterworth digital filter design. This computes the same result as scipy.signal.butter(n, Wn, output='zpk'), but it uses mpmath, and the results are returned in lists instead of NumPy arrays. rr)r*)r")r7r2tanr4r.r() r5Wnzerosr6r!r"warpedrrs r butter_lpr=Ssx E  #E A B VfjjR"!45 5FuaF3GAq!1ar*GAq! a7Nr c|t|trF|xsd}t|Dcgc]+}tjtj |z|z -}}n|}g}|D]k}tj d|z} t|D cgc]} | | z  c} } t|D cgc]} | | z  c} } || z| z } |j| m||fScc}wcc} wcc} w)a Frequency response of a filter in zpk format, using mpmath. This is the same calculation as scipy.signal.freqz, but the input is in zpk format, the calculation is performed using mpath, and the results are returned in lists instead of NumPy arrays. ir0) isinstanceintr1r2r4mpfr3r append)rrr!worNNjwshwkzm1tr%r&hks r zpkfreqzrLes |z$, KC5:1X >fii&**Q-'!+ > >  Ajjb!*1sQw*+*1sQw*+ Y    q5L?+*s0C C  C )rr) __doc__r2 ImportErrorr rr(r.r7r=rLrr r rOsL   ,  $} Fs  **