4 years, 11 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 :


#include "mbed.h"
// Initialize a pins to perform analog input and digital output fucntions
AnalogIn  ain(A0);
DigitalOut dout(LED1);
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){
float a[3]={1,-1.1430,0.4128};
float b[3]={0.0675,0.1349,0.0675};
static float x[3],y[3];
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]) ;
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);
            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.