Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bugfix: scaling of windows with negative coefficients
For proper scaling of the magnitude a division by the sum
of all window elements is needed.
To be able to handle complex window coefficients an abs()
was introduced in a622508
which falsifies the scaling for windows with negative
coefficients. Most prominently the flattop window.

A proper type check is introduced to handle both cases
correctly.
  • Loading branch information
LucasIsOnline
LucasIsOnline committed Apr 11, 2022
commit 7b2d4aff01358f9eeca6ac541dcb4b39f15bd706
6 changes: 5 additions & 1 deletion lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
elif mode == 'psd':
result = np.conj(result) * result
elif mode == 'magnitude':
result = np.abs(result) / np.abs(window).sum()
result = np.abs(result)
if np.iscomplexobj(window):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to check for complex windows here.

result /= np.abs(window).sum()
else:
result /= np.asarray(window).sum()
elif mode == 'angle' or mode == 'phase':
# we unwrap the phase later to handle the onesided vs. twosided case
result = np.angle(result)
Expand Down