o
    h{                     @   s  d dl mZ d dlZd dlZd dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  d dl!m"Z" d dl#m$Z$ d/d	d
Z%G dd dZ&G dd dZ'G dd dZ(G dd de(Z)G dd de(Z*G dd dZ+G dd de+Z,G dd de+Z-G dd dZ.G dd de.Z/G dd  d e.Z0G d!d" d"Z1G d#d$ d$Z2G d%d& d&Z3G d'd( d(Z4G d)d* d*Z5G d+d, d,Z6G d-d. d.Z7dS )0    )abstractmethodN)assert_almost_equalassert_equalassert_allcloseassert_suppress_warnings)raises)warns)ss2tftf2sslsim2impulse2step2ltidltibodefreqresplsimimpulsestepabcd_normalizeplace_polesTransferFunction
StateSpaceZerosPolesGain)BadCoefficients:0yE>c              
   C   s   |  }| D ]D}d}t|jd D ](}tt|t|gt|| t|| g||r9d}t||  nq|sJtdt	| d t	| qdS )a  
    Check each pole in P1 is close to a pole in P2 with a 1e-8
    relative tolerance or 1e-8 absolute tolerance (useful for zero poles).
    These tolerances are very strict but the systems tested are known to
    accept these poles so we should not be far from what is requested.
    Fr   TzCan't find pole z in N)
copyrangeshapenpallcloserealimagdelete
ValueErrorstr)P1P2rtolatolp1foundp2_idx r.   Y/var/www/html/scripts/venv/lib/python3.10/site-packages/scipy/signal/tests/test_ltisys.py_assert_poles_close   s    r0   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestPlacePolesc                 K   sZ   t |||fi |}tj|t||j \}}t||j t||j t||j |S )z
        Perform the most common tests on the poles computed by place_poles
        and return the Bunch object for further specific tests
        )	r   r    linalgeigdotgain_matrixr0   requested_polescomputed_poles)selfABPkwargsfsfexpected_r.   r.   r/   _check)   s   zTestPlacePoles._checkc                 C   s   t g ddd}t g ddd}t g d}| j|||dd | j|||dd t jd	d
 | ||d W d    d S 1 sHw   Y  d S )NgGz?gʿg\(@gNbX9g<,Ԛg)\(r   g?gOn?d;O@gV-gOn@g~jt?rB   grh|?gE    )r   K@V-?rE   r   r   ^I+	r      皙ɿ      g}гY9gDT!KNV0methodYTignore)invalid)rG   rG      rQ   )r    arrayreshaper@   errstate)r8   r9   r:   r;   r.   r.   r/   	test_real5   s   "zTestPlacePoles.test_realc                 C   s  t g dg dg dg dg}t ddgddgddgddgg}t g d}t jddd | ||| W d    n1 sBw   Y  g d	}t jddd | j|||d
d W d    n1 sfw   Y  t g ddd}t g ddd}g d}| ||| t dt d }t dt dgd dd d dd f  }||d dd df< ||d dd df< g d}t jddd | ||| W d    n1 sw   Y  g d}| |d dd df |d dd df | g d}| |d dd df |d dd df | t g ddd}t g ddd}t g d}t jddd t||| W d    n	1 sNw   Y  t g d}t jddd | ||| W d    d S 1 suw   Y  d S )N)r      r   r   )r   r   r   竪@)r   r   r   r   r      )                          ?rO   )dividerP   )y        ưy        ư>
   i  maxiter)$iii%iiFii[iiiYiiii\ii^iciii(i~iiiiirG   iSiiigiiipii   )iiiii0i_iLi`iiiii]ii#iii"iHiii<i^iUiiiciiiR   )y      9      =y      9      =@y      ?@      Ey      ?@      E@y     @@     Dy     @@     D@)   rd   rd   )rd   r_   r_   )r^   (   2   <   F   y      4      y      4      @y      @      @y      @      )
r^   re   rf   iiiirZ   )
y      $      $@y      4      4@y      >      >@y      D      D@y      I      I@y      $      $y      4      4y      >      >y      D      Dy      I      I)r   rV   r   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   rc   r   r   r   r   	   )
r   r   r   r   rX   r   r   rX   rG   rQ   rG   )y            ?y                        ?            )ro   rY   rp   rq   )	r    rR   rT   r@   rS   oneseyediagr   )r8   r9   r:   r;   big_Abig_Br.   r.   r/   test_complexK   sl   

,..$zTestPlacePoles.test_complexc                 C   s   t g ddd}t g ddd}t g d}| |||}t|jt j t|jt j t d}| |||}t|jt j t|jt j |d d df dd}t d}| |||}t|jd t|jd d S )NrA   rC   )r   rD   rE   rE   r   r   rF   r   rX   rG   rQ   rC   rc   rb   rV      rH   )r\   r[   rY   ro   r   rX   )r    rR   rS   r@   r   r)   nannb_iter)r8   r9   r:   r;   r=   r.   r.   r/   test_tricky_B   s&   

zTestPlacePoles.test_tricky_Bc              	   C   s  t g ddd}t g ddd}ttt||ddd ttt||t ddd ttt|d d d d t jf |d ttt||d d d d t jf d ttt||d	 ttt||d
 ttt||ddd ttt||ddd ttt||d tttt dt dd tj	dd9}t
d t||dddd}tt|dk tt|d jt tdt|d jv  t|jd W d    n1 sw   Y  ttt||d ttt|d d d df |d ttt||d dd d f d ttt||ddd d S ) N)r   rV   r   r   r   r   r   rW   r   r   r   r   r   r   r   r   rC   )r   r   r   r   rX   r   r   rX   rG   ) 皙ffffff333333foorL   rX   )r}   r~   r   r   rY   )r}   r~   r   *   r)   ir`   )ro   ro   ro   ro   )rC   rC   )rC   rG   rX   rG   rQ   rC   T)recordalways)rZ   ro   rY   rr   gؗҜ<)r)   ra   rZ   z4Convergence was not reached after maxiter iterations)r\   r[                @ro   rQ   )ro   rY   rr   )r\   r[   r   y             rK   )r    rR   rS   assert_raisesr%   r   newaxisrs   warningscatch_warningssimplefilterr   len
issubclasscategoryUserWarningr&   messager   r{   )r8   r9   r:   wr=   r.   r.   r/   test_errors   sT   



  

