o
    4Bi                     @   sL  d dl Z d dlZd dlmZmZmZmZmZm	Z	m
Z
 d dlZd dlmZ d dlmZ d dlmZmZmZmZ d dlmZ d dl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
l#m$Z% d dl#m&Z' d dl#m(Z) G dd dZ*G dd dZ+G dd dZ,G dd dZ-G dd dZ.G dd dZ/G dd dZ0G dd dZ1dS )    N)assert_assert_approx_equalassert_allcloseassert_array_equalassert_equalassert_array_almost_equal_nulpsuppress_warnings)raises)signal)fftfreqrfftfreqfftirfft)	trapezoid)periodogramwelchlombscargle	coherencespectrogram
check_COLA
check_NOLA)hann)_spectral_helper)stft_compare)istft_compare)csd_comparec                   @   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ejjejdkdddd Zejjejdkdd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d0S )1TestPeriodogramc                 C   sj   t d}d|d< t|\}}t|t ddd t d}d|d< |d  d  < |d }t|| d S )	N      r         ?	          @   npzerosr   r   linspaceonesselfxfpq r/   `/var/www/html/Trade-python/venv/lib/python3.10/site-packages/scipy/signal/tests/test_spectral.pytest_real_onesided_even   s   

z'TestPeriodogram.test_real_onesided_evenc                 C   s^   t d}d|d< t|\}}t|t dd  t d}d|d< |d9 }t||dd	 d S )
N   r   r          @      .@r#   ?V瞯<atol)r%   r&   r   r   aranger(   r)   r/   r/   r0   test_real_onesided_odd$   s   

z&TestPeriodogram.test_real_onesided_oddc                 C   sT   t d}d|d< t|dd\}}t|tdd t dd}d|d< t|| d S )Nr   r   r   Freturn_onesided      ?      ?)r%   r&   r   r   r   fullr)   r/   r/   r0   test_real_twosided.   s   
z"TestPeriodogram.test_real_twosidedc                 C   sX   t d}d|d< t|dd\}}t|dd\}}t|t ddd t||d	  d S )
Nr   r   r   spectrumscalingdensityr   r    g      0@)r%   r&   r   r   r'   )r*   r+   r,   r-   gr.   r/   r/   r0   test_real_spectrum7   s   
z"TestPeriodogram.test_real_spectrumc                 C   sn   t jdtd}d|d< t|\}}t|t ddd t d}d|d< |d  d  < |d	 }t|| d S )
Nr   dtyper   r   r   r    r!   r"   r#   )r%   r&   intr   r   r'   r(   r)   r/   r/   r0   test_integer_even?   s   
z!TestPeriodogram.test_integer_evenc                 C   sb   t jdtd}d|d< t|\}}t|t dd  t d}d|d< |d9 }t||d	d
 d S )Nr2   rG   r   r   r3   r4   r#   r5   r6   r7   )r%   r&   rI   r   r   r9   r(   r)   r/   r/   r0   test_integer_oddJ   s   
z TestPeriodogram.test_integer_oddc                 C   sX   t jdtd}d|d< t|dd\}}t|tdd t dd}d|d< t|| d S )	Nr   rG   r   r   Fr;   r=   r>   )r%   r&   rI   r   r   r   r?   r)   r/   r/   r0   test_integer_twosidedT      z%TestPeriodogram.test_integer_twosidedc                 C   sX   t dt j}d|d< t|dd\}}t|tdd t dd}d|d< t|| d S )Nr         ?       @r   Fr;   r=         ?)r%   r&   
complex128r   r   r   r?   r)   r/   r/   r0   test_complex]   rM   zTestPeriodogram.test_complexc                 C   s   t tttdtjdd d S )N   foorB   )assert_raises
ValueErrorr   r%   r&   rP   r*   r/   r/   r0   test_unk_scalingf   s   
z TestPeriodogram.test_unk_scalingl        zOn some 32-bit tolerance issue)reasonc                 C   s   t jdt jd}|d}d|d d d d df< t|\}}t|jd t|ddd d f |ddd d f d t|ddd d f \}}t|t jd d f |dd d f d d S )	N   rG      r   
   r=   r   r[   r      r   <   )	r%   r&   float64reshaper   r   shaper   newaxisr*   r+   r,   r-   f0p0r/   r/   r0   test_nd_axis_m1j   s   
(*zTestPeriodogram.test_nd_axis_m1c                 C   s   t jdt jd}|d}d|dd d d d f< t|dd\}}t|jd t|d d ddf |d d ddf d	 t|d d ddf \}}t||d d ddf  d S )
NrY   rG   r\   r[   r   r=   r   axisr^   r[   r   r   r_   )r%   r&   r`   ra   r   r   rb   r   rd   r/   r/   r0   test_nd_axis_0x   s   
(zTestPeriodogram.test_nd_axis_0c                 C   sr   t d}d|d< t|dd\}}tdd}t|d|\}}t|| t|| tdd}ttt|d| d S )Nr   r   r   r\   r       )r%   r&   r   r
   
get_windowr   rT   rU   r*   r+   r,   r-   winfepewin_errr/   r/   r0   test_window_external   s   


z$TestPeriodogram.test_window_externalc                 C   sf   t d}d|d< t|\}}t|dd\}}t||d d d  t||d d d  t|jd d S )Nr   r   r   rm   nfftr[   )   )r%   r&   r   r   r   rb   )r*   r+   r,   r-   fpppr/   r/   r0   test_padded_fft   s   
zTestPeriodogram.test_padded_fftc                 C   \   t g \}}t|jd t|jd dD ]}t t|\}}t|j| t|j| qd S Nr   r}      r   r      r[   )r   r   rb   r%   emptyr*   r,   r-   rb   r/   r/   r0   test_empty_input      z TestPeriodogram.test_empty_inputc                 C   <   dD ]}t t|dd\}}t|j| t|j| qd S Nr   r   r   ri   )r   r%   r   r   rb   r*   rb   r,   r-   r/   r/   r0   test_empty_input_other_axis   
   z+TestPeriodogram.test_empty_input_other_axisc                 C   sn   t d}d|d< t|dd\}}t|t ddd t d}d|d< |d  d	  < |d
 }t|| d S )N   r   r   r   ru   r   r    r!   r"   r#   r$   r)   r/   r/   r0   test_short_nfft      

