Mid-Side Matrix — Stereo Stem Tool

A reversible Mid/Side matrix for stereo stem preparation. It encodes stereo L/R to independent Mid and Side stems, decodes matching Mid/Side stems back to stereo, performs a round-trip null test, and can create a complementary +Side/−Side pair for spatial processing.

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

What this does

Mid-Side Matrix is a dedicated stereo stem tool. Its exact modes apply only a linear Mid/Side matrix: no per-stem normalization, DC removal, filtering, or resampling is applied. The script preserves sample rate, sample count, start time, and duration through the encode/decode operations, so a normal round trip reconstructs the source within floating-point tolerance.

Matrix convention: This script uses the half-sum / unity-mono form M = (L+R)/2 and S = (L−R)/2, with inverse L = M+S and R = M−S. The factor of 1/2 keeps the encoded Mid and Side stems within the input sample bounds when the source itself is within those bounds.

Key behavior:

v1.3.1: The current release changes visualization layout only. v1.3 standardized label rails, summary layout, and typography; v1.3.1 separates the title/header bands and compacts the Summary panel. The DSP and matrix are unchanged from the hardened v1.2 implementation.

Quick start

  1. Select the Sound object(s) required by the chosen mode.
  2. Run script… → Mid-Side_Matrix.praat.
  3. Choose one of the four Mode options.
  4. Leave Run_reference_test enabled unless you intentionally want to skip the matrix self-test.
  5. Choose whether to draw the visualization and whether to play the result/preview.
  6. Click OK.
Mode 2 naming is strict: select exactly two mono Sounds whose names end in _Mid and _Side and whose base names match, for example piece_Mid and piece_Side. Selection order does not determine polarity. The script aborts instead of guessing if it cannot identify a valid pair.

Parameters & defaults

ParameterDefaultBehavior
Mode11 = Stereo L/R → Mid/Side; 2 = Mid/Side → Stereo L/R; 3 = Round-trip verification; 4 = Spatial source preparation.
Run_reference_testyesRuns four known matrix cases before processing. Any failure aborts the script.
Draw_visualizationyesDraws diagnostics for Modes 1, 3, and 4. Mode 2 does not draw a figure.
Play_resultnoMode 2 plays the decoded stereo output. Modes 1, 3, and 4 build a temporary stereo preview from the produced Mid/Side pair, play it, and remove the temporary preview.

4 Modes

Mode 1 Stereo L/R → Mid/Side

Select exactly one stereo Sound with at least two samples. The script extracts L and R and creates original_Mid and original_Side.

Final selection: the two produced mono stems.

Mode 2 Mid/Side → Stereo L/R

Select exactly two mono Sounds: a matching _Mid and _Side pair. They must have the same sample rate, sample count, and start time. The output is base_Stereo.

Peak handling: no normalization is applied. The decoded absolute peak is reported; if it exceeds 1.0 the script warns that Mid and Side should be reduced jointly before integer WAV export.

Mode 3 Round-trip verification

Select exactly one stereo Sound. The script encodes it to Mid/Side, reconstructs L/R internally, subtracts the originals, and reports max and RMS residuals.

Outputs: the _Mid and _Side stems remain as the produced objects.

Mode 4 Spatial source preparation

Select exactly one stereo Sound. The final outputs are original_Mid, original_Side_Left (+S), and original_Side_Right (−S). The intermediate original_Side object is removed.

Use: complementary Side stems for later spatial processing. This is preparation for creative spatial interpretation, not a transparent stereo-to-ambisonics conversion.

The Matrix — Exact and Reversible

Encoding (L/R → M/S)

M = (L + R) / 2

S = (L − R) / 2

  • L = R → M = L, S = 0.
  • L = −R → M = 0, S = L.
  • R = 0 → M = L/2, S = L/2.
  • L = 0 → M = R/2, S = −R/2.

Decoding (M/S → L/R)

L = M + S

R = M − S

Round trip:
M + S = ((L+R) + (L−R))/2 = L
M − S = ((L+R) − (L−R))/2 = R
Reference self-test: when enabled, the script constructs four short two-channel test signals — mono, anti-phase, left-only, and right-only — and checks the resulting M and S sample values against the analytic expectations with a tolerance of 1e-9. Any failure aborts processing.

Metrics & Diagnostics

Mid RMS / Side RMS

RMS amplitude of the encoded Mid and Side stems.

Side/Mid ratio (dB)

20·log10(SideRMS / MidRMS). The script explicitly reports silent-input, silent-Mid, and silent-Side cases instead of forcing a finite dB value.

Channel correlation

mean(L·R) / (rmsL·rmsR), clamped to −1…1. This is zero-lag normalized channel correlation, not full Pearson correlation because channel means are not subtracted. It is undefined if either channel RMS is effectively zero.

Side energy share

100 × SideRMS² / (MidRMS² + SideRMS²). 0% corresponds to identical L/R; 50% occurs when the L/R cross-product averages to zero; values above 50% indicate a negative L/R cross-term.

Reconstruction null test

The internally reconstructed L and R are subtracted from the extracted input channels. PASS requires the maximum absolute residual across both channels to be below 1e-9; combined RMS residual is also reported.

Report interpretation implemented in the script: correlation > 0.98 with Side share < 2% is labelled “nearly mono”; correlation > 0.98 with more Side energy is “highly correlated / mono-compatible (but level-imbalanced, so not mono)”; Side share > 50% is flagged as negative correlation / anti-phase; Side share > 30% is labelled moderately wide.

Visualization

When Draw_visualization is enabled in Modes 1, 3, or 4, the script draws an 8-unit-wide figure. v1.3.1 uses separate header bands so the title and source metadata do not collide with the data panels.

  • Header: title MID-SIDE MATRIX v1.3.1, followed by source name, duration, and sample rate in a separate metadata band.
  • Input stereo: L in blue and R in red, sharing an amplitude scale based on the larger input-channel absolute peak with 15% visual headroom.
  • Mid / Side: Mid in green and Side in amber, drawn on that same amplitude scale for direct comparison with the input.
  • Energy/correlation bars: Mid and Side energy fractions plus correlation mapped from −1…1 onto a 0…1 bar. Undefined correlation is shown as a grey full-height bar labelled N/A.
  • Summary: compact grey panel with Mid RMS, Side RMS, Side/Mid ratio, correlation, Side energy share, reconstruction residuals, null-test PASS/FAIL, and the matrix equations.
Mode 2: no visualization is drawn. The script reports the decoded object, sample count/rate, and peak in the Info window instead.

Applications

Stereo stem extraction

Use Mode 1 to create independent Mid and Side stems for later processing. If exact reconstruction is required after processing, preserve the stems' timing and apply any global level change jointly rather than normalizing them independently.

Stereo reconstruction

Use Mode 2 on a matching _Mid/_Side pair. The decoder does not apply a limiter or normalization; it reports a warning if reconstructed samples exceed ±1.

Matrix verification

Mode 3 tests the complete encode/decode path on the selected stereo source and leaves the encoded stems available after the test.

Spatial stem preparation

Mode 4 creates a Mid anchor and complementary +S/−S Side stems. Processing the two Side stems symmetrically preserves their polarity relationship, but subsequent spatial encoding/decoding is not guaranteed to reconstruct the original stereo image.

Important: The matrix itself is reversible, but independent processing of Mid and Side changes the signal by design. Likewise, separately normalizing or otherwise applying unequal gain to a matching Mid/Side pair changes the reconstructed L/R relationship.