8000 Documentation: A possible mistake in the STFT formula · Issue #153531 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Documentation: A possible mistake in the STFT formula #153531

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

Open
yn- opened this issue May 14, 2025 · 0 comments
Open

Documentation: A possible mistake in the STFT formula #153531

yn- opened this issue May 14, 2025 · 0 comments
Labels
module: docs Related to our documentation, both in docs/ and docblocks module: fft triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@yn-
Copy link
yn- commented May 14, 2025

📚 The doc issue

In the stft documentation, the formula is given as follows:

pytorch/torch/functional.py

Lines 598 to 601 in 1341794

.. math::
X[\omega, m] = \sum_{k = 0}^{\text{win\_length-1}}%
\text{window}[k]\ \text{input}[m \times \text{hop\_length} + k]\ %
\exp\left(- j \frac{2 \pi \cdot \omega k}{\text{n\_fft}}\right),

$$X[\omega, m] = \sum_{k = 0}^{\text{win}\textunderscore\text{length-1}}% \text{window}[k]\ \text{input}[m \times \text{hop}\textunderscore\text{length} + k]\ % \exp\left(- j \frac{2 \pi \cdot \omega k}{\text{n}\textunderscore\text{fft}}\right),$$

The denominator in the exponent is n_fft. Is that a mistake? I would expect the window length here rather than the number of frequency samples. I cannot find the actual implementation by a quick lookaround, so I have not checked what is done by the code.

Apart from the above, a minor issue is that the '- 1' on top of the sum sign should be outside of the \text macro.

Suggest a potential alternative/fix

Change the denominator to win_length, and leave '-1' in math mode.

     .. math:: 
         X[\omega, m] = \sum_{k = 0}^{\text{win\_length}-1}% 
                             \text{window}[k]\ \text{input}[m \times \text{hop\_length} + k]\ % 
                             \exp\left(- j \frac{2 \pi \cdot \omega k}{\text{win\_length}}\right), 

$$X[\omega, m] = \sum_{k = 0}^{\text{win}\textunderscore\text{length}-1}% \text{window}[k]\ \text{input}[m \times \text{hop}\textunderscore\text{length} + k]\ % \exp\left(- j \frac{2 \pi \cdot \omega k}{\text{win}\textunderscore\text{length}}\right),$$

cc @svekars @sekyondaMeta @AlannaBurke @mruberry

@yn- yn- changed the title A possible mistake in the STFT formula Documentation: A possible mistake in the STFT formula May 14, 2025
@soulitzer soulitzer added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: fft module: docs Related to our documentation, both in docs/ and docblocks labels May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: docs Related to our documentation, both in docs/ and docblocks module: fft triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants
0