zTestPeriodogram.test_short_nfftc                 C   sn   t d}d|d< t|dd\}}t|t ddd t d}d|d< |d  d  < |d	 }t|| d S )
Nr   r   r   ru   r   r    r!   r"   r#   r$   r)   r/   r/   r0   test_nfft_is_xshape   r   z#TestPeriodogram.test_nfft_is_xshapec                 C   s~   t dd}d|d< t|\}}t|t ddd t dd}d|d< |d  d  < |d	 }t|| t|j|jk d S )
Nr   r,   r   r   r   r    r!   r"   r#   )r%   r&   r   r   r'   r(   r   rH   r)   r/   r/   r0   test_real_onesided_even_32   s   
z*TestPeriodogram.test_real_onesided_even_32c                 C   sr   t dd}d|d< t|\}}t|t dd  t dd}d|d< |d9 }t||d	d
 t|j|jk d S )Nr2   r,   r   r   r3   r4   r#   r5   Hz>r7   )r%   r&   r   r   r9   r(   r   rH   r)   r/   r/   r0   test_real_onesided_odd_32   s   z)TestPeriodogram.test_real_onesided_odd_32c                 C   sh   t dd}d|d< t|dd\}}t|tdd t ddd}d|d< t|| t|j|jk d S )	Nr   r,   r   r   Fr;   r=   r>   r%   r&   r   r   r   r?   r   rH   r)   r/   r/   r0   test_real_twosided_32      
z%TestPeriodogram.test_real_twosided_32c                 C   sh   t dd}d|d< t|dd\}}t|tdd t ddd	}d|d< t|| t|j|jk d S )
Nr   FrN   r   Fr;   r=   rO   r,   r   r)   r/   r/   r0   test_complex_32   r   zTestPeriodogram.test_complex_32c                 C   s`   t d}d|d< tdd}d}tt|d t||d W d    d S 1 s)w   Y  d S )	Nr   r   r   r   r\   zOthe size of the window must be the same size of the input on the specified axismatchwindow)r%   r&   r
   rn   rT   rU   r   )r*   r+   rp   expected_msgr/   r/   r0   test_shorter_window_error   s   
"z)TestPeriodogram.test_shorter_window_errorN)__name__
__module____qualname__r1   r:   r@   rF   rJ   rK   rL   rQ   rW   pytestmarkskipifsysmaxsizerg   rl   rt   rz   r   r   r   r   r   r   r   r   r   r/   r/   r/   r0   r      s>    
	
		



		

r   c                   @     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-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAS )B	TestWelchc                 C   s`   t d}d|d< d|d< t|dd\}}t|t ddd t g d}t||d	d	d
 d S Nr   r   r   r#   npersegr   r   iKGUU?gS8?#q?r   #q?r   r8   rtolr%   r&   r   r   r'   arrayr)   r/   r/   r0   r1         
z!TestWelch.test_real_onesided_evenc                 C   s`   t d}d|d< d|d< t|dd\}}t|t dd  t g d	}t||d
d
d d S Nr   r   r   r#   r    r         @      "@g9?g?p0?r   r   r   r   )r%   r&   r   r   r9   r   r)   r/   r/   r0   r:      r   z TestWelch.test_real_onesided_oddc                 C   s^   t d}d|d< d|d< t|ddd\}}t|tdd t g d}t||d	d	d
 d S Nr   r   r   r#   Fr   r<   r=   r   S8?r   r   r   r   r   r   r   r   )r%   r&   r   r   r   r   r)   r/   r/   r0   r@   
  s   
zTestWelch.test_real_twosidedc                 C   sb   t d}d|d< d|d< t|ddd\}}t|t ddd t g d	}t||d
d
d d S Nr   r   r   r#   rA   )r   rC   r   r   )g      ?g-UU?.iqUU?r   g-UU?r   r   r   r)   r/   r/   r0   rF        
zTestWelch.test_real_spectrumc                 C   sd   t jdtd}d|d< d|d< t|dd\}}t|t ddd t g d	}t||d
d
d d S Nr   rG   r   r   r#   r   r   r   r   r   r   )r%   r&   rI   r   r   r'   r   r)   r/   r/   r0   test_integer_onesided_even     z$TestWelch.test_integer_onesided_evenc                 C   sd   t jdtd}d|d< d|d< t|dd\}}t|t dd	  t g d
}t||ddd d S Nr   rG   r   r   r#   r    r   r   r   r   r   r   )r%   r&   rI   r   r   r9   r   r)   r/   r/   r0   test_integer_onesided_odd(  r   z#TestWelch.test_integer_onesided_oddc                 C   sb   t jdtd}d|d< d|d< t|ddd\}}t|tdd t g d	}t||d
d
d d S Nr   rG   r   r   r#   Fr   r=   r   r   r   )r%   r&   rI   r   r   r   r   r)   r/   r/   r0   rL   2     zTestWelch.test_integer_twosidedc                 C   sb   t dt j}d|d< d|d< t|ddd\}}t|tdd t g d}t||d	d	d
 d S Nr   rN   r   r#   Fr   r=   )g&>?#q?n)t?r   r   r   r   r   r   r   )r%   r&   rP   r   r   r   r   r)   r/   r/   r0   rQ   <  r   zTestWelch.test_complexc                 C   s    t tttdtjddd d S NrR   rS   )rC   r   )rT   rU   r   r%   r&   rP   rV   r/   r/   r0   rW   F  s   
zTestWelch.test_unk_scalingc                 C   s>   t jdt jdd }t|ddd\}}t|t |dd d S Nr\   rG   {Gz?linearr   detrendr6   r7   r%   r9   r`   r   r   
zeros_liker*   r+   r,   r-   r/   r/   r0   test_detrend_linearJ  s   zTestWelch.test_detrend_linearc                 C   s\   t jdt jdd }t|ddd\}}t|ddd d\}}t||dd	 t||dd	 d S )
Nr\   rG   r   Fr   c                 S      | S Nr/   r+   r/   r/   r0   <lambda>R      z.TestWelch.test_no_detrending.<locals>.<lambda>r6   r7   )r%   r9   r`   r   r   r*   r+   f1p1f2p2r/   r/   r0   test_no_detrendingO  s
   zTestWelch.test_no_detrendingc                 C   sB   t jdt jdd }t|ddd d\}}t|t |dd d S )	Nr\   rG   r   c                 S      t j| ddS Nl)typer
   r   segr/   r/   r0   r   Y      z1TestWelch.test_detrend_external.<locals>.<lambda>r   r6   r7   r   r   r/   r/   r0   test_detrend_externalV  s
   
zTestWelch.test_detrend_externalc                 C   sL   t jdt jdd }|d}t|ddd d\}}t|t |d	d
 d S )N(   rG   r   r[   r[   r\   r\   c                 S   r   r   r   r   r/   r/   r0   r   `  r   z7TestWelch.test_detrend_external_nd_m1.<locals>.<lambda>r   r6   r7   )r%   r9   r`   ra   r   r   r   r   r/   r/   r0   test_detrend_external_nd_m1\  s   

z%TestWelch.test_detrend_external_nd_m1c                 C   s\   t jdt jdd }|d}t |dd}t|dddd	 d
\}}t|t |dd d S )NrY   rG   r   rZ   r[   r   r\   c                 S      t j| dddS Nr   r   )rj   r   r   r   r/   r/   r0   r   h      z6TestWelch.test_detrend_external_nd_0.<locals>.<lambda>r   rj   r   r6   r7   )r%   r9   r`   ra   moveaxisr   r   r   r   r/   r/   r0   test_detrend_external_nd_0c  s   

