Breaking the Sound Barrier: Symmetrical 2x2 MIMO Acoustic Handshake & THD Optimization

9 min read
networkingacoustic-phymimosignal-processingdspopen-sourceandroidswift

Sound is a wonderfully stubborn medium.

When you try to transmit high-speed data over-the-air using acoustic waves, you aren’t just fighting standard wireless path loss. You are fighting severe multipath reflections (sound bounces off desks, monitor bezels, and walls), extreme Doppler shift (a human walking past a desk shifts the carrier frequency by tens of Hertz), and, worst of all, the stubborn physical nonlinearities of standard laptop and mobile transducers.

In my work on Cyrinx, the goal has been simple: see how far we can push local, pure offline over-the-air communication using sound.

Our baseline was a highly robust single-channel (1x1) physical layer, shifting between a robust Chirp Spread Spectrum (D-CSS) mode and a high-speed QPSK/16-QAM OFDM modem. But to truly cross the performance threshold, we needed to move from single-input, single-output (SISO) to a fully symmetrical, closed-loop 2x2 MIMO (Multiple-Input Multiple-Output) architecture.

Today, I’m excited to share that we just merged the core handshake negotiation, capacity broadcasting protocol, and dynamic harmonic distortion calibrator. For the first time, a MacBook Pro and a Pixel 7a can dynamically discover each other’s physical channel capacities and sound the acoustic environment with orthogonal preambles—laying the mathematical and protocol groundwork for up to 24 kbps co-channel spatial multiplexing, while benchmarking at 8 kbps single-channel goodput today.

Here is how the system actually works, the math under the hood, and the live benchmark findings.


🤝 Symmetrical Dynamic Channel Capacity Negotiation

In a true local-first ad-hoc environment, you cannot assume both sides have symmetrical hardware. A laptop might have stereo speakers and a dual-microphone array; a mobile phone might only support single-channel capture or mono playback at target ultrasonic rates.

To solve this, we implemented a lightweight, dynamic Capacity Handshake protocol operating on the control plane (Stream ID 0) using a magic frame identifier (0xE1):

+-----------------------------------------------------------+
| Frame Header (Type: DATA, Stream: 0, Priority: 3, Seq)    |
+-----------------------------------------------------------+
| Payload: [ 0xE1 (Magic), 1 (Version), Mics, Speakers ]   |
+-----------------------------------------------------------+

The State Machine Sequence

The negotiation follows a clean, rate-limited progression:

  1. Discovery (Gear 1): The Master session broadcasts a robust chirp preamble. The Slave captures and synchronizes.
  2. Transition to G2 (Robust DCSS): The moment the Slave locks on the preamble, it transitions to Gear 2. This transition automatically triggers an auto-broadcast of its channel capacities: [0xE1, 1, slave_mics, slave_speakers].
  3. Auto-Reply and Interception: Both sides ingest Stream 0 packets directly into the private session core. If a client receives a peer’s capabilities, it saves peer_mics_count and peer_speakers_count and responds with its own capacity if it has not done so recently (throttled to >1,000ms intervals to prevent flood loops).
  4. Immediate Acknowledgment: When a capacity packet is ingested, a priority ACK report is packed and returned immediately, cementing the negotiation.

This handshake maintains 100% backward compatibility. If either side reports channels == 1, the session automatically pins itself to robust mono mode, safely falling back to single-channel transmission without breaking the link.


📐 Solving the Spatial Matrix: 2x2 SVD & Orthogonal Pilots

Once both clients agree that they have addressable dual microphones ($N_{rx} = 2$) and speakers ($N_{tx} = 2$), Cyrinx enters the Channel Sounding phase. To characterize the transmission matrix, we must transmit dual orthogonal pilots simultaneously.

Left Speaker  -----> [ Pilot PL (Zadoff-Chu root=29) ] -----\
                                                             =======> Dual Microphones (y1, y2)
Right Speaker -----> [ Pilot PR (Zadoff-Chu root=31) ] -----/

