#12359·audacity

Optimize reassigned spectrogram for Gaussian windows: reduce 3 FFTs to 2

Author: racociCreated Sep 30, 2026Updated Sep 30, 2026
LabelsEnhancement Request

Problem to be solved

The current reassigned spectrogram implementation performs three FFTs per analysis frame: one using the analysis window, one using its derivative, and one using the time-weighted window $ h(t) $. For the Gaussian windows already supported by Audacity, these two auxiliary windows are analytically related by $ t h(t) = -\sigma^2 h'(t) $. Computing both therefore performs redundant work and increases the cost of reassignment unnecessarily.

Your idea

Add a Gaussian-specific reassignment path that computes only the FFT of the Gaussian window and the FFT of its derivative. The time-reassignment correction can then be obtained from the same complex ratio used for frequency reassignment, using &t h(t) = -\sigma^2 h'(t)$, reducing the FFT count from three to two per frame. This is consistent with the Gaussian reassignment formulation described by Gardner and Magnasco (PNAS, 2006), while the existing three-FFT implementation can remain unchanged for non-Gaussian windows.

Prior art

  1. Gardner, T. J., & Magnasco, M. O. (2006). “Sparse time-frequency representations.” Proceedings of the National Academy of Sciences, 103(16), 6094–6099. DOI: 10.1073/pnas.0601707103. This is the key reference for the Gaussian-specific two-FFT reassignment formulation. (PubMed Central (PMC)][1]) Open-access paper (PMC)

Additional context

The current reassignment implementation computes three FFTs for each analysis frame: one for the analysis window h, one for its derivative h', and one for the time-weighted window u h, where u = τ - t. This is the standard general-purpose formulation because, for an arbitrary window, h' and u h are independent functions.

For the Gaussian windows already supported by Audacity, however, these two auxiliary windows are analytically dependent.

A convenient centered STFT convention for deriving the reassignment equations is

latex
\[
V_h(t,\omega)
=
\int_{-\infty}^{\infty}
x(\tau)\,h(\tau-t)\,
e^{-i\omega(\tau-t)}\,d\tau.
\]

Write the complex STFT as

latex
\[
V_h(t,\omega)=A(t,\omega)e^{i\phi(t,\omega)}.
\]

With this convention, the classical reassignment coordinates are obtained from the phase gradient:

latex
\[
\widehat{\omega}(t,\omega)
=
\omega+\frac{\partial\phi}{\partial t},
\]

\[
\widehat{t}(t,\omega)
=
t-\frac{\partial\phi}{\partial\omega}.
\]

Since

latex
\[
\frac{\partial\log V_h}{\partial u}
=
\frac{\partial_u V_h}{V_h}
=
\frac{\partial_u A}{A}
+i\frac{\partial_u\phi}{\partial u},
\]

the imaginary part of the logarithmic derivative gives the corresponding phase derivative.

Frequency reassignment

Differentiating the centered STFT with respect to time gives

latex
\[
\frac{\partial V_h}{\partial t}
=
-\int
x(\tau)\,h'(\tau-t)\,
e^{-i\omega(\tau-t)}\,d\tau
+
i\omega V_h(t,\omega).
\]

Define