z$TestWelch.test_detrend_external_nd_0c                 C   s   t jdt jdd }|d}t|dd\}}t|jd t|ddd d f |d	dd d f d
d
d t|ddd d f dd\}}t|t jd d f |d	d d f d
d
d d S NrY   rG   r   rZ   r\   r   r]   r   r   vIh%<=r   )	r%   r9   r`   ra   r   r   rb   r   rc   rd   r/   r/   r0   rg   k  s   
,.zTestWelch.test_nd_axis_m1c                 C   s   t jdt jdd }|d}t|ddd\}}t|jd t|d d ddf |d d d	df d
d
d t|d d ddf dd\}}t||d d d	df d
d
d d S NrY   rG   r   rh   r\   r   )r   rj   rk   r   r   r   r   )r%   r9   r`   ra   r   r   rb   r   rd   r/   r/   r0   rl   t  s   
,"zTestWelch.test_nd_axis_0c                 C   s   t d}d|d< d|d< t|dddd\}}tdd}t|d|d d\}}t|| t|| t|jd t|jd tt	t|d|d	d tdd
}tt	t|d|d d d S )Nr   r   r   r#   r\   r   r   r   rR   rm   )
r%   r&   r   r
   rn   r   r   rb   rT   rU   ro   r/   r/   r0   rt   }  s"   



zTestWelch.test_window_externalc                 C   r{   r|   )r   r   rb   r%   r   r   r/   r/   r0   r     r   zTestWelch.test_empty_inputc                 C   r   r   )r   r%   r   r   rb   r   r/   r/   r0   r     r   z%TestWelch.test_empty_input_other_axisc           
      C   s   t d}d|d< t !}d}|t| t|dd\}}t|ddd\}}W d    n1 s0w   Y  t|dd	\}}	t|| t||	 t|| t||	 d S 
Nr#   r   r   zBnperseg = 256 is greater than input length  = 8, using nperseg = 8r   r      r   r   r   )r%   r&   r   filterUserWarningr   r   
r*   r+   supmsgr,   r-   r   r   r   r   r/   r/   r0   test_short_data  s   



zTestWelch.test_short_datac              	   C   sF   t tttddtg d t tttddtdd d S NrR   r   )r   r   r   r   r   r^   )r[   r   )rT   rU   r   r%   r&   r   r9   ra   rV   r/   r/   r0   test_window_long_or_nd  s    z TestWelch.test_window_long_or_ndc                 C   sJ   t d}d|d d d< t|ddd\}}t g d}t||dd	 d S 
N@   r   r#   r   rR   r   noverlap)	r   gUUUUUU?UUUUUU?皙?r  r  r  r  gUUUUUU?g-q=r7   )r%   r&   r   r   r   r)   r/   r/   r0   test_nondefault_noverlap  s
   
z"TestWelch.test_nondefault_noverlapc                 C   s   t tttddddd d S NrR   r   r   r[      )rT   rU   r   r%   r&   rV   r/   r/   r0   test_bad_noverlap  s   zTestWelch.test_bad_noverlapc                 C   s   t tttdddd d S N   r   rR   )rv   r   )rT   rU   r   r%   r(   rV   r/   r/   r0   test_nfft_too_short  s   zTestWelch.test_nfft_too_shortc                 C   st   t dd}d|d< d|d< t|dd\}}t|t ddd t g d	d}t||d
d
d t|j|jk d S Nr   r,   r   r   r#   r   r   r   r   r   r   )r%   r&   r   r   r'   r   r   rH   r)   r/   r/   r0   r        
z$TestWelch.test_real_onesided_even_32c                 C   st   t dd}d|d< d|d< t|dd\}}t|t dd	  t g d
d}t||ddd t|j|jk d S Nr   r,   r   r   r#   r    r   r   r   )gx:?gyѲI?r   gw0?r   r   r   )r%   r&   r   r   r9   r   r   rH   r)   r/   r/   r0   r     r  z#TestWelch.test_real_onesided_odd_32c                 C   sr   t dd}d|d< d|d< t|ddd\}}t|tdd t g d	d}t||d
d
d t|j|jk d S Nr   r,   r   r   r#   Fr   r=   r   r   r   r%   r&   r   r   r   r   r   rH   r)   r/   r/   r0   r     s   
zTestWelch.test_real_twosided_32c                 C   s   t dd}d|d< d|d< t|ddd\}}t|tdd t g d	d
}t||ddd t|j|jkd|j d|j  d S Nr   r   rN   r   r#   Fr   r=   )g%?A2q?d^?r  g~?r  r  r  r,   r   r   zdtype mismatch, , r  r)   r/   r/   r0   r     s   
zTestWelch.test_complex_32c                 C   s   t d}d}t|dd |d d  }|d  d9  < t|d|d\}}t|d	|d\}}t|| t|| d
}t|dd |d d  }t|d|d\}}t|d	|d\}}t|| t|| d S Nr     r=   r[   r   r!   r   r   rv   r^      )r%   r&   r   r   r   )r*   r+   rv   r,   fodd_fevenr/   r/   r0   test_padded_freqs  s   



zTestWelch.test_padded_freqsc                 C   s   d}d}t |d }d}t || | }t|| }|tdtj | |  }dD ]7}t||||dd\}	}
t||||d	d\}}t|
| |d d
  ttt|||td d dd q+d S )NrY   g     @r\   ,  r[   )r   bartlett)tukey皙?flattoprA   )fsr   r   rC   rD   r"   gMbP?r   )	rI   r%   r9   sinpir   r   sqrtr   )r*   Ar$  r   fsigiittr+   r   r  p_specfreqp_densr/   r/   r0   test_window_correction   s&   



 z TestWelch.test_window_correctionc           	      C   s   t jd t jd}t|\}}tdD ]8}dgd }d||< ||}t||d\}}t|||j d\}}t||	 |d t||	 ||j d qd S )N     r   r   r!   ri   err_msg)
