Initial Checklist
Problem Statement & User Value
As a DSP Engineer, Machine Learning Engineer, I want to reconstruct a time-domain signal from its Short-Time Fourier Transform (STFT) representation, so that I can implement and apply spectral processing algorithms such as filtering, time-stretching, pitch-shifting, and audio synthesis.
Acceptance Criteria (Definition of Done)
API Definition
Core Functionality & Correctness
Parameter Handling & Validation
Utility Functions
Performance
Proposed Solution or Technical Approach (Optional)
1. Core Algorithm: Overlap-Add (OLA)
The fundamental method for iSTFT is the Overlap-Add (OLA) technique. The process involves these steps:
- Each time frame (column) of the input STFT matrix is transformed back to a short time-domain signal segment using an Inverse Fast Fourier Transform (IFFT).
- Each resulting time-domain segment is multiplied by a synthesis window.
- These windowed segments are then overlapped and summed (added) together at intervals determined by the hop_length to reconstruct the full time-domain signal.
The reconstruction formula can be expressed as:
$x[n] = \frac{\sum_{t} y_t[n] \cdot w_s[n - tH]}{\sum_{t} w_a[n - tH] \cdot w_s[n - tH]}$
where $y_t$ is the IFFT of the $t$-th frame, $w_a$ is the analysis window used in the forward STFT, $w_s$ is the synthesis window, and $H$ is the hop size. For perfect reconstruction, the denominator must be a non-zero constant.
2. COLA and NOLA Constraints
For the iSTFT to be a true inverse, the windowing and overlap parameters must satisfy certain constraints.
- NOLA (Nonzero Overlap-Add): This is the minimum requirement for invertibility. It ensures the denominator in the OLA equation is never zero, preventing division by zero but not necessarily preserving the signal's original amplitude.
- COLA (Constant Overlap-Add): This is a stricter condition where the denominator is a non-zero constant. Satisfying COLA ensures that all windowing artifacts are perfectly cancelled out, leading to perfect reconstruction of an unmodified STFT.
- Weak COLA is sufficient for perfect reconstruction of unmodified spectra but relies on alias cancellation that can be disrupted by spectral modifications.
- Strong COLA is preferred when the spectrum is modified (e.g., for audio effects), as it prevents aliasing altogether.
3. High-Level Algorithm Steps:
- Initialization: Infer parameters (
n_fft, win_length, etc.) from the input matrix and optional arguments. Generate the synthesis window array win. Pre-calculate the squared window win_sq = win * win. Initialize an output signal buffer y and a window normalization buffer win_sum_sq to zeros, with a length determined by the STFT dimensions and hop length.
- Frame Processing Loop: Iterate through each time frame (column
t) of the stft matrix.
- IFFT: For each frame, perform an
n_fft-point IFFT. If the input is one-sided (from a real signal), first reconstruct the full conjugate-symmetric spectrum.
- Overlap-Add: Multiply the resulting time-domain segment by the synthesis window. Determine the start sample index
n = t * hop_length. Add the windowed segment to the output buffer y and the squared window win_sq to the normalization buffer win_sum_sq at the appropriate offsets.
- Normalization: After the loop, normalize the output signal:
y = y / win_sum_sq. To prevent division by zero at the signal edges where the window sum might be zero, replace zeros in win_sum_sq with a small epsilon before division.
- Finalization: If the length parameter is provided, trim or pad the final signal y to the specified length.
Additional Context (Mockups, Links, etc.)
Reference table of common window functions and their COLA-compliant overlap percentages should be included in the documentation.
| Window Function |
COLA-Compliant Overlap |
| Rectangular |
0%, 50%, 75% |
| Hann |
50%, 66.7% (2/3), 75% |
| Hamming |
50% |
| Bartlett |
50% |
This information is derived from the documentation of SciPy and librosa.
References
- Smith, J.O. (2011). Spectral Audio Signal Processing. W3K Publishing. The definitive textbook on STFT, overlap-add methods, and windowing.
- Griffin, D., & Lim, J. (1984). "Signal estimation from modified short-time Fourier transform." IEEE Transactions on Acoustics, Speech, and Signal Processing, 32(2), 236-243. The seminal paper describing the least-squares approach to STFT inversion and the Griffin-Lim algorithm.
- Librosa: librosa.istft documentation.
- SciPy: scipy.signal.istft documentation. A key reference for the NOLA constraint and the least-squares implementation method.
- MATLAB: istft documentation. Strict, COLA-focused implementation and the utility of providing a COLA-checking function.
Code of Conduct
Initial Checklist
Problem Statement & User Value
As a DSP Engineer, Machine Learning Engineer, I want to reconstruct a time-domain signal from its Short-Time Fourier Transform (STFT) representation, so that I can implement and apply spectral processing algorithms such as filtering, time-stretching, pitch-shifting, and audio synthesis.
Acceptance Criteria (Definition of Done)
API Definition
SoundML.Transform.istftis available in the library'sTransformmodule.odoc) is provided for the function. The documentation must detail each parameter, the return value, potential exceptions, and explicitly state the conditions required for perfect reconstruction.Core Functionality & Correctness
librosaandSciPy.n_fft,hop_length, andwindowparameters are used for bothstftandistft.windowandhop_lengthsatisfy the Constant Overlap-Add (COLA) constraint.Parameter Handling & Validation
n_fftandwin_lengthfrom the input STFT matrix shape when these parameters are not explicitly provided, as documented bylibrosa.Hann,Hamming,Rectangular) passed via a variant type.stftfunction, which is critical for avoiding boundary artifacts.win_length > n_fft).Utility Functions
SoundML.Utils.is_cola : window -> hop_length -> boolis provided. This utility allows users to programmatically check if their chosen window and hop length parameters satisfy the COLA constraint, mirroring the functionality of MATLAB'siscolaand SciPy'scheck_COLA.Performance
Proposed Solution or Technical Approach (Optional)
1. Core Algorithm: Overlap-Add (OLA)
The fundamental method for iSTFT is the Overlap-Add (OLA) technique. The process involves these steps:
The reconstruction formula can be expressed as:
where
2. COLA and NOLA Constraints
For the iSTFT to be a true inverse, the windowing and overlap parameters must satisfy certain constraints.
3. High-Level Algorithm Steps:
n_fft,win_length, etc.) from the input matrix and optional arguments. Generate the synthesis window array win. Pre-calculate the squared windowwin_sq = win * win. Initialize an output signal bufferyand a window normalization bufferwin_sum_sqto zeros, with a length determined by the STFT dimensions and hop length.t) of thestftmatrix.n_fft-point IFFT. If the input is one-sided (from a real signal), first reconstruct the full conjugate-symmetric spectrum.n = t * hop_length. Add the windowed segment to the output bufferyand the squared windowwin_sqto the normalization bufferwin_sum_sqat the appropriate offsets.y = y / win_sum_sq. To prevent division by zero at the signal edges where the window sum might be zero, replace zeros inwin_sum_sqwith a small epsilon before division.Additional Context (Mockups, Links, etc.)
Reference table of common window functions and their COLA-compliant overlap percentages should be included in the documentation.
This information is derived from the documentation of SciPy and librosa.
References
Code of Conduct