We modulate two distinct roots of a Zadoff-Chu (ZC) CAZAC (Constant Amplitude Zero Autocorrelation) sequence onto the Left and Right channels:

  • Left Pilot ($P_L$): Zadoff-Chu sequence with root = 29
  • Right Pilot ($P_R$): Zadoff-Chu sequence with root = 31

At the receiver, the dual microphone signals ($y_1(t)$ and $y_2(t)$) are captured at $48\text{ kHz}$. We execute a parallel cross-correlation search against $P_L$ and $P_R$ to isolate the complete complex $2 \times 2$ time-domain channel impulse matrix:

$$\mathbf{H} = \begin{bmatrix} h_{11} & h_{12} \ h_{21} & h_{22} \end{bmatrix}$$

Where $h_{ij}$ represents the complex path coefficient from speaker $j$ to microphone $i$.

The SVD Spatial Solver

To determine if the acoustic environment can support co-channel spatial multiplexing, we perform an analytical, in-place Singular Value Decomposition (SVD) directly on the complex matrix $\mathbf{H}$ at the subcarrier level:

$$\mathbf{H} = \mathbf{U} \mathbf{\Sigma} \mathbf{V}^*$$

Where $\mathbf{\Sigma} = \operatorname{diag}(\sigma_1, \sigma_2)$ contains the singular values ($\sigma_1 \ge \sigma_2 \ge 0$).

We then calculate the channel condition number:

$$\kappa_{\text{dB}} = 20 \log_{10}\left(\frac{\sigma_1}{\sigma_2}\right)$$

This condition number serves as our link dispatcher’s primary metric:

  • Spatial Multiplexing (MIMO SM): If $\kappa_{\text{dB}} < 6\text{ dB}$, the channels are highly decorrelated (rich multipath scattering, no deep spatial overlap). We transmit two independent co-channel streams simultaneously, doubling the theoretical goodput up to 24 kbps (active dual-stream decoding is the next target in our roadmap, while single-channel OFDM is benchmarked up to 8-12 kbps).
  • Spatial Diversity (Alamouti/STBC): If $\kappa_{\text{dB}} \ge 6\text{ dB}$ (highly correlated paths, deep obstruction, or severe spatial overlap), spatial multiplexing would collapse under co-channel interference. We fallback to transmitting redundant space-time block codes, maximizing link reliability over a single robust stream.

🔊 Programmatic Total Harmonic Distortion (THD) Calibration

One of our biggest engineering breakthroughs came from debugging severe cyclic redundancy check (CRC) failures when physical hardware was placed in direct contact.

When the phone is rested directly on a laptop’s metal keyboard frame, the mechanical vibrations conduct directly through the aluminum chassis. This direct physical coupling generates massive harmonic buzzing, rattling, and phase distortion that completely garbles high-speed QPSK and 16-QAM constellations.

To solve this, Cyrinx includes an automated THD characterization routine built into the channel sounding phase:

  1. Pure Tone Probe: The transmitter emits a single-frequency sine wave test tone at a fundamental frequency $f_0$ (e.g., $3\text{ kHz}$ or $5\text{ kHz}$) at an initial gain $g$.
  2. FFT Power Capture: The receiver records $N = 2048$ samples, computes an in-place $N$-point FFT, and extracts the power at the fundamental bin $P(f_0)$ and all integer harmonics $P(2f_0), P(3f_0), \dots$ up to the Nyquist limit ($24\text{ kHz}$).
  3. THD Calculation: We calculate the distortion percentage:

$$\text{THD}{\text{pct}} = \sqrt{\frac{\sum{n=2}^{M} |X(nf_0)|^2}{|X(f_0)|^2}} \times 100%$$

If the measured THD is too high (exceeding a strict $5%$ threshold), indicating mechanical clipping or severe rattling, the closed-loop handshake automatically caps the transmit gain. This feedback loop actively drives the speakers and microphones into their linear operating regions before data transmission begins.


📡 Agile Frequency Fallbacks (Without Going Insane)