r%   randomseedrandnr   rangera   ndimr   squeeze)	r*   x_flatr  p_flatanewshaper+   p_plusp_minusr/   r/   r0   test_axis_rolling  s   

zTestWelch.test_axis_rollingc                 C   st   t d}d|d< d|d< t|ddd\}}t|t ddd t g d	}t||d
d
d ttt|ddd d S )Nr   r   r   r#   median)r   averager   r   )r"  g?        g&E    9rD  r   r   zunrecognised-average)r%   r&   r   r   r'   r   rT   rU   r)   r/   r/   r0   test_average'  s   


zTestWelch.test_averageN)#r   r   r   r1   r:   r@   rF   r   r   rL   rQ   rW   r   r   r   r   r   rg   rl   rt   r   r   r   r   r  r
  r  r   r   r   r   r  r0  rA  rE  r/   r/   r/   r0   r      sB    







			r   c                   @   r   )BTestCSDc                 C   s\   t d}t d}t ddd}t jdt jd}t||dd\}}t|| t|| d S )Nr#   r  r   r   r	  rG   r   r%   r&   r'   rP   csdr   r*   r+   yr,   cr   c1r/   r/   r0   test_pad_shorter_x5     


zTestCSD.test_pad_shorter_xc                 C   s\   t d}t d}t ddd}t jdt jd}t||dd\}}t|| t|| d S )Nr  r#   r   r   r	  rG   r   rG  rI  r/   r/   r0   test_pad_shorter_y@  rN  zTestCSD.test_pad_shorter_yc                 C   sb   t d}d|d< d|d< t||dd\}}t|t ddd t g d}t||d	d	d
 d S r   r%   r&   rH  r   r'   r   r)   r/   r/   r0   r1   K  r   zTestCSD.test_real_onesided_evenc                 C   sb   t d}d|d< d|d< t||dd\}}t|t dd  t g d	}t||d
d
d d S r   )r%   r&   rH  r   r9   r   r)   r/   r/   r0   r:   U  r   zTestCSD.test_real_onesided_oddc                 C   s`   t d}d|d< d|d< t||ddd\}}t|tdd t g d}t||d	d	d
 d S r   )r%   r&   rH  r   r   r   r)   r/   r/   r0   r@   _  s   
zTestCSD.test_real_twosidedc                 C   sd   t d}d|d< d|d< t||ddd\}}t|t ddd t g d	}t||d
d
d d S r   rP  r)   r/   r/   r0   rF   i  s   
zTestCSD.test_real_spectrumc                 C   sf   t jdtd}d|d< d|d< t||dd\}}t|t ddd t g d	}t||d
d
d d S r   )r%   r&   rI   rH  r   r'   r   r)   r/   r/   r0   r   s     z"TestCSD.test_integer_onesided_evenc                 C   sf   t jdtd}d|d< d|d< t||dd\}}t|t dd	  t g d
}t||ddd d S r   )r%   r&   rI   rH  r   r9   r   r)   r/   r/   r0   r   }  rQ  z!TestCSD.test_integer_onesided_oddc                 C   sd   t jdtd}d|d< d|d< t||ddd\}}t|tdd t g d	}t||d
d
d d S r   )r%   r&   rI   rH  r   r   r   r)   r/   r/   r0   rL        zTestCSD.test_integer_twosidedc                 C   sd   t dt j}d|d< d|d< t||ddd\}}t|tdd t g d}t||d	d	d
 d S r   )r%   r&   rP   rH  r   r   r   r)   r/   r/   r0   rQ     rR  zTestCSD.test_complexc                 C   s,   t tttdtjtdtjddd d S r   )rT   rU   rH  r%   r&   rP   r(   rV   r/   r/   r0   rW     s   
zTestCSD.test_unk_scalingc                 C   s@   t jdt jdd }t||ddd\}}t|t |dd d S r   r%   r9   r`   rH  r   r   r   r/   r/   r0   r     s   zTestCSD.test_detrend_linearc                 C   s`   t jdt jdd }t||ddd\}}t||ddd d\}}t||dd	 t||dd	 d S )
Nr\   rG   r   Fr   c                 S   r   r   r/   r   r/   r/   r0   r     r   z,TestCSD.test_no_detrending.<locals>.<lambda>r6   r7   )r%   r9   r`   rH  r   r   r/   r/   r0   r     s
   zTestCSD.test_no_detrendingc                 C   sD   t jdt jdd }t||ddd d\}}t|t |dd d S )	Nr\   rG   r   c                 S   r   r   r   r   r/   r/   r0   r     r   z/TestCSD.test_detrend_external.<locals>.<lambda>r   r6   r7   rS  r   r/   r/   r0   r     s
   
zTestCSD.test_detrend_externalc                 C   sN   t jdt jdd }|d}t||ddd d\}}t|t |d	d
 d S )Nr   rG   r   r   r\   c                 S   r   r   r   r   r/   r/   r0   r     r   z5TestCSD.test_detrend_external_nd_m1.<locals>.<lambda>r   r6   r7   )r%   r9   r`   ra   rH  r   r   r   r/   r/   r0   r     s   

z#TestCSD.test_detrend_external_nd_m1c                 C   s^   t jdt jdd }|d}t |dd}t||dddd	 d
\}}t|t |dd d S )NrY   rG   r   rZ   r[   r   r\   c                 S   r   r   r   r   r/   r/   r0   r     r   z4TestCSD.test_detrend_external_nd_0.<locals>.<lambda>r   r6   r7   )r%   r9   r`   ra   r   rH  r   r   r   r/   r/   r0   r     s   


z"TestCSD.test_detrend_external_nd_0c                 C   s   t jdt jdd }|d}t||dd\}}t|jd t|ddd d f |d	dd d f d
d
d t|ddd d f |ddd d f dd\}}t|t jd d f |d	d d f d
d
d d S r   )	r%   r9   r`   ra   rH  r   rb   r   rc   rd   r/   r/   r0   rg     s   
,..zTestCSD.test_nd_axis_m1c                 C   s   t jdt jdd }|d}t||ddd\}}t|jd t|d d ddf |d d d	df d
d
d t|d d ddf |d d ddf dd\}}t||d d d	df d
d
d d S r   )r%   r9   r`   ra   rH  r   rb   r   rd   r/   r/   r0   rl     s   
,."zTestCSD.test_nd_axis_0c              	   C   s   t d}d|d< d|d< t||ddd\}}tdd}t||d|d d\}}t|| t|| t|jd t|jd tt	t||d|d	d tdd
}tt	t||d|d d d S )Nr   r   r   r#   r\   r   r   r   r   rm   )
r%   r&   rH  r
   rn   r   r   rb   rT   rU   ro   r/   r/   r0   rt     s"   





