o
    g.                     @   s   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  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)assert_almost_equalassert_equalassert_assert_allcloseassert_array_equal)raisesc                 C   s   ||| |  |  }|S N tf0f1t1fr	   r	   _/home/ubuntu/cloudmapper/venv/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'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_zero1      zTestChirp.test_linear_at_zeroc           
   
   C   l   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	t|	dk  d S )Nr%   r#   r$   r   d   ư>	r   linspacer)   _chirp_phaser    maxabsr   r   
r,   r'   r   r   r   r   phaser   r   abserrr	   r	   r   test_linear_freq_015      zTestChirp.test_linear_freq_01c           
   
   C   l   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	t|	dk  d S )Nr%         i@      Y@      $@r   r1   r2   r3   r8   r	   r	   r   test_linear_freq_02@   r<   zTestChirp.test_linear_freq_02c                 C   r"   )Nr   r#   r$   	quadraticr&   r(   r+   r	   r	   r   test_quadratic_at_zeroK   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$   rB   F)r   r   r   r   r'   r   r(   r+   r	   r	   r   test_quadratic_at_zero2O   s   z!TestChirp.test_quadratic_at_zero2c           
   
   C   r0   )NrB   r#   r$   r     r2   	r   r4   r)   r5   r    r6   r7   r   r   r8   r	   r	   r   test_quadratic_freq_01T   r<   z TestChirp.test_quadratic_freq_01c           
   
   C   sl   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	t|	dk  d S )NrB         4@r@   r   rE   r2   rF   r8   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_zeroj   r/   z"TestChirp.test_logarithmic_at_zeroc           
   
   C   r0   )NrJ   r#   r$   r   '  r2   	r   r4   r)   r5   r    r6   r7   r   r   r8   r	   r	   r   test_logarithmic_freq_01n   r<   z"TestChirp.test_logarithmic_freq_01c           
   
   C   r=   )NrJ   r>   r?   r@   r   rL   r2   rM   r8   r	   r	   r   test_logarithmic_freq_02y   r<   z"TestChirp.test_logarithmic_freq_02c           
   
   C   sl   d}d}d}d}t d|d}t|||||}t||\}}t t |t|||| }	t|	dk  d S )NrJ   r?   r@   r   rL   r2   rM   r8   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|	|
 qd S )NrQ   r#   r   rL   r@   g      $      )r   r4   r)   r5   r    r   r   )r,   r'   r   r   casesr   r   r9   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 )NrQ   r#   r      r   r   r4   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@   rH   r#   r   
   rX   )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@   rH   r   r            @   z'Integer input 't1=3' gives wrong resulterr_msgr   r4   r)   r*   r   )r,   r   r   r   r   float_result
