Electronic – arduino – Low pass audio filter design

arduinoaudiobasicfilter

I want my Arduino project to listen to the ambient music and sync its light show output to the beat.

It seems that doing BPM detection properly is fiendishly difficult in software, but if your music is sufficiently doofy in nature and you use a little bit of hardware you can cheat and get away with it.

So my plan is to hook a mic/opamp breakout board to a simple 1st order passive low-pass filter and sample the input on an interrupt every 5ms or so. Audacity tells me a bass beat is around 15ms long, so every 5ms should be plenty to make sure I don't, er, "miss a beat".

If my low-pass'd sample is over a volume threshold, I'll record the time since the last beat, do some kind of weighted average calculation over the past few samples and that will allow me to predict how many ms until the next beat (some other software trickery might be necessary to account for bass drops and breakbeats.)

Firstly, do I have roughly the right idea?

Secondly, can anyone tell me what order-of-magnitude values I'll need for the resistor and capacitor? I figure I want my cutoff frequency to be something like 500-1000Hz. I also gather the resistance of the rest of my circuit counts but I'm not sure where to measure that resistance across. A little fiddling with this tool gives me answers that look reasonable (500Hz = 330Ω/1uF) but I don't know enough to really know.

An example schematic showing where I measure the resistance of the existing circuit and where the low pass filter goes in the context of the rest would be exceedingly helpful.

Best Answer

A fair share of the spectral content of most music is below 500-1000 Hz, and with a fairly weak first-order filter falloff of 6 dB/octave, your waveform will be relatively unaffected. A much higher-order filter would be required, preferably at a much lower cutoff (440 Hz is concert A, bass hits should be way below that), with envelope detection (a diode and cap).

As you don't care about the actual fidelity of the audio, a passive filter should suffice, though the order required may significantly reduce your amplitude and reduce the effective resolution.

Addendum:

Just to reiterate other's concerns, the main problem of just filtering audio like this is that if you have some very loud hit (e.g. cymbal crash), it will still go through your LPF (low-pass filter) and give you spikes that you may interpret wrong. Another problem would be inability to cope with much dynamic range (music getting softer/louder); though you may be able to add some variable threshold.

As you've correctly stated, this approach will work best with Techno, but that still might not be very good.