zTestPlacePoles.test_errorsN)__name__
__module____qualname__r@   rU   rx   r|   r   r.   r.   r.   r/   r1   '   s    P"r1   c                   @   D   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S )	TestSS2TFc                 C   s<   t t||ft||ft||ft||fd d S )Nr   )r
   r    zerosr8   pqrr.   r.   r/   check_matrix_shapes  s
   zTestSS2TF.check_matrix_shapesc                 C   s"   dD ]\}}}|  ||| qd S )N))rQ   rQ   rQ   )rX   rQ   rQ   rX   rX   rX   )r   r   r.   r.   r/   test_shapes  s   zTestSS2TF.test_shapesc           	      C   s   t g d}t g d}t||\}}}}t|ddgddggdd t|dgdggdd t|dd	ggdd t|dggd
d t||||\}}t|d |dd t||dd d S )N)      ?      @      @)r          @r   ro   rY   rX   r   vIh%<=r   rG   +=)r    rR   r   r   r
   )	r8   bar9   r:   CDbbaar.   r.   r/   
test_basic  s   zTestSS2TF.test_basicc                 C   sF  d}t | \}}}}t|dggdd t|dggdd t|dggdd t|dggdd t||||\}}t|ddggdd t|ddgdd dgdggdf}t | \}}}}t|dggdd t|dggdd t|dgdggdd t|dgdggdd t||||\}}t|ddgddggdd t|ddgdd d S )N)rG   rX   r   r   r   rG   rX   rc   )r   r   r
   r8   tfr9   r:   r   r   numdenr.   r.   r/   test_zero_order_round_trip  s$   z$TestSS2TF.test_zero_order_round_tripc                 C   s  ddgddggddgf}t | \}}}}t|dggdd t|dggdd t|dgdggdd t|dgdggdd t||||\}}t|ddgddggdd t|ddgdd g dg d	gg d	f}t | \}}}}t|ddgddggdd t|dgdggdd t|ddgddggdd t|dgdggdd t||||\}}t|g dg d	gdd t|g d	dd g d
g d
gg df}t | \}}}}t|g dg dg dgdd t|dgdgdggdd t|g d
g d
gdd t|dgdggdd t||||\}}t|g dg dgdd t|g ddd tjdddggtdddgf}t | \}}}}t|dggdd t|dggdd t|dgdggdd t|dgdggdd t||||\}}t|ddgddggdd t|ddgdd tjddgg d
gtdg df}t | \}}}}t|ddgddggdd t|dgdggdd t|ddgddggdd t|dgdggdd t||||\}}t|g dg d
gdd t|g ddd d S )NrX   rG   ro   r   r   r   rZ   )rX   r   rX   r   )rX   rG   rQ   r   )ro   rY   rr   )rX   r   r   r   rX   r   )r   rX   rG   rQ   rQ   )dtyperb   ighe99irY   )rX   rb   rc   r   rr   )r   rX   rY   )r   r   r
   r    rR   objectr   r.   r.   r/   test_simo_round_trip5  sZ    "zTestSS2TF.test_simo_round_tripc                 C   sv   g dg dg dg}dgdgdgg}g dg}dgg}t ||||\}}t|g dgdd	d
 t|g ddd d S )Nr   )r   r   rX   )rY   rr   ro   r   rX   )rc   rX   r   )        r   r   r   r   r   r)   r*   )r   r         @r   r   )r
   r   )r8   r9   r:   r   r   r   r   r.   r.   r/   test_all_int_arraysn  s   