Ultrasonic communication is wonderful because it is completely silent ($18.5\text{ kHz} - 21\text{ kHz}$). However, air absorption is extremely high at these frequencies, and obstacles block high frequencies easily.

If the link quality drops below our threshold and requires a fallback to the human-audible range, most legacy modems drop directly to $9\text{ kHz}$. Unfortunately, a $9\text{ kHz}$ tone or sweep is highly audible and can be quite irritating to human ears.

Cyrinx introduces a Frequency-Agile Fallback Band strategy:

  • Ultrasonic (Primary): $18.5\text{ kHz} - 21\text{ kHz}$. (Inaudible, $2.5\text{ kHz}$ bandwidth).
  • Audible Fallback (Secondary): $3\text{ kHz} - 6\text{ kHz}$.

If we must fall back into the audible band, we bypass the $9\text{ kHz}$ region entirely and jump straight down to $3 - 6\text{ kHz}$. By dropping down into this lower acoustic spectrum, we exploit the absolute peak of transducer sensitivity and range on typical mobile hardware. The sound becomes a warmer, low-frequency acoustic chirp rather than a high-pitched metallic squeal, providing superior propagation while being far more tolerable.


📊 Performance Benchmarks & HIL Results

To validate the robustness of our transport session and the rate-adaptive downshift logic, we executed a series of rigorous benchmarks using both our deterministic in-memory simulator and physical hardware targets (MacBook Pro Master and Pixel 7a Slave).

1. Deterministic Channel Profiles (Simulation)

We ran 120-packet benchmarks across three distinct channel presets, measuring packet delivery rates, frame counts, and final stabilized transmission gears:

Profile Simulated Environment Packets Transmitted Packets Delivered Failures / Resets Final Gear Goodput (Bps)
Quiet Desktop High SNR ($31\text{ dB}$), low CFO drift 120 120 0 / 0 turboQPSK (G3) $1023.99\text{ Bps}$ (~$8.19\text{ kbps}$)
Moving Phone Active CFO Doppler sweeps ($\pm 58\text{ Hz}$) 120 120 0 / 0 turboQPSK (G3) $1023.99\text{ Bps}$ (~$8.19\text{ kbps}$)
Office Burst Severe transient noise, $35%$ CRC fail probability 120 120 4 / 0 robust (G2) $449.99\text{ Bps}$ (~$3.60\text{ kbps}$)

Key Takeaway: Under optimal conditions and active motion, the rate-adaptive policy cleanly upshifts to turboQPSK to maximize goodput. When subjected to severe office noise and burst interference, the core safely downshifts to robust mode, maintaining 100% packet delivery via transport-level ACKs and retransmissions.

2. Over-The-Air Symmetrical HIL Trials

In our physical target runs (symmetrical bidirectional setups over actual air-coupled local links with $\text{tx_gain} = 0.35$ and a $\text{sync_threshold} = 0.12$):

  • MacBook Pro Master successfully received and demodulated 6 logical messages over-the-air from the Pixel 7a Slave.
  • Android Slave successfully locked onto the orthogonal preambles and recorded the primary capacity handshake packets, establishing a stable symmetrical exchange of addressable channel counts.
  • The link successfully maintained phase coherence, automatically configuring the correct transmit gain caps based on real-time THD measurements.

🔮 What’s Next?

With the capacity handshake and spatial solver firmly in place, the path is clear for our next sprint. We are currently implementing:

  • LDPC Forward Error Correction (FEC) profiles (Rate 1/2 and 2/3) to reduce transport-level retries.
  • Incremental Redundancy HARQ combining at the block level.
  • Active phase tracking over payload symbols to fully enable stable 16-QAM in moving-phone scenarios.

The code is fully open-source. Check out the repository, run the simulator, and try the HIL CLI for yourself:

👉 GitHub Repository: dweekly/cyrinx

If you’ve been experimenting with local-first physical layer protocols, acoustic communications, or SVD-based equalizers, let me know! I would love to swap notes.