Mid-Side Matrix — Stereo Stem Tool
A clean, reversible Mid/Side matrix. Splits a stereo mix into independent Mid and Side objects, rebuilds L/R from them, verifies losslessness within floating-point tolerance, and can prepare an anti-phase Side pair for ambisonic spatialisation.
What this does
This script implements a clean, reversible Mid/Side matrix for stereo stem preparation. Unlike the library's other M/S uses (panning, mic simulation, subharmonics), this is a dedicated stem tool: it splits a stereo mix into independent Mid and Side objects, rebuilds L/R from them, verifies losslessness within floating-point tolerance, and can prepare an anti-phase Side pair for ambisonic spatialisation.
Key Features:
- 4 Modes — Stereo L/R → Mid/Side, Mid/Side → Stereo L/R, Round-trip verification, Spatial source preparation
- Exact reversible matrix — L = M + S, R = M − S, reconstruction within floating-point tolerance
- Self-test — verifies matrix correctness with known test signals before processing
- Metrics — correlation, Side energy share, Side/Mid ratio, null test residual
- Visualisation — input L/R, output M/S, energy share and correlation bars
Quick start
- Select the appropriate Sound(s) based on the mode (see below).
- Run script… →
Mid-Side_Matrix.praat. - Choose a mode from the dropdown (4 options).
- Enable Run_reference_test (recommended) to verify matrix correctness.
- Enable Draw_visualization to see L/R, M/S waveforms, and diagnostics.
- Click OK — script processes, reports metrics, creates output stem(s).
_Mid and _Side suffixes sharing the same base name (e.g., piece_Mid and piece_Side). The script fails closed if it can't identify the stems — no guessing of polarity. The matrix is exact: M = (L+R)/2, S = (L−R)/2, and L = M + S, R = M − S. Reconstruction is within floating-point tolerance (not bit-identical due to floating-point rounding).
4 Modes
Mode 1 Stereo L/R → Mid/Side
Select one stereo Sound. The script extracts Left and Right channels, applies the matrix, and creates two mono Sounds: original_Mid and original_Side.
Use: Split a stereo mix into Mid and Side stems for further processing.
Mode 2 Mid/Side → Stereo L/R
Select two mono Sounds with _Mid and _Side suffixes (same base name). The script reconstructs L = M + S and R = M − S, creating a stereo Sound.
Use: Reconstruct stereo from Mid and Side stems after processing.
Mode 3 Round-trip verification
Select one stereo Sound. The script encodes to Mid/Side, decodes back to L/R, and reports the reconstruction residual (max and RMS).
Use: Verify that the matrix is lossless within floating-point tolerance.
Mode 4 Spatial source preparation
Select one stereo Sound. The script creates three mono stems: Mid (anchor), Side_Left (+S), and Side_Right (−S).
Use: Prepare stems for ambisonic spatialisation — process +S and −S symmetrically to preserve their complementary polarity relationship.
The Matrix — Exact and Reversible
Encoding (L/R → M/S)
M = (L + R) / 2
S = (L − R) / 2
This is the half-sum / unity-mono version:
- L = R → M = L, S = 0 (mono signal)
- L = −R → M = 0, S = L (anti-phase signal)
- R = 0 → M = L/2, S = L/2 (left-only signal)
- L = 0 → M = R/2, S = −R/2 (right-only signal)
Decoding (M/S → L/R)
L = M + S
R = M − S
Metrics & Diagnostics
Mid RMS / Side RMS
Root-mean-square amplitude of the Mid and Side channels. High Side RMS relative to Mid indicates wide stereo content.
Side/Mid ratio (dB)
20·log₁₀(SideRMS / MidRMS). Positive = Side dominates; negative = Mid dominates. "−inf dB" = Side silent (mono signal). "+inf dB" = Mid silent (anti-phase signal).
Channel correlation
Zero-lag normalised correlation between L and R: mean(L·R) / (rmsL·rmsR). Values near 1 = mono-compatible; near −1 = anti-phase; undefined if a channel is silent.
Side energy share
Percentage of total energy (Mid + Side) contained in the Side channel. 0% = mono; 50% = uncorrelated equal energy; >50% = negative correlation/anti-phase.
Reconstruction null test
After encoding to Mid/Side and decoding back to L/R, the residual (original − reconstructed) is measured. Max and RMS residuals are reported. PASS if max residual < 1e-9.
Applications
Stereo stem extraction (Mode 1)
Use case: Split a stereo mix into Mid and Side stems for independent processing — e.g., compress the Mid for punch, add reverb to the Side for width.
Settings: Mode 1, select one stereo Sound. Output: original_Mid and original_Side.
Stereo reconstruction from stems (Mode 2)
Use case: After processing Mid and Side separately, reconstruct the stereo mix.
Settings: Mode 2, select _Mid and _Side mono Sounds. Output: base_Stereo.
Losslessness verification (Mode 3)
Use case: Verify that the matrix is reversible and no information is lost.
Settings: Mode 3, select one stereo Sound. The script reports reconstruction residuals.
Ambisonic spatialisation preparation (Mode 4)
Use case: Prepare Mid, +Side, and −Side stems for ambisonic encoding or spatial processing.
Settings: Mode 4, select one stereo Sound. Output: Mid, Side_Left (+S), Side_Right (−S). Process +S and −S symmetrically.
Workflow: Stereo mix → Mid/Side processing → Stereo
Source: Stereo mix (music, field recording).
Step 1: Mode 1 → original_Mid and original_Side.
Step 2: Process Mid (e.g., EQ, compression) and Side (e.g., reverb, delay).
Step 3: Mode 2 → select processed _Mid and _Side → processed_Stereo.
Result: Stereo mix with independently processed Mid and Side channels.
Workflow: Round-trip verification
Source: Any stereo Sound.
Settings: Mode 3, Run_reference_test = yes.
Result: The script reports max and RMS residuals. If PASS, the matrix is lossless within floating-point tolerance. This verifies that no information is lost in the encoding/decoding process.
Workflow: Ambisonic spatialisation
Source: Stereo Sound (e.g., field recording).
Settings: Mode 4 → Mid, Side_Left (+S), Side_Right (−S).
Processing: Apply spatial effects symmetrically to +S and −S (e.g., delay, panning, EQ).
Result: Three mono stems ready for ambisonic encoding or further spatialisation. The complementary polarity of +S and −S is preserved.
• Mode 2: "Could not identify Mid and Side" — Rename the two mono objects with
_Mid and _Side suffixes (e.g., piece_Mid, piece_Side). They must share the same base name.• Mode 2: "Length mismatch" or "Sample-rate mismatch" — Mid and Side stems must be exactly the same length and sample rate. The script checks and reports the mismatch.
• Decoded peak exceeds ±1 — Reduce Mid and Side jointly (same factor) before WAV export. Do not normalise separately — that would break the matrix.
• Correlation shows "undefined (a channel is silent)" — This is normal for mono or anti-phase signals. The visualisation shows "N/A" in grey instead of a misleading 0.5 value.
• Self-test fails — This indicates a bug in the matrix implementation. Abort and report the issue. Do not continue processing.
Visualisation (8-wide canvas)
- Input L/R — blue = Left, red = Right
- Mid / Side — green = Mid, amber = Side
- Energy share and correlation — bars showing Mid/Side energy share and correlation (mapped 0–1). Correlation bar is grey with "N/A" if undefined.
- Summary panel — Mid RMS, Side RMS, Side/Mid ratio, correlation, Side energy share, reconstruction null test result.