zTestSS2TF.test_all_int_arraysc                 C   s  t g dg dg dg dg}t dgdgdgdgg}t g dg d	g d
g}t dgdgdgg}t||||\}}t|||d |d \}}t|||d |d \}	}
t|||d |d \}}t||dd t|
|dd t||dd t|t ||	|fddd d S )N)      r   r   r   )r   r   r   r   )g      r   r   r   )g              @r   r   333333?r   g      @)r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   rX   rG   r   r   r   r   )r    rR   r
   r   vstack)r8   r9   r:   r   r   b_allr   b0a0b1a1b2a2r.   r.   r/   test_multioutputw  s4   

 zTestSS2TF.test_multioutputN)
r   r   r   r   r   r   r   r   r   r   r.   r.   r.   r/   r      s    9	r   c                   @   s\   e Zd ZdZe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 )_TestLsimFuncsrV   c                 O   s   d S Nr.   r8   argsr<   r.   r.   r/   func  s   z_TestLsimFuncs.funcc                 G   s>   t  }|t t| }W d    |S 1 sw   Y  |S r   )r   filterr   r   )r8   r   supsystemr.   r.   r/   
lti_nowarn  s   


z_TestLsimFuncs.lti_nowarnc                 C   sd   |  dddd}tdd}t|}| j|||dgd\}}}t| }t|| t|| d S Nr   r   r   r   rc   X0r   r    linspace
zeros_liker   expr   r8   r   tutoutyx
expected_xr.   r.   r/   test_first_order  s   

z_TestLsimFuncs.test_first_orderc                 C   st   t ddd}t |}| dgg d}| j|||ddgd\}}}d| t |  }t|d d df | d S )Nr   r_   i  r   r   r   r   r   r   )r    r   r   r   r   r   r   r8   r   r   r   r   r   r   r   r.   r.   r/   test_second_order  s   
z _TestLsimFuncs.test_second_orderc                 C   sd   |  dddd}tdd}|}| |||\}}}d|d  }t||| jd t||| jd d S )Nr   r   r   rc         ?rG   decimal)r   r    r   r   r   digits_accuracyr   r.   r.   r/   test_integrator  s   z_TestLsimFuncs.test_integratorc                 C      t ddgddgg}t ddgddgg}t ddg}t d}| ||||}t ddd}t t|d	f}| j|||ddgd
\}}	}
t | }t | }t d| }t|	| t|
d d df | t|
d d df | d S )Nr   r          r   rX   rG   r   g      $@   rG   )UTr   rX   	r    rR   r   r   r   r   r   r   r   r8   r9   r:   r   r   r   r   r   r   r   r   
expected_yexpected_x0expected_x1r.   r.   r/   test_two_states  s   

z_TestLsimFuncs.test_two_statesc                 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}t |}| |||\}}}	t t d|d  |g}
|d }t|	|
| jd t||| jd d S )	Nr   r   r   r   rc   r   rG   r   )	r    rR   r   r   	ones_liker   	transposer   r   )r8   r9   r:   r   r   r   r   r   r   r   r   r   r.   r.   r/   test_double_integrator  s   
z%_TestLsimFuncs.test_double_integratorc                 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}t |}| j|||ddgd\}}}	|t |  }
t||
 d S r   )r    rR   r   r   r   r   r   r   )r8   r9   r:   r   r   r   r   r   r   r   r   r.   r.   r/   test_jordan_block  s   
z _TestLsimFuncs.test_jordan_blockc                 C   r   )Nr   r   r   r   r   r   r   e   rG   r   rX   r   r   r.   r.   r/   	test_miso  s   

z_TestLsimFuncs.test_misoN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r.   r.   r.   r/   r     s    

