#NEWLINE# def test_multitaper_spectral_normalization( ) : #NEWLINE# #INDENT# '\n    Check that the spectral estimators are normalized in the\n    correct Watts/Hz fashion\n    ' #NEWLINE# x = np . random . randn ( 1024 ) #NEWLINE# ( f1 , Xp1 , _ ) = tsa . multi_taper_psd ( x ) #NEWLINE# ( f2 , Xp2 , _ ) = tsa . multi_taper_psd ( x , Fs = 100 ) #NEWLINE# ( f3 , Xp3 , _ ) = tsa . multi_taper_psd ( x , NFFT = ( 2 ** 12 ) ) #NEWLINE# p1 = ( ( ( np . sum ( Xp1 ) * 2 ) * np . pi ) / ( 2 ** 10 ) ) #NEWLINE# p2 = ( ( np . sum ( f2 ) * 100 ) / ( 2 ** 10 ) ) #NEWLINE# p3 = ( ( ( np . sum ( Xp3 ) * 2 ) * np . pi ) / ( 2 ** 12 ) ) #NEWLINE# nt . assert_true ( ( np . abs ( ( p1 - p2 ) ) < 1e-14 ) , 'Inconsistent frequency normalization in MTM PSD (1)' ) #NEWLINE# nt . assert_true ( ( np . abs ( ( p3 - p2 ) ) < 1e-08 ) , 'Inconsistent frequency normalization in MTM PSD (2)' ) #NEWLINE# td_var = np . var ( x ) #NEWLINE# nt . assert_true ( ( np . abs ( np . log10 ( ( p1 / td_var ) ) ) < 1 ) , 'Incorrect frequency normalization in MTM PSD' ) #NEWLINE# nt . assert_true ( ( f2 . max ( ) == 50 ) , 'MTM PSD returns wrong frequency bins' )