int_resultrc   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 )
NrH   r`   r   r   r_   r@   r]   z(Integer input 'f0=10' gives wrong resultrb   rd   )r,   r   r   r   r   re   rf   rc   r	   r	   r   test_integer_f0   rh   zTestChirp.test_integer_f0c                 C   sT   d}d}t ddd}d}t||||}d}t||||}d}t|||d	 d S )
Nr@   r`   r   r   r_   rH      z(Integer input 'f1=20' gives wrong resultrb   rd   )r,   r   r   r   r   re   rf   rc   r	   r	   r   test_integer_f1   rh   zTestChirp.test_integer_f1c                 C   s\   d}d}d}t ddd}t|t|t|t|}t||||}d}t|||d d S )	Nr]   ra   rj   r   r   r_   z5Integer input 'f0=10, t1=3, f1=20' gives wrong resultrb   )r   r4   r)   r*   floatr   )r,   r   r   r   r   re   rf   rc   r	   r	   r   test_integer_all   s   zTestChirp.test_integer_allN)__name__
__module____qualname__r.   r;   rA   rC   rD   rG   rI   rK   rN   rO   rP   rR   rV   r[   r^   rg   ri   rk   rm   r	   r	   r	   r   r!   /   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 || }t|dk  d S )N)r#           r#   r   r`   rL   r2   	r   poly1dr4   r)   _sweep_poly_phaser    r6   r7   r   r,   pr   r9   r   r   rU   r:   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 || }t|dk  d S )Nr$   r   r`   rL   r2   rt   rw   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 || }t|dk  d S )NrS   r@   r   r`   rL   r2   rt   rw   r	   r	   r   test_sweep_poly_linear   rz   z$TestSweepPoly.test_sweep_poly_linearc                 C   rr   )N)r#   rs          r   r`   rL   r2   rt   rw   r	   r	   r   test_sweep_poly_quad2   rz   z#TestSweepPoly.test_sweep_poly_quad2c                 C   rr   )Nr$   r#   rs   r}   r   r$   rL   r2   rt   rw   r	   r	   r   test_sweep_poly_cubic  rz   z#TestSweepPoly.test_sweep_poly_cubicc                 C   sh   t g d}t ddd}t||}t||\}}t ||}t t || }t	|dk  dS )z1Use an array of coefficients instead of a poly1d.r   r   r$   rL   r2   N)
r   arrayr4   r)   rv   r    ru   r6   r7   r   rw   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 || }t|dk  dS )z/Use a list of coefficients instead of a poly1d.r   r   r$   rL   r2   N)	r   r4   r)   rv   r    ru   r6   r7   r   rw   r	   r	   r   test_sweep_poly_cubic3  s   z$TestSweepPoly.test_sweep_poly_cubic3N)
rn   ro   rp   ry   r{   r|   r~   r   r   r   r	   r	   r	   r   rq      s    					
rq   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 resultrb   r)   
gausspulser   r,   re   rf   rc   r	   r	   r   test_integer_fc$     zTestGaussPulse.test_integer_fcc                 C   r   )Nr   r#   )bwr   z'Integer input 'bw=1' gives wrong resultrb   r   r   r	   r	   r   test_integer_bw*  r   zTestGaussPulse.test_integer_bwc                 C   r   )Nr   g      )bwriz)Integer input 'bwr=-6' gives wrong resultrb   r   r   r	   r	   r   test_integer_bwr0  r   zTestGaussPulse.test_integer_bwrc                 C   r   )Nr   g      N)tpriz*Integer input 'tpr=-60' gives wrong resultrb   r   r   r	   r	   r   test_integer_tpr6  r   zTestGaussPulse.test_integer_tprN)rn   ro   rp   r   r   r   r   r	   r	   r	   r   r   "  s
    r   c                   @   r   )
TestUnitImpulsec                 C   s:   t tdg d t tdg dg dg dg d S )N   )r   r   r   r   r   r   r   ra   ra   )r   r   r   r   r   r   r   r)   unit_impulser,   r	   r	   r   test_no_index?  s   
zTestUnitImpulse.test_no_indexc              	   C   sr   t tddg d t tddg dg dg dg tdd	}t |tg d
g d
g dg d
g d S )Nr]   ra   )
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   r,   impr	   r	   r   
test_indexD  s   zTestUnitImpulse.test_indexc                 C   s>   t tddg dg dg dg t tddg d d S )Nr   midr   r   	   )	r   r   r   r   r   r   r   r   r   r   r   r	   r	   r   test_midQ  s   zTestUnitImpulse.test_midc                 C   sj   t d}tt|jtj t jddtd}tt|jtj t jddt	d}tt|jtj
 d S )Nr   rW   ra   )dtype)rW   r   )ra   r   )r)   r   r   r   
issubdtyper   floatingintintegercomplexcomplexfloatingr   r	   r	   r   
test_dtypeW  s   
zTestUnitImpulse.test_dtypeN)rn   ro   rp   r   r   r   r   r	   r	   r	   r   r   =  s
    r   )T)numpyr   numpy.testingr   r   r   r   r   pytestr   rY   scipy.signal._waveformssignal
_waveformsr)   r   r   r   r   r    r!   rq   r   r   r	   r	   r	   r   <module>   s    
 0D