r   c                   @   $   e Zd Zdd Zdd Zdd ZdS )TestLsimc                 O      t |i |S r   )r   r   r.   r.   r/   r        zTestLsim.funcc                 C   sZ   |  dddd}tdd}t|}| j|||dgd\}}}t| }t|| d S )Nr   r   r   rX   rG   r   r   )r8   r   r   r   r   r   r   r   r.   r.   r/   test_nonzero_initial_time  s   
z"TestLsim.test_nonzero_initial_timec                 C   sv   t g d}t g d}dgddgf}ttdd | j|||dgd\}}}W d    d S 1 s4w   Y  d S )Nr   r   r   r   r   r   r   r   r   r   z"Time steps are not equally spaced.matchr   )r    rR   r   r%   r   )r8   r   r   r   r   r   r   r.   r.   r/   test_nonequal_timesteps  s   "z TestLsim.test_nonequal_timestepsN)r   r   r   r   r   r  r.   r.   r.   r/   r     s    r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )	TestLsim2rb   c                 O   sV   t tdd t|i |\}}}W d    n1 sw   Y  |t|t|fS )Nzlsim2 is deprecatedr  )r	   DeprecationWarningr   r    squeeze)r8   r   r<   r   r   r   r.   r.   r/   r   )  s   zTestLsim2.funcc                 C   s^   t g d}t g d}dgddgf}| j|||dgd\}}}t d|}t|| d S )Nr   r   r   r   r   )r    rR   r   maximumr   r   r.   r.   r/   "test_integrator_nonequal_timestamp.  s   z,TestLsim2.test_integrator_nonequal_timestampc                 C   s^   t g d}t g d}dgddgf}| j|||dd\}}}t g d}t|| d S )N)r   r   r   皙?r	  r   )r   r   r   r   r   r   r   r   {Gz?)hmax)r   r   r   皙?r  r  )r    rR   r   r   r   r.   r.   r/   (test_integrator_nonequal_timestamp_kwarg7  s   z2TestLsim2.test_integrator_nonequal_timestamp_kwargc                 C   sT   dgg df}| j |ddgd\}}}d| t|  }t|d d df | d S )Nr   r   r   r   r   r   r    r   r   )r8   r   r   r   r   r   r.   r.   r/   test_default_arguments@  s   z TestLsim2.test_default_argumentsN)r   r   r   r   r   r  r  r  r.   r.   r.   r/   r  &  s    		r  c                   @   sL   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S )_TestImpulseFuncsc                 C   s6   dgddgf}|  |\}}t| }t|| d S Nr   r  r8   r   r   r   r   r.   r.   r/   r   N  s   z"_TestImpulseFuncs.test_first_orderc                 C   sd   dgddgf}d}t dd|}| j||d\}}t|j|f t|| t | }t|| d S )Nr   r   r   r   r   r    r   r   r   r   r   r   r8   r   nr   r   r   r   r.   r.   r/   test_first_order_fixed_timeV  s   
z-_TestImpulseFuncs.test_first_order_fixed_timec                 C   s>   dgddgf}| j |dd\}}dt|  }t|| d S Nr   r   r   r   r  r  r.   r.   r/   test_first_order_initiald  s   z*_TestImpulseFuncs.test_first_order_initialc                 C   s@   dgddgf}| j |dgd\}}dt|  }t|| d S r  r  r  r.   r.   r/   test_first_order_initial_listn  s   z/_TestImpulseFuncs.test_first_order_initial_listc                 C   s4   dgddgf}|  |\}}t|}t|| d S Nr   r   )r   r    r   r   r  r.   r.   r/   r   x  s   
z!_TestImpulseFuncs.test_integratorc                 C   s:   dgg df}|  |\}}|t|  }t|| d S )Nr   r   r  r  r.   r.   r/   r     s   z#_TestImpulseFuncs.test_second_orderc                 C   sD   dgg df}| j |dgddgd\}}| j |dgdgd\}}d S )Nr   r   rQ   rc   rb   r   r   r   r8   r   r   r   r.   r.   r/   test_array_like  s   z!_TestImpulseFuncs.test_array_likec                 C   s&   dgg df}| j |ddd\}}d S )Nr   r   rQ   rc   r  r  r  r.   r.   r/   test_array_like2  s   z"_TestImpulseFuncs.test_array_like2N)r   r   r   r   r  r  r  r   r   r  r   r.   r.   r.   r/   r  K  s    

	r  c                   @      e Zd Zdd ZdS )TestImpulse2c                 O   >   t tdd t|i |W  d    S 1 sw   Y  d S )Nzimpulse2 is deprecatedr  )r	   r  r   r   r.   r.   r/   r        $zTestImpulse2.funcNr   r   r   r   r.   r.   r.   r/   r"        r"  c                   @   r!  )TestImpulsec                 O   r   r   )r   r   r.   r.   r/   r     r   zTestImpulse.funcNr%  r.   r.   r.   r/   r'    r&  r'  c                   @   r   )_TestStepFuncsc                 C   s:   dgddgf}|  |\}}dt|  }t|| d S r  r  r  r.   r.   r/   r     s   z_TestStepFuncs.test_first_orderc                 C   sh   dgddgf}d}t dd|}| j||d\}}t|j|f t|| dt |  }t|| d S )Nr   r   r   r   r  rX   r  r  r.   r.   r/   r    s   