zTestCSD.test_window_externalc                 C   s   t g td\}}t|jd t|jd t tdg \}}t|jd t|jd dD ]}t t|t|\}}t|j| t|j| q.t tdtd\}}t|jd t|jd t tdtd\}}t|jd t|jd d S )Nr\   r}   r~   )r   r   )rH  r%   r&   r   rb   r   r(   r   r/   r/   r0   r     s    zTestCSD.test_empty_inputc                 C   s   dD ]}t t|t|dd\}}t|j| t|j| qt tdtddd\}}t|jd t|jd t tdtddd\}}t|jd t|jd d S )Nr   r   ri   )r\   r\   r   )r\   r   r   )r\   r   r   )rH  r%   r   r   rb   r&   r   r/   r/   r0   r     s   z#TestCSD.test_empty_input_other_axisc           
      C   s   t d}d|d< t #}d}|t| t||dd\}}t||ddd\}}W d    n1 s2w   Y  t||dd	\}}	t|| t||	 t|| t||	 d S r   )r%   r&   r   r   r   rH  r   r   r/   r/   r0   r     s   



zTestCSD.test_short_datac              
   C   sV   t tttdtddtg d t tttdtddtdd d S r   )	rT   rU   rH  r%   r&   r(   r   r9   ra   rV   r/   r/   r0   r     s   zTestCSD.test_window_long_or_ndc                 C   sL   t d}d|d d d< t||ddd\}}t g d}t||dd	 d S r  )r%   r&   rH  r   r   r)   r/   r/   r0   r    s
   
z TestCSD.test_nondefault_noverlapc              	   C   s&   t tttdtddddd d S r  )rT   rU   rH  r%   r&   r(   rV   r/   r/   r0   r
  &  s   zTestCSD.test_bad_noverlapc                 C   s$   t tttdtdddd d S r  )rT   rU   rH  r%   r(   r&   rV   r/   r/   r0   r  *  s   
zTestCSD.test_nfft_too_shortc                 C   sv   t dd}d|d< d|d< t||dd\}}t|t ddd t g d	d}t||d
d
d t|j|jk d S r  )r%   r&   rH  r   r'   r   r   rH   r)   r/   r/   r0   r   .     
z"TestCSD.test_real_onesided_even_32c                 C   sv   t dd}d|d< d|d< t||dd\}}t|t dd	  t g d
d}t||ddd t|j|jk d S r  )r%   r&   rH  r   r9   r   r   rH   r)   r/   r/   r0   r   9  rT  z!TestCSD.test_real_onesided_odd_32c                 C   st   t dd}d|d< d|d< t||ddd\}}t|tdd t g d	d}t||d
d
d t|j|jk d S r  r%   r&   rH  r   r   r   r   rH   r)   r/   r/   r0   r   D  s   
zTestCSD.test_real_twosided_32c                 C   s   t dd}d|d< d|d< t||ddd\}}t|tdd t g d	d
}t||ddd t|j|jkd|j d|j  d S r  rU  r)   r/   r/   r0   r   P  s   
zTestCSD.test_complex_32c                 C   s   t d}t d}d}t|dd |d d  }|d  d9  < t||d|d\}}t||d	|d\}}t|| t|| d
}t|dd |d d  }t||d|d\}}t||d	|d\}}t|| t|| d S r  )r%   r&   r(   r   rH  r   )r*   r+   rJ  rv   r,   r  r  r  r/   r/   r0   r  \  s   




zTestCSD.test_padded_freqsc                 C   s   t jd}| }t||dddd\}}t||dddd\}}t|| t||dddd\}}t||dddd\}}t|| d S )Nr  r#   meanF)r   rC  r<   rB  )r%   r5  r7  copyrH  r   )r*   r+   rJ  r  p_samep_copiedr/   r/   r0   test_copied_datao  s    








zTestCSD.test_copied_dataN)#r   r   r   rM  rO  r1   r:   r@   rF   r   r   rL   rQ   rW   r   r   r   r   r   rg   rl   rt   r   r   r   r   r  r
  r  r   r   r   r   r  rZ  r/   r/   r/   r0   rF  4  sB    







		rF  c                   @   s   e Zd Zdd Zdd ZdS )TestCoherencec                 C   sX   t jd}t |}t ddd}t d}t||dd\}}t|| t|| d S NrY   r   r   r^   r\   r   )r%   r5  r7  rW  r'   r(   r   r   r*   r+   rJ  r,   Cr   C1r/   r/   r0   test_identical_input  s   


z"TestCoherence.test_identical_inputc                 C   sT   t jd}| }t ddd}t d}t||dd\}}t|| t|| d S r\  )r%   r5  r7  r'   r(   r   r   r]  r/   r/   r0   test_phase_shifted_input  s   

