Take the course at /learn/path/dsp-on-microcontrollers. It is an advanced course: it assumes the Uno course and is easier after Sound and audio.
The bench
Six lessons run on an Uno with a bench function generator on A0 (a sine from 0.5 to 4.5 V to start with) and a scope on the same pin. The filter lessons add a second generator, mains hum, averaged into A0 through two 10 k resistors; the beat lesson puts a third generator, a short pulse twice a second, on A1. Steps that change a frequency or a wave shape say which generator to set. The boss is an ESP32 with an INMP441 microphone, which plays a tone you set as the guitar string, and a 2.8 inch ILI9341 screen.
The lessons
Sampling and Nyquist. 1000 samples a second sees 100 and 400 Hz truly, 600 Hz as 400 and 900 Hz as 100; sampling at 2500 Hz fixes it.
Moving average and FIR. A 10-point average cancels 50 Hz hum exactly and fails at 60 Hz; a 15-tap windowed-sinc FIR is a general low-pass.
IIR filters. The exponential moving average, its time constant measured on a square wave: 9 samples at alpha 1/8, 33 at 1/32.
The FFT. arduinoFFT on 128 samples at 4000 Hz: bin 14 for 440 Hz, the odd harmonics of a square wave, and 2500 Hz folding to 1500.
Windowing. Leakage of a tone between bins with no window (7.2%) and with Hamming (1.1%) and Blackman (0.2%) windows.
Pitch and beat detection. Autocorrelation finds 110 Hz in a sine or a sawtooth; an onset detector finds 120 and 150 BPM.
Boss: a guitar tuner. Decimation, autocorrelation, the nearest string, cents, and a needle on the screen; one constant retunes it to A4 = 432.
The sketches
| Sketch | Board | What it does |
|---|---|---|
dsxsample |
Uno | Samples A0 and finds the frequency in the samples |
dsxfir |
Uno | Moving average and FIR on a signal with hum |
dsxiir |
Uno | Exponential moving average and its time constant |
dsxfft |
Uno | 128-point FFT, biggest bin and strong bins |
dsxwindow |
Uno | One capture through two windows, leakage compared |
dsxpitch |
Uno | Autocorrelation pitch and onset tempo |
dsxtuner |
ESP32 | The guitar tuner |
What the simulation leaves out
The generators are perfect: no noise beyond the ADC's own rounding. The INMP441 plays a pure tone where a guitar string has harmonics and a decay. Mokxi models the ESP32 without its floating-point unit, so the ESP32 sketch uses double throughout; a float there stops the board with a message.
Related
Sound and audio on microcontrollers and the INMP441 part page.