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.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 1.2 (2026) License: MIT License Repo: https://github.com/ShaiCohen-ops/Praat-plugin_AudioTools
Contents:

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.

What is Mid/Side? Mid/Side is a stereo encoding technique that transforms the standard Left/Right representation into a sum channel (Mid = L+R) and a difference channel (Side = L−R). This representation is useful for spatial audio processing, as Mid contains the mono-compatible centre content and Side contains the stereo width information. The matrix used here is the half-sum / unity-mono version: M = (L+R)/2, S = (L−R)/2, which is safer for headroom than the full-sum version.

Key Features:

v1.2 library-hardening: Decode mode now fails closed if Mid/Side can't be identified by name suffix (_Mid / _Side), and requires both stems to share a base name. Correlation bar shows "N/A" (grey) when undefined instead of 0.5. Wording has been clarified: "anti-phase (L=-R)", "within floating-point tolerance", and "highly correlated / mono-compatible".

Quick start

  1. Select the appropriate Sound(s) based on the mode (see below).
  2. Run script…Mid-Side_Matrix.praat.
  3. Choose a mode from the dropdown (4 options).
  4. Enable Run_reference_test (recommended) to verify matrix correctness.
  5. Enable Draw_visualization to see L/R, M/S waveforms, and diagnostics.
  6. Click OK — script processes, reports metrics, creates output stem(s).
Quick tip: Use Mode 1 to split any stereo sound into Mid and Side. Use Mode 2 to reconstruct stereo from two mono _Mid and _Side stems. Use Mode 3 to verify the round-trip is lossless. Use Mode 4 to prepare Mid, +Side, and −Side stems for ambisonic spatialisation.
Important: Mode 2 requires exactly two mono Sounds with _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.

Spatial mode note: Mode 4 does NOT guarantee exact reconstruction of the original stereo image after spatial encoding/decoding. It is preparation for creative spatial interpretation, not transparent stereo → ambisonics conversion. The complementary polarity relationship (+S and −S) should be preserved during processing.

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

Why half-sum? The half-sum normalisation (dividing by 2) prevents clipping when L and R are both at full scale. In the full-sum version (M = L+R, S = L−R), a mono signal at 0 dBFS would produce M = 2.0, which clips. The half-sum version keeps M at 1.0 for a mono signal, safe for headroom. Reconstruction is exact: (M+S) = ((L+R)/2 + (L−R)/2) = L.
Self-test: The script runs a reference self-test by default, verifying the matrix with four known signals (mono, anti-phase, left-only, right-only). This catches polarity and scaling errors immediately. If the self-test fails, the script aborts so no wrong stems are produced.

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.

Interpreting the metrics: A Side energy share of 30–50% indicates moderate width; >50% suggests negative correlation (anti-phase content). The correlation metric is the standard zero-lag normalised channel correlation — useful for checking mono compatibility. The reconstruction null test confirms the matrix is exact within floating-point tolerance.

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 _Sideprocessed_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.

Troubleshooting:
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)

When Draw_visualization is enabled, the script generates:
  • 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.
The visualisation is drawn in Modes 1, 3, and 4 (stereo input). Mode 2 does not draw visualisation (it reconstructs stereo from mono stems).