Skip to content

Ron12777/198

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Active Noise Cancellation on Raspberry Pi

Project Structure

  • 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, add src/ 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.

Prerequisites

  1. MATLAB with Audio Toolbox + Raspberry Pi Support Package.
  2. Raspberry Pi 4 reachable at 10.42.0.250 (edit the host scripts if your IP/credentials differ).
  3. ALSA capture/playback devices configured as described in docs/Project Info.txt (I2S mics + PWM playback).

Workflow

  1. Calibrate the secondary path
    • In MATLAB, cd into host/ and run deploy_calibration (or deploy_calibration_and_runtime to do both stages sequentially).
    • The script deploys anc_calibrate_deploy to the Pi; it plays ~20 s of white noise and writes /home/pi/anc/anc_S.bin (consumed by anc_run). A companion /home/pi/anc/anc_S.mat is only produced when you run anc_calibrate directly inside MATLAB for debugging.
  2. Run ANC
    • Still in host/, run deploy_runtime (or reuse deploy_calibration_and_runtime after calibration).
    • This builds/deploys anc_run_deploy so the ANC loop executes on the Pi. Stop it via Ctrl+C in MATLAB.
  3. Recalibrate when hardware changes
    • Anytime the speaker/mic geometry changes, rerun deploy_calibration before deploy_runtime so anc_S.bin stays in sync.

Audio Bring-up / Mic Self-test

  1. Enable the I2S stack (Pi config)
    • Edit /boot/firmware/config.txt and ensure the [all] section contains:
      dtparam=i2s=on
      dtoverlay=googlevoicehat-soundcard
      dtoverlay=audremap,pins_12_13
      
    • Reboot, then run /usr/bin/dtoverlay -l and arecord -l. The capture card should appear as snd_rpi_googlevoicehat_soundcar (typically plughw:1,0).
  2. 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).
  3. Run the mic self-test
    • From MATLAB, cd into Assorted Testing Garbage/ and run run_mic_selftest to deploy mic_selftest via deploy.
    • After it finishes, read /home/pi/anc/mic_selftest_report.txt on the Pi. Both channels must report non-zero RMS before proceeding with calibration.

Notes

  • Do not call the deploy wrappers (anc_calibrate_deploy, anc_run_deploy) directly from the host MATLAB prompt; they are entry points for deploy(board,...) and expect to run on the Pi.
  • anc_run reads the secondary-path taps from /home/pi/anc/anc_S.bin using fopen/fread; the .mat file 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 plus codegen/ 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 play calls at the same frame size (256) on the Pi; playblocking is not available, and mixing buffer sizes causes size-lock errors.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors