hbaocr
Full Member level 4
here the LOW Pass filter code with NUM and DEN designed by matlab (sptool) that fsample=1KHZ;Fc=40Hz;ButterWorth IIR filter
#define pi acos(-1)
double Numerator[]={0.00018321602337,0.000732864093479,0.001099296140218,0.000732864093479,0.00018321602337};
double Denominator[]={1,-3.344067837711875,4.238863950884069,-2.409342856586321,0.517478199788041};
and then In the main program,the input data is
why it doesn't work????
Do anyone help me to make the filter work
#define pi acos(-1)
double Numerator[]={0.00018321602337,0.000732864093479,0.001099296140218,0.000732864093479,0.00018321602337};
double Denominator[]={1,-3.344067837711875,4.238863950884069,-2.409342856586321,0.517478199788041};
Code:
void CVedothiDlg::Low_pass_filter(double *NUM,double *DEN,double *sample,double data_update,double *output,unsigned int length_output_data)
{
unsigned char i;
sample[4] =sample[3];
sample[3] =sample[2];
sample[2] =sample[1];
sample[1] =sample[0];
sample[0]=data_update;
//buffer output
for(i=length_output_data;i>0;i--)
{
output[i]=output[i-1];
}
//update output data
output[0]=NUM[0]*sample[0]+NUM[1]*sample[1]+NUM[2]*sample[2]+NUM[3]*sample[3]+NUM[4]*sample[4]-DEN[1]*output[1]-DEN[2]*output[2]-DEN[3]*output[3]-DEN[4]*output[4];
}
Code:
void CVedothiDlg::OnPlot()
{
// TODO: Add your control notification handler code here
int i;
DOUBLE y[1000];
DOUBLE x[4];
DOUBLE data;
for(i=0;i<1000;i++)
{
data=sin(2*pi*i/1000)+sin(2*pi*500*i/1000);
Low_pass_filter(Numerator,Denominator,x,data,y,1000);
Scope.Channels[0].Data.SetYData(y,1000) ;//draw signal output
}
}
Do anyone help me to make the filter work