a
    ˆù»j­:  ã                   @   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   úKE:\soccer\ml_env\Lib\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>.Òâ"¨Ð?gÙ4ðpL	Ó?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      ì?gáz®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Žüø]OŸõ¿g–oü²hã?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   gwÀÄRN½ó?g.-“.ˆç?y\9¨Oî?Æ„ò°(Ö?y\9¨Oî?Æ„ò°(Ö¿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{®Gáz„¿r   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   ç{®Gáz„?gUùxÊe±ï¿gü©ñÒMbP?rc   ra   gÞT(û|®ï¿)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   g‚vIhÂ%<=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@   gffffffæ¿r   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{®Gázt?g�â„i®ß¿gYì­›É]ï¿g{®Gáz”?)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"