o
    h2                     @   s   d dl Zd dlmZ d dlmZmZmZ d dl	m
  mZ dd ZdddZd	d
 Zdd Zdd ZG dd dZG dd dZG dd dZG dd dZdS )    N)raises)assert_almost_equalxp_assert_equalxp_assert_closec                 C   s   ||| |  |  }|S N tf0f1t1fr   r   U/var/www/vscode/kcb/lib/python3.10/site-packages/scipy/signal/tests/test_waveforms.pychirp_linear      r   Tc                 C   sH   |r||| | d  |d   }|S ||| ||  d  |d   }|S )N   r   )r	   r
   r   r   vertex_zeror   r   r   r   chirp_quadratic   s
    r   c                 C   s   ||| | |   }|S r   r   r   r   r   r   chirp_geometric   r   r   c                 C   s$   || | || |  ||   }|S r   r   r   r   r   r   chirp_hyperbolic   s    r   c                 C   sL   | d | d  }t |dt j  | }d| dd | dd   }||fS )zR
    Compute theta'(t)/(2*pi), where theta'(t) is the derivative of theta(t).
       r   r   g      ?N)npdiffpi)r	   thetadtr   tfr   r   r   compute_frequency$   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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 ).	TestChirpc                 C   "   t jdddddd}t|d d S )Nr         ?       @linearr	   r
   r   r   method	waveformschirpr   selfwr   r   r   test_linear_at_zero2      zTestChirp.test_linear_at_zeroc           
   
   C   l   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	|	dk s4J d S )Nr#   r!   r"   r   d   ư>r   linspacer'   _chirp_phaser   maxabsr   
r*   r%   r
   r   r   r	   phaser   r   abserrr   r   r   test_linear_freq_016      zTestChirp.test_linear_freq_01c           
   
   C   l   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	|	dk s4J d S )Nr#         i@      Y@      $@r   r/   r0   r1   r6   r   r   r   test_linear_freq_02A   r:   zTestChirp.test_linear_freq_02c                 C   s|   d}d}d}d}t d|d}tj|||||dd}tj|||||dd}t |}t |}	|t |	 }
|
d	k s<J d S )
Nr#   r!   r"   r   r/   F)complexTr0   )r   r2   r'   r(   varreal)r*   r%   r
   r   r   r	   w_real	w_complexw_pwr_rw_pwr_cerrr   r   r   test_linear_complex_powerL   s   

z#TestChirp.test_linear_complex_powerc                 C   s$   t jddddddd}t|d d S )Nr         $r!   r#   Tr	   r
   r   r   r%   r@         ?        r'   r(   r   r)   r   r   r   test_linear_complex_at_zero]      z%TestChirp.test_linear_complex_at_zeroc                 C   r    )Nr   r!   r"   	quadraticr$   r&   r)   r   r   r   test_quadratic_at_zerob   r-   z TestChirp.test_quadratic_at_zeroc                 C   s$   t jddddddd}t|d d S )Nr   r!   r"   rO   F)r	   r
   r   r   r%   r   r&   r)   r   r   r   test_quadratic_at_zero2f   rN   z!TestChirp.test_quadratic_at_zero2c                 C   s$   t jddddddd}t|d d S )	Nr         r"   r!   rO   TrJ   rK   rL   r)   r   r   r   test_quadratic_complex_at_zerok   rN   z(TestChirp.test_quadratic_complex_at_zeroc           
   
   C   r.   )NrO   r!   r"   r     r0   r   r2   r'   r3   r   r4   r5   r   r6   r   r   r   test_quadratic_freq_01p   r:   z TestChirp.test_quadratic_freq_01c           
   
   C   sl   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	|	dk s4J d S )NrO         4@r>   r   rT   r0   rU   r6   r   r   r   test_quadratic_freq_02{   r:   z TestChirp.test_quadratic_freq_02c                 C   r    )Nr   r!   r"   logarithmicr$   r&   r)   r   r   r   test_logarithmic_at_zero   r-   z"TestChirp.test_logarithmic_at_zeroc           
   
   C   r.   )NrY   r!   r"   r   '  r0   r   r2   r'   r3   r   r4   r5   r   r6   r   r   r   test_logarithmic_freq_01   r:   z"TestChirp.test_logarithmic_freq_01c           
   
   C   r;   )NrY   r<   r=   r>   r   r[   r0   r\   r6   r   r   r   test_logarithmic_freq_02   r:   z"TestChirp.test_logarithmic_freq_02c           
   
   C   sl   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	|	dk s4J d S )NrY   r=   r>   r   r[   r0   r\   r6   r   r   r   test_logarithmic_freq_03   r:   z"TestChirp.test_logarithmic_freq_03c                 C   s"   t jdddddd}t|d d S )Nr   r>   r!   
