Creating IIR Filters

Interested in experimenting with some IIR filters from this site...

www.schwietering.com/jayduino/filtuino/

Is this the process?

1) Create a library for the filter function(s). 2) Define filter type and calculate coefficients from the above site. 3) Copy the generated code to the created library. 4) Add library function(s) calls to sketch. 5) Run the sketch and evaluate results.

If only interested in a few known frequencies and frequency bands, does anyone know how efficient IIR filters are relative to FFT/FHT? Since IIR is much more frequency-tailor-able, unneeded bin data isn't calculated like with FFT/FHT.

There is no need to use a libiary just include the code in you sketch before setup() and loop().

It is not very optimized code because the samples are shuffled up on each call. What you need to do is to have a circular buffer and move the input / output pointers rather than all the data.

does anyone know how efficient IIR filters are relative to FFT/FHT?

Yes 6.

Now what exactly do you mean? There is a lot less calculations with an IIR filter but the calculations are floating point which slows things down. You can apply this filter to each sample as it comes in, or you can load a short burst of samples into a buffer and apply that. However an IIF filter does take some time to "settle down" so the number of samples you have to take might be more than you might expect.

An FFT gives you the magnitude of the output in each bin, where as an IIR filter gives you a series of samples representing the waveform. If you want to know the peak then you have to find it by searching the output samples. That is once the output has settled down.

Actually, you'd compute the RMS value of the filtered signal to get something comparable to the sum of magnitudes (real and imaginary components combined) of the FFT's bins which span the range of the filter's passband.

But finding the peak is much easier. Or at least so it seems, but like so many things in DSP, hidden gotchas await. Consider the case of a sine wave at 1/4 the sample frequency. Here's an image to help with that visualization...

|500x272

If you implement peak detection using the simplest approach of just remember the largest sample value over some window of time, you could entirely miss the peaks if in these sorts of cases. Of course for waveforms that are very low frequencies relative to the sample rate, the worst case error become much less, but never zero. The amount of error varies greatly depending on the waveform's phase relationship to the sampling frequency, which has the practical effect of seeming like a random or intermittent or "flaky" problem if your signals are arbitrary real-world signals that can be at any random phase.

Also, if you applied a window to your signal before computing the FFT, which of course you must do for arbitrary signals like real sounds which aren't perfectly repeating at an exact multiple of the FFT length (well, unless you're ok with the FFT results corrupted by spectral leakage), don't forget the window you chose has the net effect of scaling the magnitude of your FFT bins.

[/quote][quote author=Paul Stoffregen link=msg=2880872 date=1471160614] Actually, you'd compute the RMS value of the filtered signal to get something comparable to the sum of magnitudes (real and imaginary components combined) of the FFT's bins which span the range of the filter's passband. [/quote] I think what you are saying is the RMS of the sound samples is equal to the RMS of the FFT. Both give you the sound power.