@@ -615,7 +615,7 @@ def test_psd_window_hanning(self):
615
615
noverlap = 0 ,
616
616
sides = self .sides ,
617
617
window = mlab .window_none )
618
- spec_c *= len (ycontrol1 )/ (np . abs ( windowVals ) ** 2 ).sum ()
618
+ spec_c *= len (ycontrol1 )/ (windowVals ** 2 ).sum ()
619
619
assert_array_equal (fsp_g , fsp_c )
620
620
assert_array_equal (fsp_b , fsp_c )
621
621
assert_allclose (spec_g , spec_c , atol = 1e-08 )
@@ -662,14 +662,41 @@ def test_psd_window_hanning_detrend_linear(self):
662
662
noverlap = 0 ,
663
663
sides = self .sides ,
664
664
window = mlab .window_none )
665
- spec_c *= len (ycontrol1 )/ (np . abs ( windowVals ) ** 2 ).sum ()
665
+ spec_c *= len (ycontrol1 )/ (windowVals ** 2 ).sum ()
666
666
assert_array_equal (fsp_g , fsp_c )
667
667
assert_array_equal (fsp_b , fsp_c )
668
668
assert_allclose (spec_g , spec_c , atol = 1e-08 )
669
669
# these should not be almost equal
670
670
with pytest .raises (AssertionError ):
671
671
assert_allclose (spec_b , spec_c , atol = 1e-08 )
672
672
673
+ def test_psd_window_flattop (self ):
674
+ # flattop window
675
+ # adaption from https://github.com/scipy/scipy/blob\
676
+ # /v1.10.0/scipy/signal/windows/_windows.py#L562-L622
677
+ a = [0.21557895 , 0.41663158 , 0.277263158 , 0.083578947 , 0.006947368 ]
678
+ fac = np .linspace (- np .pi , np .pi , self .NFFT_density_real )
679
+ win = np .zeros (self .NFFT_density_real )
680
+ for k in range (len (a )):
681
+ win += a [k ] * np .cos (k * fac )
682
+
683
+ spec , fsp = mlab .psd (x = self .y ,
684
+ NFFT = self .NFFT_density ,
685
+ Fs = self .Fs ,
686
+ noverlap = 0 ,
687
+ sides = self .sides ,
688
+ window = win ,
689
+ scale_by_freq = False )
690
+ spec_a , fsp_a = mlab .psd (x = self .y ,
691
+ NFFT = self .NFFT_density ,
692
+ Fs = self .Fs ,
693
+ noverlap = 0 ,
694
+ sides = self .sides ,
695
+ window = win )
696
+ assert_allclose (spec * win .sum ()** 2 ,
697
+ spec_a * self .Fs * (win ** 2 ).sum (),
698
+ atol = 1e-08 )
699
+
673
700
def test_psd_windowarray (self ):
674
701
freqs = self .freqs_density
675
702
spec , fsp = mlab .psd (x = self .y ,
0 commit comments