8 years, 3 months ago.

Audio Filter with PWM Out

Hi, I'm currently trying to make Audio Filter with microphone Input and PWM output to speaker. The filter is digital filter IIR, but i'm having problem and several question.

1. do i need to count frequency to make it work, because the filter is for frequency used? there the whole program :

filter

#include "mbed.h"
 
// Initialize a pins to perform analog input and digital output fucntions
AnalogIn  ain(A0);
DigitalOut dout(LED1);
PwmOut PW(PWM_OUT);
int i=0;
float DCC;
float PWM2;
float ptes;
float koe;
float meas, ADCdata;
float data_in, data_out, filter;
Ticker s5khz_tick;
float n; 
void s5khz_task(void);

void s5khz_task(void){
PW.period(0.0002f); 
DCC=(ain.read_u16()/16);
data_in=DCC;
float a[3]={1,-1.1430,0.4128};
float b[3]={0.0675,0.1349,0.0675};
static float x[3],y[3];
x[0]=DCC;
x[2]=x[1]; x[1]=x[0];
y[2]=y[1]; y[1]=y[0];
 

y[0]=(b[0]*x[0]) + (b[1]*x[1]) +(b[2]*x[2]) + (a[1]*y[1]) + (a[2]*y[2]) ;
PW.write(y[0]/4095.0f);
}
int main(void)
{
            printf("DOTO : %f \n\r",ADCdata);
            printf("\nADC: %f \n", DCC);
            printf("\npercentage: %3.3f%%\n", ain.read()*100.0f);
            printf("\nmeasure = %.0f mV\n", meas);
            s5khz_tick.attach_us(&s5khz_task,200);
            while (1) ;
            
    
}

with the Input (Function Generator) or Microphone to Pre-Amp Circuit then clamper circuit. output clamper to Input Nucleo board Pin A0. currently i used STMF401RE board.

i can't get it work, the PWM seem have static duty cycle 50% which i tested with function generator sinewave 10 - 5000 Hz. please help me out.

Thank in advanced.

Be the first to answer this question.