Title: [Bug]: Windows correction is not correct in `mlab._spectral_helper` · Issue #24821 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Windows correction is not correct in `mlab._spectral_helper` · Issue #24821 · matplotlib/matplotlib
X Title: [Bug]: Windows correction is not correct in `mlab._spectral_helper` · Issue #24821 · matplotlib/matplotlib
Description: Bug summary Windows correction is not correct in mlab._spectral_helper: matplotlib/lib/matplotlib/mlab.py Lines 423 to 430 in 3418bad if scale_by_freq: result /= Fs # Scale the spectrum by the norm of the window to compensate for # windo...
Open Graph Description: Bug summary Windows correction is not correct in mlab._spectral_helper: matplotlib/lib/matplotlib/mlab.py Lines 423 to 430 in 3418bad if scale_by_freq: result /= Fs # Scale the spectrum by the norm...
X Description: Bug summary Windows correction is not correct in mlab._spectral_helper: matplotlib/lib/matplotlib/mlab.py Lines 423 to 430 in 3418bad if scale_by_freq: result /= Fs # Scale the spectrum by the norm...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24821
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Windows correction is not correct in `mlab._spectral_helper`","articleBody":"### Bug summary\r\n\r\nWindows correction is not correct in `mlab._spectral_helper`:\r\nhttps://github.com/matplotlib/matplotlib/blob/3418bada1c1f44da1f73916c5603e3ae79fe58c1/lib/matplotlib/mlab.py#L423-L430\r\n\r\nThe `np.abs` is not needed, and give wrong result for window with negative value, such as `flattop`.\r\nFor reference, the implementation of scipy can be found here :\r\nhttps://github.com/scipy/scipy/blob/d9f75db82fdffef06187c9d8d2f0f5b36c7a791b/scipy/signal/_spectral_py.py#L1854-L1859\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport numpy as np\r\nfrom scipy import signal\r\nwindow = signal.windows.flattop(512)\r\nprint(np.abs(window).sum()**2-window.sum()**2)\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n4372.942556173262\r\n\r\n### Expected outcome\r\n\r\n0\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\n_No response_\r\n\r\n### Matplotlib Version\r\n\r\nlatest\r\n\r\n### Matplotlib Backend\r\n\r\n_No response_\r\n\r\n### Python version\r\n\r\n_No response_\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\nNone","author":{"url":"https://github.com/gapplef","@type":"Person","name":"gapplef"},"datePublished":"2022-12-27T04:17:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/24821/matplotlib/issues/24821"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:410562b2-5274-bf61-5581-9f63929c5586 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C24:3FA248:BE7942:C1F4B7:6A5127E9 |
| html-safe-nonce | ec98c6a05e49655cccab360fd3c467a0f895805b0a07383ca1d36851c38d97a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzI0OjNGQTI0ODpCRTc5NDI6QzFGNEI3OjZBNTEyN0U5IiwidmlzaXRvcl9pZCI6IjQ2ODg3MTcxMDkwNjgzNzYwNDEiLCJyZWdpb25fZWRnZSI6InNlYSIsInJlZ2lvbl9yZW5kZXIiOiJzZWEifQ== |
| visitor-hmac | 79bfcaa82892c40c7468e30965204512cb0d864ccba0c4e36291c4a592b446eb |
| hovercard-subject-tag | issue:1511418865 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/24821/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6ab5e41b8e9ccce74824480da95a79a98a1d68985c1794ca6f3da29a085bb95d/matplotlib/matplotlib/issues/24821 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6ab5e41b8e9ccce74824480da95a79a98a1d68985c1794ca6f3da29a085bb95d/matplotlib/matplotlib/issues/24821 |
| og:image:alt | Bug summary Windows correction is not correct in mlab._spectral_helper: matplotlib/lib/matplotlib/mlab.py Lines 423 to 430 in 3418bad if scale_by_freq: result /= Fs # Scale the spectrum by the norm... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gapplef |
| hostname | github.com |
| expected-hostname | github.com |
| None | 689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 942b51ed3bd5feee3d5e2719f890a5fe286edbbb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width