z&TestCoherence.test_phase_shifted_inputN)r   r   r   r`  ra  r/   r/   r/   r0   r[    s    r[  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestSpectrogramc                 C   sh   t jd}d}d}d}d}t|||||\}}}t|||||\}	}
t||	 tt j|dd|
 d S )Nr2  r=   r!  g      ?r   r[   r!   ri   )r%   r5  r7  r   r   r   rV  )r*   r+   r$  r   r   r  r,   r  PfwPwr/   r/   r0   test_average_all_segments  s   
z)TestSpectrogram.test_average_all_segmentsc                 C   s   t jd}d}d}d}d}t|||||\}}}tdd}	t|||	d dd\}
}}t|
jd t|jd tt	t|||	d	d
 tdd}tt	t|||d d
 d S )Nr2  r=   rc  r   r[   r  )r    )r    I   r#   r   i   )
r%   r5  r7  r   r
   rn   r   rb   rT   rU   )r*   r+   r$  r   r   r  r,   r  rd  rp   rq   Pers   r/   r/   r0   rt     s"   
z$TestSpectrogram.test_window_externalc                 C   s   t jd}d}t||dd\}}}t }|td t||ddd\}}}W d    n1 s1w   Y  t||dd	\}	}}
t||dd	\}}}t||	 t||
 t|| t|| d S )
Nr2  r=   rc  r   zInperseg = 1025 is greater than input length  = 1024, using nperseg = 1024i  r   r   r   )r%   r5  r7  r   r   r   r   r   )r*   r+   r$  r,   r  r-   r   r   r   r   r   f3p3r/   r/   r0   r     s"   


zTestSpectrogram.test_short_dataN)r   r   r   rg  rt   r   r/   r/   r/   r0   rb    s    rb  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 )TestLombscarglec                 C   s   d}d}dt j }d}d}d}t jd t j|}t dt j d	t j |||k }|t || |  }	t dd	|}
t||	|
}|
d
 |
d  }t||
t 	|  |d k  dS )zgTest if frequency location of peak corresponds to frequency of
        generated input signal.
        r"   r=   r   d     ffffff?# {Gz?      $@r   r   N)
r%   r'  r5  r6  randr'   r&  r   r   argmax)r*   amplwphininnoutr-   rtr+   r,   rd  deltar/   r/   r0   test_frequency  s   
""zTestLombscargle.test_frequencyc                 C   s   d}d}dt j }d}d}d}t jd t j|}t dt j d	t j |||k }|t || |  }	t dd	|}
t||	|
}t d
| |j	d  }t
t ||dd d S )Nr"   r=   r   rm  rn  ro  rp  rq  rr  rR   r   r[   significant)r%   r'  r5  r6  rs  r'   r&  r   r(  rb   r   max)r*   ru  rv  rw  rx  ry  r-   rz  r{  r+   r,   pgramr/   r/   r0   test_amplitude  s   
"zTestLombscargle.test_amplitudec                 C   s   d}d}dt j }d}d}d}d}t jd t j|}t d	t j d
t j |||k }	|t ||	 |  | }
t d	d
|}t|	|
|dd}t|	|
|
  |dd}t	|| d S )Nr"   r=   r   rm  rn  ro  g333333?rp  rq  rr  T)	precenterF)
r%   r'  r5  r6  rs  r'   r&  r   rV  r   )r*   ru  rv  rw  rx  ry  r-   offsetrz  r{  r+   r,   r  pgram2r/   r/   r0   test_precenter  s   
"zTestLombscargle.test_precenterc                 C   s   d}d}dt j }d}d}d}t jd t j|}t dt j d	t j |||k }|t || |  }	t dd	|}
t||	|
}t||	|
d
d}t|d t 	|	|	 | t
t |ddd d S )Nr"   r=   r   rm  rn  ro  rp  rq  rr  T)	normalizer[   r~  )r%   r'  r5  r6  rs  r'   r&  r   r   dotr   r  )r*   ru  rv  rw  rx  ry  r-   rz  r{  r+   r,   r  r  r/   r/   r0   test_normalize-  s   
"zTestLombscargle.test_normalizec                 C   s>   t ddd}t ddd}t ddd}ttt||| d S )Nr   r   r[   r   )r%   r'   rT   rU   r   r*   r{  r+   r,   r/   r/   r0   test_wrong_shapeK  s   z TestLombscargle.test_wrong_shapec                 C   s2   t d}t d}t d}ttt||| d S )Nr   )r%   r&   rT   ZeroDivisionErrorr   r  r/   r/   r0   test_zero_divisionQ  s   


z"TestLombscargle.test_zero_divisionc                 C   sP   t jddddd}t d| }t jdddddd	 }t|||d
 t j  d S )Nr   r\   rn  F)endpointrR   2   i  r"  r[   )r%   r'   r&  r   r'  r  r/   r/   r0   test_lombscargle_atan_vs_atan2W  s   z.TestLombscargle.test_lombscargle_atan_vs_atan2N)
r   r   r   r}  r  r  r  r  r  r  r/   r/   r/   r0   rl    s     !rl  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
dddgdd Zdd Zdd Zdd Zej	
dddgdd Zdd Zdd Zdd Zdd Zd d! Zd"S )#TestSTFTc                 C   s2  dd }|d t ddd W d    n1 sw   Y  |d t ddd	 W d    n1 s3w   Y  |d
 t tddd W d    n1 sPw   Y  |d t td	dd W d    n1 smw   Y  |d tddd W d    n1 sw   Y  |d tddd	 W d    n1 sw   Y  |d
 ttddd W d    n1 sw   Y  |d ttd	dd W d    n1 sw   Y  |d tddd W d    n1 sw   Y  td}t|d }|d
 t|tdd W d    n	1 sw   Y  |d t|tddd W d    n	1 s=w   Y  |d t|dd W d    n	1 sXw   Y  |d t|ddd W d    n	1 stw   Y  |d t|ddd W d    n	1 sw   Y  |d t| W d    n	1 sw   Y  |d
 t|tdd W d    n	1 sw   Y  |d t|tddd W d    n	1 sw   Y  |d t|dd W d    n	1 sw   Y  |d t|ddd W d    n	1 sw   Y  |d t|ddd W d    n	1 s9w   Y  tjt	dd  t|dddd! W d    n	1 sYw   Y  |d" t|ddd# W d    n	1 suw   Y  |d$ t
||d%d& W d    n	1 sw   Y  |d' t
|d d( |d(d  d)d& W d    n	1 sw   Y  |d* t
||d%d+ W d    n	1 sw   Y  d,}|d-|d. t||d/ W d    n	1 sw   Y  |d-|d. t||d/ W d    d S 1 sw   Y  d S )0Nc                 S   s   t jt| dS )zAssert for a ValueError matching regexp `match`.

            This little wrapper allows a more concise code layout.
            r   )r   r	   rU   r   r/   r/   r0   chk_VEc  s   z.TestSTFT.test_input_validation.<locals>.chk_VEz"nperseg must be a positive integerr   ir   z#noverlap must be less than nperseg.r\   rY   zwindow must be 1-D)r[   r[   z"window must have length of npersegz"noverlap must be less than npersegz&noverlap must be a nonnegative integerr  ir2  r[   r   z>value specified for nperseg is different from length of windowr   r   i r   r  z.nfft must be greater than or equal to nperseg.r#   r  zInput stft must be at least 2d!zwindow must have length of 256z1NOLA condition failed, STFT may not be invertibler   r   r  r   z/Must specify differing time and frequency axes!	time_axis	freq_axisz=Unknown value for mode foo, must be one of: \{'psd', 'stft'\}rS   )modez'x and y must be equal if mode is 'stft'   stftz[Unknown boundary option 'foo', must be one of: \['even', 'odd', 'constant', 'zeros', None\])boundary	not_validzParameter scaling=z not in \['spectrum', 'psd'\]!rB   )r   r%   r(   r   r&   r  istftr   warnsr   r   )r*   r  r+   zrC   r/   r/   r0   test_input_validationa  s   
























 
$zTestSTFT.test_input_validationc                 C   s2   g d}|D ]}dj | }tdt| |d qd S )N)boxcarr\   r   r  r\   r    r   3      r   r      r   r      blackmanr     r!  r   r   r  r   r      
{}, {}, {}Tr3  )formatr   r   )r*   settingssettingr   r/   r/   r0   test_check_COLA  s
   
zTestSTFT.test_check_COLAc                 C   s   g d}|D ]}dj | }tdt| |d qtd}d|d d d< |t|t|d fdg}|D ]}dj | }td	t| |d q2d S )
N)r  r  )r  r\   r	  r  )r   r  r\   r  r  )r   r   %   r  )r  r  {   r  )r  r   &   r  )r   r   '   r  Tr3  r   r   r[   )r   r  r   F)r  r   r   r%   r(   len)r*   settings_passr  r   w_failsettings_failr/   r/   r0   test_check_NOLA  s   


zTestSTFT.test_check_NOLAc              
   C   s   t jd t jd}d}d}d}d}t|||||ddd d\}}}t|||||dd	dd
\}	}
t||	 tt jt |d dd|
 d S )Nr1  r2  r=   r   r   r#   F)paddedr<   r  rA   )r<   rC   r   r[   r!   ri   )	r%   r5  r6  r7  r  r   r   rV  abs)r*   r+   r$  r   r   r  r,   r  Zre  rf  r/   r/   r0   rg    s   

"z"TestSTFT.test_average_all_segmentsc              	   C   s   t jd t jd}d}d}d}d}t|||||\}}}t|d||||dd	\}	}
}t|||||\}}t|j||||dd
d\}}t||	 t||
 t|| t||d d ddd d f  t||d d ddf  d S )Nr1  r2  r=   r   r   r#   )r!   r   r   r   ri   r!   r  )	r%   r5  r6  r7  r  ra   r  Tr   )r*   r+   r$  r   r   r  r   t1Z1r   t2Z2t3x1t4x2r/   r/   r0   test_permute_axes  s&   



zTestSTFT.test_permute_axesrC   rA   psdc              
   C   s   t jd g d}|D ]B\}}}}t |}dt j|j }t||||d d|d\}	}	}
t|
||||d\}}| d| }t|||d t|||d qd S )	Nr1  r  rm  r\   r   r  rm  r\   r    )r   e   r  r  r   r2  r   r  )r    r   r  )r   r2  r   r  r\   F)r   r  r   r   r  rC   )r   r  r   rC   r  r3  	r%   r5  r6  r9   r7  sizer  r  r   )r*   rC   r  r   Nr   r  r{  r+   r  zztrxrr   r/   r/   r0   test_roundtrip_real  s    	

zTestSTFT.test_roundtrip_realc              
   C   s@  t jd t d}d|d d d< |dt|t|d fdg}|D ]{\}}}}| d| d| d| }t|||r?J |t |}dt j|j }	t	|	|||d d	d
d\}
}
}t
jtdd t||||d	d\}}W d    n1 sxw   Y  t ||d t| sJ |t |	|d t|	 rJ |q"d S )Nr1  r   r   r[   r   )r   r   r  r   r  r\   Tr&   r   r  r   r   r  r  NOLAr   r   r  r   r  )r%   r5  r6  r(   r  r   r9   r7  r  r  r   r  r   r  allclose)r*   r  r  r   r  r   r  r   r{  r+   r  r  r  r  r/   r/   r0   test_roundtrip_not_nola)  s.   

 "z TestSTFT.test_roundtrip_not_nolac              
   C   s   t jd g d}|D ]l\}}}}| d| d| }t|||s&J |t|||r0J |t |}dt j|j }t||||d ddd\}	}	}
t	|
|||dd\}}| d| }t
||d t| |d	 t
||d t| |d	 qd S )
Nr1  ))r  rm  r\   r   )r   r  r  r  )r   r2  r      )r  r  r      )r   r2  r   r   r  r\   Tr&   r  r  r3  )r%   r5  r6  r   r   r9   r7  r  r  r  r   r  )r*   r  r   r  r   r  r   r{  r+   r  r  r  r  r/   r/   r0   test_roundtrip_nola_not_colaD  s&   

z%TestSTFT.test_roundtrip_nola_not_colac              	   C   s   t jd dg}|D ]P\}}}}t |}dt j|j }|t j}t||||d dd\}}}	t	|	|||d\}
}| d| }t
|||d t
|||d	d
d t|j|jk qd S )Nr1  r  r\   Fr   r  r   r   r  r  r  r3  g-C6?gh㈵>)r4  r   r8   )r%   r5  r6  r9   r7  r  astypefloat32r  r  r   r   rH   r*   r  r   r  r   r  r{  r+   r  r  r  r  r   r/   r/   r0   test_roundtrip_float32b  s"   

zTestSTFT.test_roundtrip_float32c                 C   sV  t jd g d}|D ]P\}}}}t |}dt j|j dt j|j  }t||||d dd|d\}	}	}
t|
|||d|d\}}| d| d| }t|||d	 t|||d	 qt	 }|
td
 t||||d dd|d\}	}	}
W d    n1 sw   Y  t|
|||d|d\}}| d| d| }t|||d	 t|||d	 d S )Nr1  r  r\   y              $@F)r   r  r   r   r  r<   rC   )r   r  r   input_onesidedrC   r  r3  z9Input data is complex, switching to return_onesided=FalseT)r%   r5  r6  r9   r7  r  r  r  r   r   r   r   )r*   rC   r  r   r  r   r  r{  r+   r  r  r  r  r   r   r/   r/   r0   test_roundtrip_complexw  s>   	
$

zTestSTFT.test_roundtrip_complexc                 C   s   t jd ddg}|D ]a\}}}}t |}dt j|j }t||||d dd d\}}}	t|	||dd\}}
d	D ]2}t||||d d|d\}}}t|||dd\}}| d
| d
| }t||
|d t|||d q:qd S )Nr1  r  r  r\   Tr  F)r  r   r  )evenoddconstantr&   r  r3  r  )r*   r  r   r  r   r  r{  r+   r  r  r  r  zz_extxr_extr   r/   r/   r0   !test_roundtrip_boundary_extension  s2   

z*TestSTFT.test_roundtrip_boundary_extensionc              	   C   s   t jd ddg}|D ]I\}}}}t |}dt j|j }t||||d dd\}}}	t|	||d\}
}| d| }t||
d |j |d	 t||d |j |d	 qd S )
Nr1  )r  r  r\   r   )r   rn  r   r  r\   Tr  )r  r   r  r3  r  r  r/   r/   r0   test_roundtrip_padded_signal  s   
z%TestSTFT.test_roundtrip_padded_signalc                 C   s   t jd g d}|D ]q\}}}}}t |}dt j|j }|t dt j d  }	t|||||d dd\}
}
}t|	||||d ddd	\}
}
}t	|||||d
\}}t	|||||dd\}}| d| }t
|||d t
|||d t
|	||d qd S )Nr1  ))r   r2  r   r  r  )r   r2  r   r  i  )r  rm  r\   r   !   )r  r  r   r  r2  r\   y              ?rR   T)r   r  rv   r   r   r  F)r   r  rv   r   r   r  r<   )r   r  rv   r   )r   r  rv   r   r  r  r3  )r%   r5  r6  r9   r7  r  expr'  r  r  r   )r*   r  r   r  r   r  rv   r{  r+   xcr  r  zcr  r  xcrr   r/   r/   r0   test_roundtrip_padded_FFT  s0   






z"TestSTFT.test_roundtrip_padded_FFTc                 C   s   t jd t jd}t|\}}}tdD ]:}dgd }d||< ||}t||d\}}}t|||j d\}}}t||	 |d t||	 ||j d qt
|jddd	\}}	t
|jd
dd	\}}
t||	dd t||
dd d S )Nr1  r2  r   r   r!   ri   r3  r  r   zistft transpose minuszistft transpose plus)r%   r5  r6  r7  r  r8  ra   r9  r   r:  r  r  r   )r*   r;  r  z_flatr=  r>  r+   z_plusz_minusx_transpose_mx_transpose_pr/   r/   r0   rA    s   

zTestSTFT.test_axis_rollingc                 C   s6  t jdtd}d|d< t j|}t|d t| }t|dddd }t|d	ddd
 }t	|| t	t
|dddf d t	t
|dddf d
 t	t
|dddf d d|ddddf< t	|ddddf dt |jjd t|ddddd }t j|jd |jd  dd|jd  }t	|| t|dd	ddd
 }t	|| t|d	dddd }t |dddddf }	t	|ddddf | t	|ddddf |	 t j|jd |jd  ddt j|	jd |	jd  dd }
|
|jd |	jd   }t	|| t|d	d	ddd
 }t	|| dS )z&Verify behavior of scaling parameter. i  rG   r2  r   r[   r  rA   )r  rC   Tr   ?   Nr!   r   r  A   r   B   r7   Fr  )r<   r  rC   ri   )r  r  rC   r     )r%   r&   complexr   r   sumr  r  r  r   r  finforH   
resolutionrealimagrb   conj)r*   Xr+   power_xZsr  Zppsd_ZpZp0Zp1s2psd_Zp01r/   r/   r0   test_roundtrip_scaling  s8   
((


zTestSTFT.test_roundtrip_scalingN)r   r   r   r  r  r  rg  r  r   r   parametrizer  r  r  r  r  r  r  r  rA  r  r/   r/   r/   r0   r  `  s$    R