z*_TestStepFuncs.test_first_order_fixed_timec                 C   sB   dgddgf}| j |dd\}}ddt|   }t|| d S Nr   r   r   rX   r   r  r  r.   r.   r/   r    s   z'_TestStepFuncs.test_first_order_initialc                 C   sD   dgddgf}| j |dgd\}}ddt|   }t|| d S r)  r  r  r.   r.   r/   r    s   z,_TestStepFuncs.test_first_order_initial_listc                 C   s.   dgddgf}|  |\}}|}t|| d S r  r   r   r  r.   r.   r/   r     s   z_TestStepFuncs.test_integratorc                 C   sB   dgg df}|  |\}}dd| t|   }t|| d S )Nr   r   rX   r  r  r.   r.   r/   r     s   z _TestStepFuncs.test_second_orderc                 C   s(   dgg df}| j |ddgd\}}d S )Nr   r   rc   rb   r  r  r  r.   r.   r/   r    s   z_TestStepFuncs.test_array_likeN)
r   r   r   r   r  r  r  r   r   r  r.   r.   r.   r/   r(    s    

	r(  c                   @      e Zd Zdd Zdd ZdS )	TestStep2c                 O   r#  )Nzstep2 is deprecatedr  )r	   r  r   r   r.   r.   r/   r     r$  zTestStep2.funcc                 C   s4   dgddgf}| j |ddd\}}|}t|| d S )Nr   r   g|=r   )r*   r)   r*  r  r.   r.   r/   r     s   zTestStep2.test_integratorN)r   r   r   r   r   r.   r.   r.   r/   r,    s    r,  c                   @   r+  )TestStepc                 O   r   r   r   r   r.   r.   r/   r     r   zTestStep.funcc                 C   s   t g dgdf d S )NrZ   y      ?        r.  r8   r.   r.   r/   test_complex_input  s   zTestStep.test_complex_inputN)r   r   r   r   r0  r.   r.   r.   r/   r-    s    r-  c                   @   r!  )TestLtic                 C   s   t dgdg}tt|t tt|t  tt|t  t|jd u  t tg tdgd}tt|t tt|t  tt|t  t|jd u  t g dgd}t dgdgdd}tt|t	 tt|t  tt|t  t|jd u  d S )NrX   rZ   rQ   )
r   r   
isinstancer   r   dtr    rR   r   r   r8   sr.   r.   r/   test_lti_instantiation  s    zTestLti.test_lti_instantiationN)r   r   r   r6  r.   r.   r.   r/   r1    s    r1  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestStateSpacec                 C   sl   t dddd t dgdgdgdg t tddgddggtdgdggtddggtdgg d S )NrX   rG   rQ   rC   r   )r   r    rR   r/  r.   r.   r/   test_initialization  s
   &z"TestStateSpace.test_initializationc                 C   sh   t dddd}tt| t  tt| t tt| t tt ||u t| |u d S )NrX   rG   rQ   rC   )r   r   r2  to_ssto_tfr   to_zpkr   r4  r.   r.   r/   test_conversion%  s   zTestStateSpace.test_conversionc                 C   s<   t dddd}t|jdg t|jdg t|jd u  d S NrX   r   )r   r   polesr   r   r3  r4  r.   r.   r/   test_properties0  s   zTestStateSpace.test_propertiesc              	   C   s  G dd d}t tddgddggtdgdggtddggtdgg}t td	d
gdd
ggtdgdggtddggtdgg}|d}|d}|d}tddd}t|}d|d< ttttj	tj
tjfD ]m}	tt|	d| ||dd |	dt|||dd   tt||	d ||dd t|||dd |	d  tt||	d ||dd t|||dd |	d  tt |	d|  W d    n1 sw   Y  qutt|d ||dd t|d| |dd  tt|| ||dd t|t|||dd |dd dd tt ||  W d    n	1 s,w   Y  tt ||  W d    n	1 sEw   Y  tt ||  W d    n	1 s^w   Y  tt ||   W d    n	1 sxw   Y  tt | |  W d    n	1 sw   Y  tt ||   W d    n	1 sw   Y  tt | |  W d    n	1 sw   Y  tt|d ||dd d| t|||dd   tt |tddg  W d    n	1 sw   Y  tt tddg|  W d    n	1 sw   Y  tt ||  W d    n	1 s4w   Y  tt |tddgddgg  W d    n	1 sVw   Y  tt ||  W d    n	1 sow   Y  tt ||   W d    n	1 sw   Y  tt | |  W d    n	1 sw   Y  tt|| ||dd t|||dd t|||dd   tt|d ||dd d| t|||dd   ttd| ||dd d| t| ||dd   tt|| ||dd t|||dd t|||dd   tt ||   W d    n	1 s,w   Y  tt | |  W d    n	1 sFw   Y  || }
t|
jdk || }
t|
jdk d| }
t|
jdk | }
t|
jdk d S )Nc                   @   s   e Zd ZdS )z.TestStateSpace.test_operators.<locals>.BadTypeN)r   r   r   r.   r.   r.   r/   BadType=  s    r@  rJ   gffffff?r   grX   r   rI   gg?r  g?d   rG   )r   r   gh㈵>)r*   rQ   rC   ro   )r   r    rR   to_discreter   r   intfloatcomplexfloat32
complex128r   r   r   	TypeErrorr%   r   r3  )r8   r@  s1s2
s_discretes2_discretes3_discreter   r   typr5  r.   r.   r/   test_operators:  s   























