1
$\begingroup$

I am designing an IIR filter with fixed-point arithmetic and I have to select the proper length for the accumulator and product. I would like to know a standard to follow in order to choose its length. I have selected the Direct Form 1 topology to implement a 6th order digital filter (instead of a cascaded second-order block), as it has only only one point where the sum is done and thus only one point which has to be taken care of when considering quantification error and overflow (correct me if I am wrong!).

For the ACCUMULATOR, I assume that I have to consider the worst case of summing numbers with N bits, so the answer should be N+M bits to avoid overflow, where M represents the quantity of numbers which it is summed.

For the PRODUCT, multiplying two numbers of N bits, in the worst scenario gives us a N+N=2N bits result.

I don't know if it is this easy or if I am skipping an important concept.

If you have experience in this field, any documentation about designing IIR filters on microcontrollers will be welcomed.

$\endgroup$
  • $\begingroup$ Hi! Your basic understanding seems (to me) right, however one thing caught my attention that you care about accuracy and can sacrifice efficiency but then designing an IIR filter and using a microcontroller ? A little bit conflicting ? $\endgroup$ – Fat32 Jul 13 at 23:09
  • $\begingroup$ Hi! Yes, I know it sounds quite strange, but it is for an university project. I know that we can design a FIR filter to avoid stability problems and other disadvantages of the IIR. However, for the sake of knowledge and experience, we want to implement it with an IIR. When I said "I don't mind using many resources inefficiently", I didn't really mean that. We can't just use 64 bits of word length when we really just needed fewer. What I meant was that our microcontroller is powerful enough to support what we need. However, thanks for pointing out the confusion my post could cause!!! $\endgroup$ – Kevin Jul 13 at 23:55
2
$\begingroup$
  1. Fixed point processing is very difficult. Floating point is A LOT easier.
  2. The best algorithm and scaling approach depends a lot on your specific filter and the statistics of your signal. There is no "one size fits all" solution.
  3. Cascaded second order sections are almost always the way to go. Primarily they guarantee that your coefficients values are bounded to something reasonable (2 or less). With transfer function implementation the coefficients tend to get really large or really small wich generates a lot of noise or scaling problems.
  4. Within each section, use either Direct Form I or Transposed Form II. This helps controlling the scaling of the state variables and intermediate result
  5. The best way to approach this to use "Q notation" https://en.wikipedia.org/wiki/Q_(number_format) to determine for EVERY SINGLE operation, which bits to use for what purpose. Doing this analysis will determine which bits to compute and which bits to keep (using multiplies, shifts, adds and masks).
  6. Sometimes you need to treat this as a statistical problem. In many cases doing conservative scaling results in very poor signal to noise ratio, so you need to trade off the probability of clipping versus your steady state signal to noise. That's highly dependent on your signal, the specific filter and the requirements of your application.
  7. You also need to carefully control your clipping and rounding behavior to avoid wrap-arounds and limit cycles.
$\endgroup$
  • $\begingroup$ Yeah exactly, except once you've done an IIR in fixed point, it is not that hard to do it again. $\endgroup$ – Ben Jul 14 at 15:58
  • $\begingroup$ Hi! Thanks for your reply! Regarding to point 6. I would like to know what do you mean with doing conservative scaling $\endgroup$ – Kevin Jul 14 at 17:57
  • 2
    $\begingroup$ Conservative scaling means, that you pre-attenuate the signal or the coefficients that even the worst case signal won't overflow your output. The worst case signal is a function of the filter and the math behind this is not trivial. If you want to know more, please ask a separate question around this topic. $\endgroup$ – Hilmar Jul 14 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.