latex
\[
V_{h'}(t,\omega)
=
\int
x(\tau)\,h'(\tau-t)\,
e^{-i\omega(\tau-t)}\,d\tau.
\]

Therefore

latex
\[
\frac{\partial_t V_h}{V_h}
=
-\frac{V_{h'}}{V_h}
+i\omega.
\]

Taking the imaginary part gives

latex
\[
\frac{\partial\phi}{\partial t}
=
\omega-
\operatorname{Im}
\left(
\frac{V_{h'}}{V_h}
\right).
\]

Hence

latex
\[
\boxed{
\widehat{\omega}
=
\omega-
\operatorname{Im}
\left(
\frac{V_{h'}}{V_h}
\right).
}
\]

This is the frequency-reassignment correction already represented by the derivative-window transform in the current Audacity implementation.

Time reassignment

Differentiating the centered STFT with respect to frequency gives

latex
\[
\frac{\partial V_h}{\partial\omega}
=
-i
\int
(\tau-t)x(\tau)\,
h(\tau-t)\,
e^{-i\omega(\tau-t)}\,d\tau.
\]

Define

latex
\[
V_{uh}(t,\omega)
=
\int
(\tau-t)x(\tau)\,
h(\tau-t)\,
e^{-i\omega(\tau-t)}\,d\tau.
\]

Then

latex
\[
\partial_\omega V_h=-iV_{uh},
\]

and therefore

latex
\[
i\frac{\partial_\omega V_h}{V_h}
=
\frac{V_{uh}}{V_h}.
\]

Since

latex
\[
\operatorname{Re}
\left(
i\frac{\partial_\omega V_h}{V_h}
\right)
=
-\frac{\partial\phi}{\partial\omega},
\]

the reassigned time is

latex
\[
\boxed{
\widehat{t}
=
t+
\operatorname{Re}
\left(
\frac{V_{uh}}{V_h}
\right).
}
\]

Thus the generic reassignment calculation requires three transforms:

latex
\[
V_h,\qquad V_{h'},\qquad V_{uh}.
\]

This explains the three FFTs currently performed by Audacity.

Gaussian-window special case

Now consider a Gaussian analysis window

latex
\[
h(u)
=
\exp
\left(
-\frac{u^2}{2\sigma^2}
\right).
\]

Its derivative is

latex
\[
h'(u)
=
-\frac{u}{\sigma^2}h(u).
\]

Therefore

latex
\[
\boxed{
u\,h(u)
=
-\sigma^2 h'(u).
}
\]

Because the STFT is linear,

latex
\[
\boxed{
V_{uh}
=
-\sigma^2 V_{h'}.
}
\]

Substituting this into the reassignment equations gives

latex
\[
\boxed{
\widehat{\omega}
=
\omega-
\operatorname{Im}
\left(
\frac{V_{h'}}{V_h}
\right)
}
\]

\[
\boxed{
\widehat{t}
=
t-
\sigma^2
\operatorname{Re}
\left(
\frac{V_{h'}}{V_h}
\right).
}
\]

Both reassignment coordinates therefore come from the same complex quotient

latex
\[
\boxed{
Q(t,\omega)
=
\frac{V_{h'}(t,\omega)}{V_h(t,\omega)}.
}
\]

The independent transform of u h is redundant.

The Gaussian case can therefore be computed using only

latex
\[
V_h=\operatorname{FFT}(xh)
\]

\[
V_{h'}=\operatorname{FFT}(xh').
\]

Thus the FFT count becomes

latex
\[
\boxed{
3\ {\rm FFTs}\longrightarrow2\ {\rm FFTs}.
}
\]

This is not a different reassignment algorithm. It is an algebraic simplification of the standard reassignment equations that exploits the differential equation satisfied by the Gaussian.

Relation to Audacity's Gaussian parameterization

Audacity currently supports Gaussian windows parameterized by a = 2.5, 3.5, and 4.5. The implementation uses the form

latex
\[
h[n]
=
\exp
\left[
-2a^2
\left(
\frac{n-N/2}{N}
\right)^2
\right].
\]

Comparing this with

latex
\[
h[n]
=
\exp
\left[
-\frac{(n-N/2)^2}{2\sigma^2}
\right]
\]

gives

latex
\[
\boxed{
\sigma=\frac{N}{2a}
}
\]

and therefore

latex
\[
\boxed{
\sigma^2=\frac{N^2}{4a^2}.
}
\]

Differentiating the Gaussian gives

latex
\[
h'[n]
=
-\frac{4a^2}{N^2}
\left(n-\frac N2\right)h[n].
\]

Consequently,

latex
\[
\boxed{
\left(n-\frac N2\right)h[n]
=
-\frac{N^2}{4a^2}h'[n].
}
\]

For example, for Gaussian(a = 4.5),

latex
\[
\sigma^2=\frac{N^2}{81}.
\]

Therefore the spectrum of the current tWindow can, in principle, be obtained directly from the spectrum of dWindow by multiplying by the appropriate Gaussian scaling factor, eliminating the third FFT.

Finite and discrete window considerations

There is one implementation detail that should be checked before making the optimization unconditional.

The identity

latex
\[
u h(u)=-\sigma^2h'(u)
\]

is exact for the continuous Gaussian. Audacity uses a finite, discretized Gaussian and has explicit endpoint handling in DerivativeOfWindowFunc().

It is therefore useful to define the discrete residual

latex
\[
r[n]
=
\left(n-\frac N2\right)h[n]
+
\frac{N^2}{4a^2}h'[n].
\]

If the discrete Gaussian and derivative satisfy the analytic relationship exactly, then

latex
\[
r[n]=0
\]

for every sample and the third FFT can be removed directly.

If the finite-window endpoint convention produces a nonzero residual, then

latex
\[
\left(n-\frac N2\right)h[n]
=
-\frac{N^2}{4a^2}h'[n]+r[n]
\]

and therefore

latex
\[
V_{uh}
=
-\frac{N^2}{4a^2}V_{h'}+V_r.
\]

Any correction associated with the finite-window boundary can potentially be evaluated explicitly rather than by performing another full FFT. This would allow the Gaussian-specific optimization while preserving compatibility with the existing discrete window definition.

The safest implementation would therefore first compare the actual discrete tWindow and dWindow generated by Audacity and verify whether the residual is zero, apart from floating-point effects. If necessary, a boundary correction can be introduced.

Proposed implementation strategy

The optimization can be restricted to the Gaussian cases:

Gaussian window:
    FFT(x * h)
    FFT(x * h')
    derive the time-reassignment term from dWindow

Non-Gaussian window:
    retain the existing
    FFT(x * h)
    FFT(x * h')
    FFT(x * tWindow)

This keeps the current generic reassignment implementation unchanged for Hann, Hamming, Blackman, Blackman-Harris, Bartlett, Welch, and other windows.

At the reassignment stage, the Gaussian path only needs the complex quotient

latex
\[
Q=\frac{V_{h'}}{V_h}.
\]

The existing frequency-correction scaling can continue to be applied to Im(Q), while the time correction can be obtained from Re(Q) multiplied by the Gaussian variance in samples squared and converted using the existing sample-rate/pixel-rate scaling.

Computational consequence

If C_FFT denotes the cost of one FFT and C_post denotes the remaining per-bin reassignment operations, the current Gaussian implementation has approximately

latex
\[
3C_{\rm FFT}+C_{\rm post}.
\]

The optimized implementation becomes

latex
\[
2C_{\rm FFT}+C_{\rm post},
\]

or, if an endpoint correction is required,

latex
\[
2C_{\rm FFT}+C_{\rm post}+C_{\rm boundary}.
\]

Since the boundary correction is expected to be much smaller than a full FFT, the dominant FFT workload is reduced by approximately one third.

Prior work

Gardner and Magnasco, “Sparse time-frequency representations,” Proceedings of the National Academy of Sciences, 103(16), 6094–6099 (2006), DOI 10.1073/pnas.0601707103, derive a Gaussian-window reassignment formulation based on the Gaussian-windowed signal and its derivative and discuss the resulting computational reduction. This is the most directly relevant reference for the proposed Gaussian-specific optimization.

Auger and Flandrin, “Improving the readability of time-frequency and time-scale representations by the reassignment method,” IEEE Transactions on Signal Processing, 43(5), 1068–1089 (1995), DOI 10.1109/78.382394, provide the standard reassignment framework and the general time/frequency reassignment formulation.

Flandrin, Auger, and Chassande-Mottin, “Time-Frequency Reassignment — From Principles to Algorithms,” in Applications in Time-Frequency Signal Processing, CRC Press, 2003, provides an implementation-oriented treatment of the reassignment method.

An implementation-oriented reference is libtfr, which documents both the conventional reassignment computation using the analysis window, its derivative, and its time-weighted version, and the Gaussian-specific formulation associated with Gardner and Magnasco:

https://github.com/melizalab/libtfr

Relevant Audacity source

The current reassignment implementation is in:

https://github.com/audacity/audacity/blob/master/src/spectrogram/internal/au3/SpectrumCache.cpp

The Gaussian windows and their derivatives are generated in:

https://github.com/audacity/audacity/blob/master/src/spectrogram/internal/au3/au3spectrogramsettings.cpp

The current Reassignment path explicitly performs three RealFFTf() transforms: one for the main window, one for dWindow, and one for tWindow. The Gaussian window types and their derivative functions are already present, so the proposed change can be implemented as a localized Gaussian-specific optimization without changing the general reassignment algorithm.