""

zTestStateSpace.test_operatorsN)r   r   r   r8  r<  r?  rO  r.   r.   r.   r/   r7    s
    
r7  c                   @   r   )TestTransferFunctionc                 C   s6   t dd t dgdg t tdgtdg d S NrX   rG   )r   r    rR   r/  r.   r.   r/   r8    s   
z(TestTransferFunction.test_initializationc                 C   sl   t ddgddg}tt| t tt| t  tt| t tt ||u t| |u d S NrX   r   rZ   )r   r   r2  r9  r   r:  r;  r   r4  r.   r.   r/   r<    s   z$TestTransferFunction.test_conversionc                 C   s2   t ddgddg}t|jdg t|jdg d S rR  )r   r   r>  r   r4  r.   r.   r/   r?    s   z$TestTransferFunction.test_propertiesN)r   r   r   r8  r<  r?  r.   r.   r.   r/   rP    s    rP  c                   @   r+  )TestZerosPolesGainc                 C   s<   t ddd t dgdgd t tdgtdgd d S rQ  )r   r    rR   r/  r.   r.   r/   r8    s    z&TestZerosPolesGain.test_initializationc                 C   sf   t ddd}tt| t tt| t tt| t  tt ||u t| |u d S )NrX   rG   rQ   )r   r   r2  r9  r   r:  r   r;  r4  r.   r.   r/   r<    s   z"TestZerosPolesGain.test_conversionN)r   r   r   r8  r<  r.   r.   r.   r/   rS    s    rS  c                   @   s   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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 ).Test_abcd_normalizec                 C   sR   t ddgddgg| _t dgdgg| _t ddgg| _t dgg| _d S )Nr   r   r   r   r   r         @)r    rR   r9   r:   r   r   r/  r.   r.   r/   setup_method  s   z Test_abcd_normalize.setup_methodc                 C   s   t tt d S r   )r   r%   r   r/  r.   r.   r/   test_no_matrix_fails  r   z(Test_abcd_normalize.test_no_matrix_failsc                 C   s    t ttddg| j| j| j d S )NrX   rZ   )r   r%   r   r:   r   r   r/  r.   r.   r/   test_A_nosquare_fails  s   z)Test_abcd_normalize.test_A_nosquare_failsc                 C       t tt| jddg| j| j d S NrZ   rc   r   r%   r   r9   r   r   r/  r.   r.   r/   test_AB_mismatch_fails     z*Test_abcd_normalize.test_AB_mismatch_failsc                 C   s$   t tt| j| jdgdgg| j d S )Nr   r   )r   r%   r   r9   r:   r   r/  r.   r.   r/   test_AC_mismatch_fails  s   z*Test_abcd_normalize.test_AC_mismatch_failsc                 C   s    t tt| j| j| jddg d S )NrU  r   )r   r%   r   r9   r:   r   r/  r.   r.   r/   test_CD_mismatch_fails  s   
z*Test_abcd_normalize.test_CD_mismatch_failsc                 C   rY  rZ  r[  r/  r.   r.   r/   test_BD_mismatch_fails  r]  z*Test_abcd_normalize.test_BD_mismatch_failsc                 C   sR   t | j| j| j| j\}}}}t|| j t|| j t|| j t|| j d S r   )r   r9   r:   r   r   r   r8   r9   r:   r   r   r.   r.   r/   "test_normalized_matrices_unchanged  s
   z6Test_abcd_normalize.test_normalized_matrices_unchangedc                 C   s   t | j| jddgd\}}}}t|jd |jd  t|jd |jd  t|jd |jd  t|jd |jd  t|jd |jd  d S r=  )r   r9   r:   r   r   ra  r.   r.   r/   r     s   zTest_abcd_normalize.test_shapesc                 C   s~   t d}t d}t| j||d\}}}}t|| j t|| t|| t|jd |jd  t|jd | jjd  d S )NrG   r   )r   r   r9   r:   r   r   rX   r    r   r   r9   r   r   )r8   B_D_r9   r:   r   r   r.   r.   r/    test_zero_dimension_is_not_none1  s   



