I have a tone generator in SigmaStudio connected to a filter and then a peak detector. When I turn the tone on, I get the expected peak value. However, when I turn the tone off, the value doesn't quite reach zero. It just decays to a very small number. When I remove the filter and try again, the output value goes to zero. What's going on? Is this a bug?
This is not a bug. What you are seeing is a limitation in the biquad implementation of the IIR filters. IIR filters in the biquad architecture have several feedback loops that are summed with the input signal.
(image from Wikimedia Commons)
If the input signal instantly goes to zero, then x[n] becomes 0, and on the subsequent sample x[n-1] becomes 0, and on the subsequent sample x[n-2] becomes 0. However, -a1*x[n-1] and –a2*x[n-2] are being added back into the input signal, and b1*x[n-1] and b2*x[n-2] are being added into the output signal, y[n].
With infinite precision, the output will eventually fade to zero. However, a fixed-point DSP does not have infinite precision. The coefficients (a1, a2, b0, b1, b2) are quantized when they are stored in memory, along with the audio data. This means that at some point, the audio signal and the coefficients become very small, but due to rounding in the calculation, they may reach an idle value (or oscillating idle tone) instead of decaying completely to zero.
Slide 12 of this lecture from the University of Texas shows a good example of how quantization of coefficients causes the impulse response of a filter to decay to a nonzero value.
In this example image (taken from the lecture in the above link), the filter's impulse response decays to a fixed value. In some cases, the filter output decays to an oscillating signal with a fixed amplitude instead of a single value. This is referred to as a “Limit Cycle.”
More information on this topic can also be found here at the Bores DSP course site.
So, this is not a SigmaDSP or SigmaStudio bug. It’s just a limitation of fixed-point IIR filter design.
Switching to double-precision filters usually will alleviate this limit cycle issue.
This FAQ was generated from the following discussion: My IIR filter is outputting a value, even when the input goes to zero. Is this a bug?