+!#r  c                   @   s   e Zd ZU dZdZeed< dZeed< dZ	eed< dZ
eed< ejed	< ejed
< eed< eed< dd ZedefddZedefddZdd Zdd ZdS )"TestSampledSpectralRepresentationsa  Check energy/power relations from `Spectral Analysis` section in the user guide.

    A 32 sample cosine signal is used to compare the numerical to the expected results
    stated in :ref:`tutorial_SpectralAnalysis` in
    file ``doc/source/tutorial/signal.rst``
    rm   nr>   r  r   a_refl_ax_refX_refE_refP_refc                 C   st   t | j| j}t|}d| _| jd | j || j< t|| _t	| j| _
| j| jd  d | _| jd d | _dS )z5Create Cosine signal with amplitude a from spectrum. r   r[   N)r   r  r  r%   r   r  r  r   r  r   r  taur  r  )r*   r,   r  r/   r/   r0   setup_methodj  s   

z/TestSampledSpectralRepresentations.setup_methodreturnc                 C   s   | j | j S )zDuration of signal. r  r  rV   r/   r/   r0   r  w  s   z&TestSampledSpectralRepresentations.tauc                 C   s   d| j | j  S )z
Bin width r   r  rV   r/   r/   r0   delta_f|  s   z*TestSampledSpectralRepresentations.delta_fc                 C   s   t d| j t| jdd t | jt| jd  | j t| jj	d | jj
d  }t | j| j | | j t d| jd  | | j dS )z Test energy and power formulas. r[   r"  r%  r   N)r   r  r%   ptpr  r  r  r  r  r  r  r  r  )r*   sum_X_ref_squaredr/   r/   r0   test_reference_signal  s
   z8TestSampledSpectralRepresentations.test_reference_signalc                 C   s  t | jdd}tt|tt|jd |jd  }}t| j	| }t
