原子的这个IIR滤波是怎么实现的?看不懂是表达的那个公式。有人讨论下吗?
#define IIR_SHIFT 8
/**
* IIR滤波.
*/
int16_t iirLPFilterSingle(int32_t in, int32_t attenua
tion, int32_t* filt)
{
int32_t inScaled;
int32_t filttmp = *filt;
int16_t out;
if (attenuation > (1<
{
attenuation = (1<
}
else if (attenuation < 1)
{
attenuation = 1;
}
// Shift to keep accuracy
inScaled = in << IIR_SHIFT;
// Calculate IIR filter
filttmp = filttmp + (((inScaled-filttmp) >> IIR_SHIFT) * attenuation);
// Scale and round
out = (filttmp >> 8) + ((filttmp & (1 << (IIR_SHIFT - 1))) >> (IIR_SHIFT - 1));
*filt = filttmp;
return out;
}