a
    BCCf9                     @   s   d dl Zd dlmZmZmZmZ d dlZd dlm	Z
 d dlmZmZmZmZmZ d dlmZmZmZmZmZ G dd dZG dd	 d	ZG d
d dZdS )    N)assert_array_almost_equalassert_almost_equalassert_allcloseassert_equal)cont2discrete)dlsimss2tfss2zpklsimlti)tf2ssimpulsedimpulsestepdstepc                   @   st   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )TestC2Dc                 C   s   t d}t dd}t ddgddgddgg}t dgdgdgg}d	t d }t dd
}d}t||||f|dd\}}	}
}}t|| t||	 t||
 t|| t|| d S )N   r            ?      ?      ?      ?        Qտ)a?g6<S?zohmethodnpeyefullarrayc2dr   r   )selfacbcccdcad_truthbd_truthdt_requestedadbdcddddt r2   a/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/signal/tests/test_cont2discrete.pytest_zoh   s    
 



zTestC2D.test_zohc                 C   s   t d}t dd}t ddgddgddgg}t dgdgdgg}d	t d }t dd
}|}t dgdgdgg}d}	t||||f|	dd\}
}}}}t||
 t|| t|| t|| t|	| d S )Nr   r   r   r   r   r   r   r   r   gm?g>."?g4pL	?g.Ȫq¿fohr   r   r%   r&   r'   r(   r)   r*   r+   cd_truthdd_truthr,   r-   r.   r/   r0   r1   r2   r2   r3   test_foh#   s$    
 



zTestC2D.test_fohc                 C   s   t d}t dd}t ddgddgddgg}t dgdgdgg}dt d }t dd	}|}t d
gdgdgg}d}	t||||f|	dd\}
}}}}t||
 t|| t|| t|| t|	| d S )Nr   r   r   r   r   r   r   r   g)a?g      ?g      ?r   r   r   r6   r2   r2   r3   test_impulse:   s"    




zTestC2D.test_impulsec                 C   s   t d}t dd}t ddgddgddgg}t dgdgdgg}d}d	}d
t d }t dd}t ddgddgddgg}	t dgdgdgg}
t||||f|d|d\}}}}}t|| t|| t|	| t|
| d S )Nr   r   r   r   r   r   r   r   UUUUUU?g?333333??333333?ffffff?皙?=
ףp=ʿgbtr   alphar    r!   r"   r#   r$   r   )r%   r&   r'   r(   r)   r,   rD   r*   r+   r7   r8   r-   r.   r/   r0   r1   r2   r2   r3   test_gbtP   s.    




zTestC2D.test_gbtc                 C   s   t d}t dd}t ddgddgddgg}t dgdgdgg}d}d	t d }t dd}t ddgddgddgg}|}	t||||f|d
d\}
}}}}t||
 t|| t|| t|	| t|| d S )Nr   r   r   r   r   r   r   r         ?Zeulerr   r   r%   r&   r'   r(   r)   r,   r*   r+   r7   r8   r-   r.   r/   r0   r1   r2   r2   r3   
test_eulerj   s(    





zTestC2D.test_eulerc                 C   s   t d}t dd}t ddgddgddgg}t dgdgdgg}d}d	t d }t dd}t d
d	gd	d	gd	dgg}t dgdgdgg}	t||||f|dd\}
}}}}t||
 t|| t|| t|	| d S )Nr   r   r   r   r   r   r   r   g       @rG   g      ?gzG?Zbackward_diffr   rE   rH   r2   r2   r3   test_backward_diff   s,    




zTestC2D.test_backward_diffc                 C   s  t d}t dd}t ddgddgddgg}t dgdgdgg}d}d	t d }t dd
}t ddgddgdd
gg}t dgd
gdgg}	t||||f|dd\}
}}}}t||
 t|| t|| t|	| t|| dt d }t dd}t ddgddgddgg}t dgdgdgg}	d
}t||||f|dd\}
}}}}t||
 t|| t|| t|	| t|| d S )Nr   r   r   r   r   r   r   r   g?r;   gUUUUUU?g?g>X%bilinearr   gffffff?r@   r=   r>   r<   r?   rA   r   rH   r2   r2   r3   test_bilinear   sH    










zTestC2D.test_bilinearc           	      C   sx   t g d}t g d}t g dg}t g d}d}t||f|dd\}}}t|| t|| t|| d S )N)r   r   r   )r   r   r   )r;   gNZۿgϱ)_?)r   g]Ogoh?r   r   r   )r    r#   r$   r   r   )	r%   ZnumcZdencZnumdZdendr,   numdenr1   r2   r2   r3   test_transferfunction   s    

zTestC2D.test_transferfunctionc                 C   s   t ddg}t dt d dt d g}d}ddg}d	d
g}d}d}t|||f|dd\}}	}
}t|| t||	 t||
 t|| d S )Nr   g      y              ?r   y             r   gwRN?g.-.?y\9O?(?y\9O?(ֿr   r   )r    r#   sqrtr$   r   r   )r%   Zzeros_cZpoles_cZk_cZzeros_dZpolls_dZk_dr,   ZzerosZpoleskr1   r2   r2   r3   test_zerospolesgain   s     "


zTestC2D.test_zerospolesgainc                 C   s2  d}d}d}d}t ||||\}}t||||\}}}	d}
d}dd| |
 |  d||
 |   }|
| d||
 |   }|d||
 |   }||| |  }t ||||\}}t||f|
