Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: signal.ShortTimeFFT: determine arbitrary dual windows #20610

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

DietBru
Copy link
Contributor

@DietBru DietBru commented Apr 29, 2024

The ShortTimeFFT can only calculate the canonical dual window (which is utilized in the istft).

This PR provides a new function closest_STFT_dual_window to calculate the closest dual window in a least-squares sense for a given desired window as well as a new method ShortTimeFFT.from_win_equals_dual to determine windows which are equal to their dual window.

The Constant OverLap Add (COLA) constraint is equivalent of having a constant dual window, i.e., all(ShortTimeFFT.dual_win == ShortTimeFFT.dual_win[0]). Hence, closest_STFT_dual_window() is a generalization of check_COLA, which is deprecated in this PR.

Closes #20608 by adding 'math:numref' to the white list in refguide_check.py.

Further minor changes:

  • In _calc_dual_canonical_window(Fixed edgde case i) fixed edge case for catching invalid zero-valued win.
  • Allow np.int for hop parameters.
  • Removed minor typos and reference for STFT applications
  • Fixed a linter error in_spectral_helper()

Update: The rendered documentation can be found here:

Update: Closes #20622 by adding additional documentation.

@github-actions github-actions bot added scipy.signal Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org enhancement A new feature or improvement labels Apr 29, 2024
Provide a new function `closest_STFT_dual_window()` to calculate the closest dual window in a least-squares sense for a given desired window as well as a new method `ShortTimeFFT.from_win_equals_dual()` to determine windows which are equal to their dual window.
@j-bowhay
Copy link
Member

j-bowhay commented May 5, 2024

@sancholp would you be interested in reviewing this?

@sancholp
Copy link

sancholp commented May 6, 2024

@j-bowhay yes, I'll take a look

Copy link

@sancholp sancholp left a comment

Choose a reason for hiding this comment

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

The documentation changes are fine. Maybe somewhere you could explain that the csd spectrogram can also be used to create a coherence spectrogram.

@DietBru
Copy link
Contributor Author

DietBru commented May 10, 2024

Thanks for looking this, @sancholp. I added a few words explaining a coherence spectrogram in the last commit.

On an unrelated side note: The Wikipedia definition of the squared coherency spectrum you cited cannot be extended into a time-frequency version of a spectrogram. The reason being that the definition is based on wide-sense stationary stochastic processes for which time-frequency analysis (as opposed to spectral analysis) is not useful.
It makes more sense to interpret it as a normalized time-frequency cross-correlation function.

@DietBru
Copy link
Contributor Author

DietBru commented May 10, 2024

The test failure seems to be unrelated.

Update: The rendered documentation can be found here:

@lucascolley lucascolley changed the title ENH: Determine arbitrary dual windows for short-time Fourier Transform ENH: signal.ShortTimeFFT: determine arbitrary dual windows May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org enhancement A new feature or improvement scipy.signal
Projects
None yet
3 participants