| j|| j  | | j| j d  t
|| j | | jd  | j| j t|| d  }| jt|| d  }t
| jt| | j t
| jt| | j td| j |ddd}t| j	fddi|\}}	t| j	fddi|\}}
t|	jj}t
|	t|| d |t|	 d	 t
|
||t|
 d	 tdt| j	d
d|}t
t| j	fddi|d |	|t|	 d	 t
t| j	fddi|d |
|t|
 d	 dS )zVerify spectral representations of windowed DFT.

        Furthermore, the scalings of `periodogram` and `welch` are verified.
        F)symr[   r   )r$  r   r   r<   rC   rA   rD   r7   r   r  Nr/   )r   r  r  r  r%   r(  r  r  r   r  r   r  r  r  r  r  r  r  dictr   r  rH   r  r  r  r   )r*   rv  c_ampc_rmsXwX_ESDX_PSDkwr  P_magP_psd	float_resr/   r/   r0   test_windowed_DFT  s,   ,&"


z4TestSampledSpectralRepresentations.test_windowed_DFTN)r   r   r   __doc__r  rI   __annotations__r  floatr  r  r%   ndarrayr  propertyr  r  r!  r-  r/   r/   r/   r0   r  Y  s"   
 

r  )2r   numpyr%   numpy.testingr   r   r   r   r   r   r   r   r	   rT   scipyr
   	scipy.fftr   r   r   r   scipy.integrater   scipy.signalr   r   r   r   r   r   r   scipy.signal.windowsr   scipy.signal._spectral_pyr   ,scipy.signal.tests._scipy_spectral_test_shimr   r  r   r  r   rH  r   r   rF  r[  rb  rl  r  r  r/   r/   r/   r0   <module>   s>    $$ ^  A  N5    |