Skip to content

Commit

Permalink
afskmdm: Simplify the IIR filter a bit
Browse files Browse the repository at this point in the history
Make the equations a little easier to understand.

Signed-off-by: Corey Minyard <[email protected]>
  • Loading branch information
cminyard committed Jan 7, 2025
1 parent 107e5f5 commit 0700efc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/gensio_afskmdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,7 @@ afskmdm_iir_filter(float *inbuf, float *outbuf, unsigned int nsamples,
unsigned int i;
float tmp;

/* hold[0] = z^-1, hold[1] = z^-2 */
for (i = chan; i < nsamples * nchans; i += nchans) {
tmp = inbuf[i] + coefa[0] * hold[0] + coefa[1] * hold[1];
outbuf[i] = tmp * coefb[0] + coefb[1] * hold[0] + coefb[2] * hold[1];
Expand All @@ -1705,11 +1706,12 @@ afskmdm_calc_iir_coefs(float samplerate, float cutoff,
{
float w1 = 2 * M_PI * cutoff / samplerate;
float w = tan(w1 / 2); /* omega */
float denom = w * w + M_SQRT2 * w + 1;
float w2 = w * w; /* omega ^ 2 */
float denom = w2 + M_SQRT2 * w + 1;

coefa[0] = - (2 * w * w - 2) / denom;
coefa[1] = - (1 - M_SQRT2 * w + w * w) / denom;
coefb[0] = (w * w) / denom;
coefa[0] = (2 - 2 * w2) / denom;
coefa[1] = - (1 - M_SQRT2 * w + w2) / denom;
coefb[0] = w2 / denom;
coefb[1] = 2 * coefb[0];
coefb[2] = coefb[0];
}
Expand Down

0 comments on commit 0700efc

Please sign in to comment.