z4Test_abcd_normalize.test_zero_dimension_is_not_none1c                 C   s|   t d}t d}t| j||d\}}}}t|| j t|| t|| t|jd |jd  t|jd |jd  d S )Nrc  )r   rG   r9   r:   r   r   rX   re  )r8   rf  C_r9   r:   r   r   r.   r.   r/    test_zero_dimension_is_not_none2   s   



z4Test_abcd_normalize.test_zero_dimension_is_not_none2c                 C   sl   t | j| j| jd\}}}}t|jd |jd  t|jd |jd  t|j| jjd | jjd f d S )N)r:   r   r   r   rX   )r   r:   r   r   r   r   ra  r.   r.   r/   test_missing_A*     $z"Test_abcd_normalize.test_missing_Ac                 C   sl   t | j| j| jd\}}}}t|jd |jd  t|jd |jd  t|j| jjd | jjd f d S )N)r9   r   r   r   rX   )r   r9   r   r   r   r   ra  r.   r.   r/   test_missing_B0  rm  z"Test_abcd_normalize.test_missing_Bc                 C   sl   t | j| j| jd\}}}}t|jd |jd  t|jd |jd  t|j| jjd | jjd f d S )Nrd  r   rX   )r   r9   r:   r   r   r   ra  r.   r.   r/   test_missing_C6  rm  z"Test_abcd_normalize.test_missing_Cc                 C   sl   t | j| j| jd\}}}}t|jd |jd  t|jd |jd  t|j| jjd | jjd f d S )Nri  r   rX   )r   r9   r:   r   r   r   ra  r.   r.   r/   test_missing_D<  rm  z"Test_abcd_normalize.test_missing_Dc                 C   s   t | j| jd\}}}}t|jd |jd  t|jd |jd  t|jd |jd  t|j| jjd | jjd f t|j| jjd | jjd f d S )N)r   r   r   rX   )r   r   r   r   r   ra  r.   r.   r/   test_missing_ABB  s    $z#Test_abcd_normalize.test_missing_ABc                 C   s   t | j| jd\}}}}t|jd |jd  t|jd |jd  t|jd |jd  t|jd |jd  t|j| jjd | jjd f t|j| jjd | jjd f d S )N)r:   r   r   rX   )r   r:   r   r   r   ra  r.   r.   r/   test_missing_ACJ      $z#Test_abcd_normalize.test_missing_ACc                 C   s   t | j| jd\}}}}t|jd |jd  t|jd |jd  t|jd |jd  t|jd |jd  t|j| jjd | jjd f t|j| jjd | jjd f d S )N)r:   r   r   rX   )r   r:   r   r   r   ra  r.   r.   r/   test_missing_ADS  rs  z#Test_abcd_normalize.test_missing_ADc                 C   s   t | j| jd\}}}}t|jd |jd  t|jd |jd  t|jd |jd  t|jd |jd  t|j| jjd | jjd f t|j| jjd | jjd f d S )N)r9   r   r   rX   )r   r9   r   r   r   ra  r.   r.   r/   test_missing_BC\  rs  z#Test_abcd_normalize.test_missing_BCc                 C   s   t tt| jd d S )N)r   )r   r%   r   r   r/  r.   r.   r/   test_missing_ABC_failse  s   z*Test_abcd_normalize.test_missing_ABC_failsc                 C      t tt| j| jd d S )N)r9   r   )r   r%   r   r9   r   r/  r.   r.   r/   test_missing_BD_failsh     z)Test_abcd_normalize.test_missing_BD_failsc                 C   rw  )N)r9   r:   )r   r%   r   r9   r:   r/  r.   r.   r/   test_missing_CD_failsk  ry  z)Test_abcd_normalize.test_missing_CD_failsN)r   r   r   rV  rW  rX  r\  r^  r_  r`  rb  r   rh  rk  rl  rn  ro  rp  rq  rr  rt  ru  rv  rx  rz  r.   r.   r.   r/   rT    s.    

			rT  c                   @   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S )	Test_bodec                 C   sD   t dgddg}g d}t||d\}}}g d}t||dd d S )NrX   r  rX   r_   rA  r   )r   rY   re   rk   r   r   r   r   )r8   r   r   magphaseexpected_magr.   r.   r/   test_01q  s
   zTest_bode.test_01c                 C   sD   t dgddg}g d}t||d\}}}g d}t||dd d S )NrX   r  rX   r_   r}  )gig33333Ur   r~  )r8   r   r   r  r  expected_phaser.   r.   r/   test_02  s
   zTest_bode.test_02c                 C   sn   t dgddg}g d}t||d\}}}|d }t|j|t|j| }dtt| }t|| d S )NrX   r|  r}                ?g      4@)	r   r   r    polyvalr   r   log10absr   )r8   r   r   r  r  jwr   r  r.   r.   r/   test_03  s   zTest_bode.test_03c                 C   sv   t dgddg}g d}t||d\}}}|d }t|j|t|j| }t|j|jd tj	 }t
