10000 Documentation: explaining the STFT formula · Issue #153531 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Documentation: explaining the STFT formula #153531
@yn-

Description

@yn-

📚 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: docsRelated to our documentation, both in docs/ and docblocksmodule: ffttriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0