hyperbolicr$   r&   r)   r   r   r   test_hyperbolic_at_zero   r-   z!TestChirp.test_hyperbolic_at_zeroc                 C   s   d}d}t d|d}ddgddgddgddgg}|D ]"\}}t|||||}t||\}}	t||||}
t|	|
dd	 qd S )
Nr`   r!   r   r[   r>   rI   rR   gHz>)atol)r   r2   r'   r3   r   r   r   )r*   r%   r   r	   casesr
   r   r7   r   r   expectedr   r   r   test_hyperbolic_freq_01   s   z!TestChirp.test_hyperbolic_freq_01c                 C   sF   d}d}t d|d}tttj|d|d| tttj|d|d| d S )Nr`   r!   r      r   r   r2   assert_raises
ValueErrorr'   r(   )r*   r%   r   r	   r   r   r   test_hyperbolic_zero_freq   s
   z#TestChirp.test_hyperbolic_zero_freqc                 C   s8   d}d}d}d}t d|d}tttj||||| d S )Nfoor>   rW   r!   r   
   rg   )r*   r%   r
   r   r   r	   r   r   r   test_unknown_method   s   zTestChirp.test_unknown_methodc                 C   sT   d}d}t ddd}d}t||||}d}t||||}d}t|||d	 d S )
Nr>   rW   r   r            @   z'Integer input 't1=3' gives wrong resulterr_msgr   r2   r'   r(   r   )r*   r
   r   r	   r   float_result
int_resultrr   r   r   r   test_integer_t1      zTestChirp.test_integer_t1c                 C   sT   d}d}t ddd}d}t||||}d}t||||}d}t|||d	 d S )
NrW   ro   r   r   rn   r>   rl   z(Integer input 'f0=10' gives wrong resultrq   rs   )r*   r   r   r	   r
   rt   ru   rr   r   r   r   test_integer_f0   rw   zTestChirp.test_integer_f0c                 C   sT   d}d}t ddd}d}t||||}d}t||||}d}t|||d	 d S )
Nr>   ro   r   r   rn   rW      z(Integer input 'f1=20' gives wrong resultrq   rs   )r*   r
   r   r	   r   rt   ru   rr   r   r   r   test_integer_f1   rw   zTestChirp.test_integer_f1c                 C   s\   d}d}d}t ddd}t|t|t|t|}t||||}d}t|||d d S )	Nrl   rp   ry   r   r   rn   z5Integer input 'f0=10, t1=3, f1=20' gives wrong resultrq   )r   r2   r'   r(   floatr   )r*   r
   r   r   r	   rt   ru   rr   r   r   r   test_integer_all   s   zTestChirp.test_integer_allN)__name__
