a
    BCCf                     @   sh   d Z zddlZW n ey&   dZY n0 dd Zdd Zdd Zdd
dZdd Zdd ZdddZ	dS )z1
Some signal functions implemented using mpmath.
    Nc                 C   s   d}| D ]}||9 }q|S )z:Returns the product of the elements in the sequence `seq`.    )seqpelemr   r   T/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/signal/tests/mpsig.py_prod   s    
r   c                 C   s$   t |t |  }|dk r td|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).
    r   zFImproper transfer function. Must have at least as many poles as zeros.)len
ValueError)zr   degreer   r   r   _relative_degree   s    r   c           
         s   t | |}d|   fdd| D } fdd|D }|dg|  t fdd| D }t fdd|D }|| | }	|||	jfS )	zCBilinear transformation to convert a filter from analog to digital.   c                    s   g | ]} |  |  qS r   r   .0Zz1Zfs2r   r   
<listcomp>)       z _zpkbilinear.<locals>.<listcomp>c                    s   g | ]} |  |  qS r   r   r   p1r   r   r   r   *   r   c                 3   s   | ]} | V  qd S Nr   r   r   r   r   	<genexpr>0   r   z_zpkbilinear.<locals>.<genexpr>c                 3   s   | ]} | V  qd S r   r   r   r   r   r   r   1   r   )r   extendr   real)
r   r   kfsr   Zz_zZp_znumerdenomZk_zr   r   r   _zpkbilinear!   s    
r   r   c                    sD   t | |} fdd| D } fdd|D }| |  }|||fS )z;Transform a lowpass filter to a different cutoff frequency.c                    s   g | ]} | qS r   r   r   wor   r   r   =   r   z_zpklp2lp.<locals>.<listcomp>c                    s   g | ]} | qS r   r   r   r    r   r   r   >   r   )r   )r   r   r   r!   r   Zz_lpZp_lpZk_lpr   r    r   	_zpklp2lp7   s
    
r"   c                    s$    fddt   d  dD }|S )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.
    c                    s*   g | ]"}t d t j | d    qS )              ?r   )mpmathexppi)r   r   nr   r   r   O   r   z(_butter_analog_poles.<locals>.<listcomp>r   r   )range)r(   polesr   r'   r   _butter_analog_polesG   s     r+   c           	      C   sf   g }t | }d}d}d| ttj| |  }t||||d\}}}t||||d\}}}|||fS )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.
    r   r   r    )r   )r+   r$   tanr&   r"   r   )	r(   ZWnZzerosr*   r   r   Zwarpedr   r   r   r   r   	butter_lpS   s    r-   c           
         s   |du st |tr2|pd  fddt D }n|}g }|D ]T}td| tfdd| D }tfdd|D }|| | }	||	 q>||fS )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.
    Ni   c                    s    g | ]}t jt |   qS r   )r$   r&   Zmpf)r   j)Nr   r   r   o   r   zzpkfreqz.<locals>.<listcomp>r#   c                    s   g | ]} | qS r   r   r   tzm1r   r   r   v   r   c                    s   g | ]} | qS r   r   r0   r2   r   r   r   w   r   )
isinstanceintr)   r$   r%   r   append)
r   r   r   ZworNwshZwkr   r   Zhkr   )r/   r3   r   zpkfreqze   s    r9   )r   )N)
__doc__r$   ImportErrorr   r   r   r"   r+   r-   r9   r   r   r   r   <module>   s   