d|d\}}}t|| t|| t||||\}}}t|||	f|
d|d\}}}}t|| t|| t|| dS )	z7Test method='gbt' with alpha=0.25 for tf and zpk cases.g      r   r   r   r   rB   rC   N)r   r	   r$   r   )r%   ABCDZcnumZcdenczcpZckhrD   ZAdZBdZCdZDdZdnumZddenZc2dnumZc2ddenr1   ZdzZdpZdkZc2dzZc2dpZc2dkr2   r2   r3   test_gbt_with_sio_tf_and_zpk   s*    $



z$TestC2D.test_gbt_with_sio_tf_and_zpkc                 C   s  dd }t dgg}t dgg}t dgg}t dgg}d}t ddd}|d	 |d  }||}	t||||f||	|d
\}}
}t||||f|dd}d|	dd |	d	d   }|dd }t||dd	||d\}}}d|
dd |
d	d   }t| |dd dS )a  
        Test that the solution to the discrete approximation of a continuous
        system actually approximates the solution to the continuous system.
        This is an indirect test of the correctness of the implementation
        of cont2discrete.
        c                 S   s   t d|  S )Ng      @)r    sin)tr2   r2   r3   u  s    z'TestC2D.test_discrete_approx.<locals>.ug{Gzr   r@   r   g      $@e   r   )TUZX0rK   r   r   N)r]   r\   x0g-C6?Zrtol)	r    r#   Zlinspacer
   r$   r   Zreshaper   ravel)r%   r]   abcdrb   r\   r1   u1ZyoutZxoutZdsysu2t2Ztd2Zyd2Zxd2Zymidr2   r2   r3   test_discrete_approx  s     zTestC2D.test_discrete_approxc                 C   sb   ddgddggddgf}t |d\}}}t|d t|ddgdd t|ddgddggdd d S )	Nr   r   {Gz?gUxegMbP?rc   ra   gT(|)r$   r   r   )r%   tfrM   rN   r1   r2   r2   r3   test_simo_tf<  s
    
zTestC2D.test_simo_tfc                 C   s   d}ddgddggddgf}t ||\}}}|d d |d f}t ||\}}}	|d d |d f}
t |
|\}}}t||	 t|| t|t||fdd t||dd t||dd d S )Nrm   r      r   gvIh%<=rc   )r$   r   r   r    Zvstack)r%   tsrn   rM   rN   r1   Ztf1Znum1Zden1Zdt1Ztf2Znum2Zden2Zdt2r2   r2   r3   test_multioutputE  s    

zTestC2D.test_multioutputN)__name__
__module____qualname__r4   r9   r:   rF   rI   rJ   rL   rO   rR   rZ   rl   ro   rs   r2   r2   r2   r3   r      s   ,*(	r   c                   @   s   e Zd Zdd Zdd ZdS )
TestC2dLtic           	      C   s   t ddgddgg}t dgdgg}t ddgg}d}t ddgd	d
gg}t dgdgg}t||||}|d}t|j| t|j| t|j| t|j| d S )Ng333333ӿ皙?r@   gffffffr   r   gГ<?gs?g?g{Kp?g1vM ?g_ǷJ(?g?)	r    r#   r   to_discreter   rS   rT   rU   rV   )	r%   rS   rT   rU   rV   ZA_resZB_resZsys_sscZsys_ssdr2   r2   r3   test_c2d_ss^  s    

zTestC2dLti.test_c2d_ssc                 C   s\   t ddgddg}|d}tddg}tddg}t|j|dd	 t|j|dd	 d S )
Nr   r<   r   g?g{Gzt?gi߿gY쭛]g{Gz?)Zatol)r   ry   r    r#   r   rN   rM   )r%   sysZnum_resZden_resr2   r2   r3   test_c2d_tfq  s    
zTestC2dLti.test_c2d_tfN)rt   ru   rv   rz   r|   r2   r2   r2   r3   rw   ]  s   rw   c                   @   s   e Zd Zeddgg dddfeddgg dddfedg d	ddfgZejd
edd Zejd
edd Z	ejd
edd Z
dS )TestC2dInvariantsr   )r   rG   r   r   
   r   )r   rG      r   r   rx   )r   r   r   r   zsys,sample_time,samples_numberc                 C   sZ   t || }t||d\}}tt||ddt|d\}}t||  |d   d S )Nr_   r   r   nr   )r    aranger   r   r$   lenr   rd   r%   r{   Zsample_timeZsamples_numbertime_Z	yout_contZ	yout_discr2   r2   r3   test_impulse_invariant  s    
z(TestC2dInvariants.test_impulse_invariantc                 C   sV   t || }t||d\}}tt||ddt|d\}}t| |d   d S )Nr   r   r   r   r   )r    r   r   r   r$   r   r   rd   r   r2   r2   r3   test_step_invariant  s    z%TestC2dInvariants.test_step_invariantc                 C   sT   t || }t|||d\}}}tt||dd|d\}}}t| |  d S )N)r_   r`   r5   r   )r]   )r    r   r
   r   r$   r   rd   r   r2   r2   r3   test_linear_invariant  s    z'TestC2dInvariants.test_linear_invariantN)rt   ru   rv   r   ZcasespytestmarkZparametrizer   r   r   r2   r2   r2   r3   r}     s   

r}   )numpyr    Znumpy.testingr   r   r   r   r   Zscipy.signalr   r$   r   r   r	   r
   r   r   r   r   r   r   r   rw   r}   r2   r2   r2   r3   <module>   s     P"