|| d S )NrX   r|  r}  r  g     f@)r   r   r    r  r   r   arctan2r#   r"   pir   )r8   r   r   r  r  r  r   r  r.   r.   r/   test_04  s   zTest_bode.test_04c                 C   sB   t dgddg}d}tdd|}t||d\}}}t|| d S NrX   r_   ro   r  )r   r    logspacer   r   )r8   r   r  
expected_wr   r  r  r.   r.   r/   test_05  s
   zTest_bode.test_05c                 C   s4   t dgddg}t|dd\}}}t|d d d S NrX   r   rG   r  r
  )r   r   r   r8   r   r   r  r  r.   r.   r/   test_06  s   zTest_bode.test_06c                 C   s&   t dgg d}t|dd\}}}d S )NrX   )rX   r   rA  rG   r  )r   r   r  r.   r.   r/   test_07  s   zTest_bode.test_07c                 C   sB   t g g dd}|jtdddd\}}}tt|ddd	 d S )
N)r^   rf   rk   rl   rm   rX   rY   rg   rA  r}  i>   r   )r   r   r    r  r   minr  r.   r.   r/   test_08  s   zTest_bode.test_08c              	   C   s   t g d}t|j}t dgdgdgg}t g dg}t dgg}t }|t t||||}t	|dd\}}	}
W d    n1 sJw   Y  dt 
t dd|d    }t|	| d S )	Nr   r   r   r   r   r   r   r   r   rA  r     rb   )r    rR   r2   	companionr   r   r   r   r   r   r  sqrtr   )r8   r   r9   r:   r   r   r   r   r   r  r  expected_magnituder.   r.   r/   test_from_state_space  s   
 zTest_bode.test_from_state_spaceN)r   r   r   r  r  r  r  r  r  r  r  r  r.   r.   r.   r/   r{  o  s    
r{  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )Test_freqrespc                 C   s\   t dgddg}g d}t||d\}}g d}g d}t|j|dd t|j|dd d S )NrX   r  r}  )gGz?r   gׁsF?)MbXrJ   r  r   r   r   r   r"   r#   )r8   r   r   Hexpected_reexpected_imr.   r.   r/   test_output_manual  s   z Test_freqresp.test_output_manualc                 C   sl   t dgddg}g d}t||d\}}|d }t|j|t|j| }t|j|j t|j|j d S )NrX   r|  r}  r  )	r   r   r    r  r   r   r   r"   r#   r8   r   r   r  r5  r>   r.   r.   r/   test_output  s   zTest_freqresp.test_outputc                 C   s@   t dgddg}d}tdd|}t||d\}}t|| d S r  )r   r    r  r   r   )r8   r   r  r  r   r  r.   r.   r/   test_freq_range  s
   zTest_freqresp.test_freq_rangec                 C   s2   t dgddg}t|dd\}}t|d d d S r  )r   r   r   )r8   r   r   r  r.   r.   r/   test_pole_zero  s   zTest_freqresp.test_pole_zeroc                 C   s   t g d}t|j}t dgdgdgg}t g dg}t dgg}t }|t t||||}t	|dd\}}	W d    n1 sIw   Y  |d }
ddd|
  d|
d   |
d	   }t
|	j|j t
|	j|j d S )
Nr  r   r   r  rA  r  r  rG   rQ   )r    rR   r2   r  r   r   r   r   r   r   r   r"   r#   )r8   r   r9   r:   r   r   r   r   r   r  r5  r>   r.   r.   r/   r    s   
$z#Test_freqresp.test_from_state_spacec                 C   sd   t g dgd dg}g d}t||d\}}|d }d|d d  }t|j|j t|j|j d S )NrZ   rC   rX   r|  r}  r  r  r  r.   r.   r/   test_from_zpk  s   zTest_freqresp.test_from_zpkN)	r   r   r   r  r  r  r  r  r  r.   r.   r.   r/   r    s    
r  )r   r   )8abcr   r   numpyr    numpy.testingr   r   r   r   r   pytestr   r   r	   scipy.signalr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   scipy.signal._filter_designr   scipy.linalgr2   r0   r1   r   r   r   r  r  r"  r'  r(  r,  r-  r1  r7  rP  rS  rT  r{  r  r.   r.   r.   r/   <module>   s@    L
 Z q%IC  d