Issue with IIR Filter demo

Hi !

I wanted to try the demo code of IIR filter shown in “Chapter 13 : Working with Digital Audio”, but my oscilloscope can’t achieve to capture the output signal

#include “mbed.h”

AnalogIn Ain(p15);
AnalogOut Aout(p18);

Ticker s20khz_tick;

void s20khz_task(void);

float data_in, data_out;

float LPF(float LPF_in){

float a[4]={1,2.623551806,-2.3146825811,0.6855359773};
float b[4]={0.0006993496,0.0020980489,0.0020980489,0.0006993496};

static float LPF_out;
static float x[4],y[4];

x[3] = x[2];x[2]=x[1];x[1]=x[0];
y[3]=y[2];y[2]=y[1];y[1]=y[0];

x[0]=LPF_in;
y[0]=LPF_in;
y[0]=(b[0]*x[0]) + (b[1]*x[1]) +(b[2]*x[2]) + (b[3]*x[3]) + (a[1]*y[1]) + (a[2]*y[2]) + (a[3]*y[3]);

LPF_out = y[0];
return LPF_out;
}

void s20khz_task(void){
data_in=Ain;
data_out=LPF(data_in);
Aout=data_out;
}

int main() {
s20khz_tick.attach_us(&s20khz_task,50);
while(1);
}

Do you have any idea ?

Thanks a lot !

Hi,

Try
Aout.write(data_out);
instead of Aout(data_out);
It should help.
https://os.mbed.com/docs/mbed-os/v5.15/apis/analogout.html#analogout-example

Regards,
Pekka

Hi,

Thanks for your replie !

I also saw an issue in the code :
x[0]=LPF_in;
y[0]=LPF_in;
is false.
I needed to delete the last line and it works perfectly !