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.
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.
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:
- 4 modes — encode, decode, round-trip verification, and spatial stem preparation.
- Reference self-test — optional, enabled by default; exercises the actual matrix code with four known stereo cases before user processing.
- Fail-closed decode — Mode 2 identifies stems only by matching
_Mid/_Sidesuffixes and requires a shared base name. - Diagnostics — Mid/Side RMS, Side/Mid ratio, zero-lag normalized L/R correlation, Side energy share, and reconstruction residual.
- Visualization — available for Modes 1, 3, and 4; Mode 2 reports numerically but does not draw.
Quick start
- Select the Sound object(s) required by the chosen mode.
- Run script… →
Mid-Side_Matrix.praat. - Choose one of the four Mode options.
- Leave Run_reference_test enabled unless you intentionally want to skip the matrix self-test.
- Choose whether to draw the visualization and whether to play the result/preview.
- Click OK.
_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
| Parameter | Default | Behavior |
|---|---|---|
| Mode | 1 | 1 = Stereo L/R → Mid/Side; 2 = Mid/Side → Stereo L/R; 3 = Round-trip verification; 4 = Spatial source preparation. |
| Run_reference_test | yes | Runs four known matrix cases before processing. Any failure aborts the script. |
| Draw_visualization | yes | Draws diagnostics for Modes 1, 3, and 4. Mode 2 does not draw a figure. |
| Play_result | no | Mode 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
M + S = ((L+R) + (L−R))/2 = L
M − S = ((L+R) − (L−R))/2 = R
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.
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.
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.