- src/ - MATLAB source for calibration/ANC plus deploy wrappers (
anc_calibrate.m,anc_run.m,anc_calibrate_deploy.m,anc_run_deploy.m). - host/ - Host-side deployment scripts (
deploy_calibration.m,deploy_runtime.m,deploy_calibration_and_runtime.m). They configure the Pi connection, addsrc/to the path, and invoke deploy. - docs/ - Design/requirements references (
codex-spec.md,Project Info.txt). - build/ - Artifacts produced by MATLAB code generation (e.g., ELF binaries). MATLAB may also create a
codegen/folder automatically. - Assorted Testing Garbage/ - Scratch utilities such as the mic self-test harness.
- MATLAB with Audio Toolbox + Raspberry Pi Support Package.
- Raspberry Pi 4 reachable at
10.42.0.250(edit the host scripts if your IP/credentials differ). - ALSA capture/playback devices configured as described in
docs/Project Info.txt(I2S mics + PWM playback).
- Calibrate the secondary path
- In MATLAB,
cdintohost/and rundeploy_calibration(ordeploy_calibration_and_runtimeto do both stages sequentially). - The script deploys
anc_calibrate_deployto the Pi; it plays ~20 s of white noise and writes/home/pi/anc/anc_S.bin(consumed byanc_run). A companion/home/pi/anc/anc_S.matis only produced when you runanc_calibratedirectly inside MATLAB for debugging.
- In MATLAB,
- Run ANC
- Still in
host/, rundeploy_runtime(or reusedeploy_calibration_and_runtimeafter calibration). - This builds/deploys
anc_run_deployso the ANC loop executes on the Pi. Stop it via Ctrl+C in MATLAB.
- Still in
- Recalibrate when hardware changes
- Anytime the speaker/mic geometry changes, rerun
deploy_calibrationbeforedeploy_runtimesoanc_S.binstays in sync.
- Anytime the speaker/mic geometry changes, rerun
- Enable the I2S stack (Pi config)
- Edit
/boot/firmware/config.txtand ensure the[all]section contains:dtparam=i2s=on dtoverlay=googlevoicehat-soundcard dtoverlay=audremap,pins_12_13 - Reboot, then run
/usr/bin/dtoverlay -landarecord -l. The capture card should appear assnd_rpi_googlevoicehat_soundcar(typicallyplughw:1,0).
- Edit
- Verify wiring
- Both INMP441 boards share the same bus: BCLK -> GPIO18 (pin 12), LRCLK -> GPIO19 (pin 35), DIN -> GPIO20 (pin 38), 3V3 -> pin 1/17, GND -> pin 6/9/etc.
- Strap the reference mic's L/R pin to GND (left channel) and the error mic's L/R pin to 3V3 (right channel).
- Speaker/amp: PWM left channel on GPIO12 (pin 32) -> 220 ohm -> junction -> 100 ohm -> filtered node -> three 0.01 uF caps to the GND rail; filtered node to PAM8302 A+, A- to GND, VIN to pin 2 (5 V).
- Run the mic self-test
- From MATLAB,
cdintoAssorted Testing Garbage/and runrun_mic_selftestto deploymic_selftestvia deploy. - After it finishes, read
/home/pi/anc/mic_selftest_report.txton the Pi. Both channels must report non-zero RMS before proceeding with calibration.
- From MATLAB,
- Do not call the deploy wrappers (
anc_calibrate_deploy,anc_run_deploy) directly from the host MATLAB prompt; they are entry points fordeploy(board,...)and expect to run on the Pi. anc_runreads the secondary-path taps from/home/pi/anc/anc_S.binusingfopen/fread; the.matfile is only for offline inspection when available.- All MATLAB source lives under
src/; add it to your path if you open files directly outside the host scripts. - The
Assorted Testing Garbage/folder also contains the generated ELF pluscodegen/artifacts if you need to redeploy manually on the Pi. - Playback is on the left PWM pin (GPIO12). If your RC filter is on GPIO13, move the wire or adjust the code/device usage back to right channel.
- Keep audio
playcalls at the same frame size (256) on the Pi;playblockingis not available, and mixing buffer sizes causes size-lock errors.