__module____qualname__r,   r9   r?   rH   rM   rP   rQ   rS   rV   rX   rZ   r]   r^   r_   ra   re   rj   rm   rv   rx   rz   r|   r   r   r   r   r   0   s.    r   c                   @   sD   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 )TestSweepPolyc                 C   b   t g d}t ddd}t||}t||\}}||}t t || }|dk s/J d S )N)r!           r!   r   ro   r[   r0   r   poly1dr2   r'   _sweep_poly_phaser   r4   r5   r*   pr	   r7   r   r   rd   r8   r   r   r   test_sweep_poly_quad1      z#TestSweepPoly.test_sweep_poly_quad1c                 C   s^   t d}t ddd}t||}t||\}}||}t t || }|dk s-J d S )Nr"   r   ro   r[   r0   r   r   r   r   r   test_sweep_poly_const  s   
z#TestSweepPoly.test_sweep_poly_constc                 C   sb   t ddg}t ddd}t||}t||\}}||}t t || }|dk s/J d S )NrR   r>   r   ro   r[   r0   r   r   r   r   r   test_sweep_poly_linear  r   z$TestSweepPoly.test_sweep_poly_linearc                 C   r   )N)r!   r          r   ro   r[   r0   r   r   r   r   r   test_sweep_poly_quad2  r   z#TestSweepPoly.test_sweep_poly_quad2c                 C   r   )Nr"   r!   r   r   r   r"   r[   r0   r   r   r   r   r   test_sweep_poly_cubic   r   z#TestSweepPoly.test_sweep_poly_cubicc                 C   sh   t g d}t ddd}t||}t||\}}t ||}t t || }|dk s2J dS )z1Use an array of coefficients instead of a poly1d.r   r   r"   r[   r0   N)	r   arrayr2   r'   r   r   r   r4   r5   r   r   r   r   test_sweep_poly_cubic2)  s   z$TestSweepPoly.test_sweep_poly_cubic2c                 C   sb   g d}t ddd}t||}t||\}}t ||}t t || }|dk s/J dS )z/Use a list of coefficients instead of a poly1d.r   r   r"   r[   r0   N)r   r2   r'   r   r   r   r4   r5   r   r   r   r   test_sweep_poly_cubic33  s   z$TestSweepPoly.test_sweep_poly_cubic3N)
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d Zd	S )
TestGaussPulsec                 C   2   t jddd}t jddd}d}t|||d d S )Ncutoffg     @@)fci  z*Integer input 'fc=1000' gives wrong resultrq   r'   
gausspulser   r*   rt   ru   rr   r   r   r   test_integer_fc@     zTestGaussPulse.test_integer_fcc                 C   r   )Nr   r!   )bwr   z'Integer input 'bw=1' gives wrong resultrq   r   r   r   r   r   test_integer_bwF  r   zTestGaussPulse.test_integer_bwc                 C   r   )Nr   g      )bwriz)Integer input 'bwr=-6' gives wrong resultrq   r   r   r   r   r   test_integer_bwrL  r   zTestGaussPulse.test_integer_bwrc                 C   r   )Nr   g      N)tpriz*Integer input 'tpr=-60' gives wrong resultrq   r   r   r   r   r   test_integer_tprR  r   zTestGaussPulse.test_integer_tprN)r}   r~   r   r   r   r   r   r   r   r   r   r   >  s
    r   c                   @   r   )
TestUnitImpulsec                 C   sF   t tdtg d t tdtg dg dg dg d S )N   )r!   r   r   r   r   r   r   rp   rp   )r!   r   r   r   r   r   r   r'   unit_impulser   asarrayr*   r   r   r   test_no_index[  s   

zTestUnitImpulse.test_no_indexc              	   C   s~   t tddtg d t tddtg dg dg dg td	d
}t |tg dg dg dg dg d S )Nrl   rp   )
r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   )   r   r   )r   r   r   r   )r   r   r   r   r   r*   impr   r   r   
test_indexa  s   zTestUnitImpulse.test_indexc                 C   sJ   t tddtg dg dg dg t tddtg d d S )Nr   midr   r   r   	   )	r   r   r   r   r   r   r   r   r   r   r   r   r   r   test_midn  s   zTestUnitImpulse.test_midc                 C   sj   t d}t|jtjsJ t jddtd}t|jtjs!J t jddtd}t|jtj	s3J d S )Nr   rf   rp   )dtype)rf   r   )rp   r   )
r'   r   r   
issubdtyper   floatingintintegerr@   complexfloatingr   r   r   r   
test_dtypet  s   
zTestUnitImpulse.test_dtypeN)r}   r~   r   r   r   r   r   r   r   r   r   r   Y  s
    r   )T)numpyr   pytestr   rh   scipy._lib._array_apir   r   r   scipy.signal._waveformssignal
_waveformsr'   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    
 KD