So IIR requires a lot of nasty mathematics. With risk of looking stupid ... isn't it possible to calculate these coefficients from a signal and it's filtered waveform by reversing the calculations in an already known algorithm. Like you would find the gain of an amplifier by processing an amplified signal and dividing it to the input signal, then maybe get the average gain value. Or varying the parameters of IIR (like changing the cut off frequency) would change the whole algorithm.
The algorithm doesn't change, but the algorithm required to calculate them is, as you say, mathy. Better to have a program generate the coefficients for you. It may be a problem, but it's a solved problem, at least!
Changing the cutoff frequency or gain, to a certain extent, might be as simple as multiplying all the coefficients by a proportion. But, I don't remember offhand if that is the case,
The first order IIR is the easiest to analyze: it's simply an RC filter, and is guaranteed stable (bounded) as long as the coefficient is negative. The smaller the coefficient is, the slower the accumulation decays, and the larger it grows due to having the input summed into it. Thus, the coefficient is proportional to the cutoff frequency, and inversely proportional to gain. (You usually have a final gain term to compensate for this, or choose a "lucky" gain like 256, as you say elsewhere.)
A single tap, you can think of as a maximum 90 degree phase shift for any frequency the filter can handle. So the feedback won't go unstable (180 degrees).
For any higher order, there is real delay (up to or beyond 180 degrees, at whichever frequencies) in the feedback loop, and the coefficients are very particular with regards to stability.
The usual design process is to follow a standard filter calculator like
http://www-users.cs.york.ac.uk/~fisher/mkfilter/ but there are ways to calculate an arbitrary filter response as well. (The FIR response is easier to measure, so is probably more appropriate where arbitrary frequency response is desired, even if it takes a pretty generous number of taps to achieve.)
I didn't understand that. A FIR filter with equal taps means that all the values in the sliding array are the same - rectangular window function. But you multiply the taps to the input signal and then sum it. How do you do that with addition only. When you say sliding average here is what pops in my head: a buffer (circular) with initially zeros in it. Data comes into the start of the buffer is summed and divided to number of samples. In case of MCU you get power of 2 buffer and use shift instead of divide. I like number 256 because then I can just ignore the least significant Byte. So I didn't get the "detltas" part and +1 at the start, -1 at the end.
This is what's lucky about the rectangular function: every output sample consists of equally weighted input samples n-1 to n-N (i.e., N previous inputs). Instead of performing N additions (the multiplications are for free if our filter is bit-aligned as you suggest), you take the previous output (we're cheating slightly by technically using one IIR feedback tap!), add input n-1 and subtract n-N.
The 0th order feedback term looks like an integrator, so instead of a rectangular window, you need the derivative, which is a delta at the start and a negative delta at the end. Which, of course, is simply adding the next sample and subtracting the last one out of the chain.
(Delta is simply the smallest pulse possible; in DSP, it's a single sample having a value of 1, the rest zero. delta(t) in real analysis is an imaginary function such that delta(0) is infinite, zero elsewhere, and Integral(delta(t) dt) = 1, so the pulse is infinitely tall, thin, but has a fixed area. The impulse response is the output when the input is a delta.)
Another convenient FIR is 1-3-3-1, which has reasonable frequency response, enough to "take the edge off", and can also be performed with additions and/or shifts. Notice it looks vaguely like a window function.
I don't think there are really any higher order windows with convenient numbers. Perhaps more results drawn from Pascal's triangle would be promising, but pretty quickly, even though the coefficients are integers, using multiplication starts to look so much easier.
"generating the impulse response" - like passing very short impulse through the filter, sampling the output and using the samples as our window function?
"suitable corrections" - like for example multiplying the taps by Hanning function?
So we sample, correct, normalize and then apply perform the convolution on the data from the ADC.
Yes!
Tim