low_filter.h typedef struct
{
int16_t Input;
int16_t Output[2];
int32_t FilterTf;
int32_t FilterTs;
int32_t Kr;
int32_t Ky;
} low_filter;
void low_filter_init(low_filter *v);
int16_t low_filter_calc(low_filter *v);
low_filter.c void low_filter_init(low_filter *v){
v->Kr = v->FilterTs*1024/(v->FilterTs + v->FilterTf);
v->Ky = v->FilterTf*1024/(v->FilterTs + v->FilterTf);
}
int16_t low_filter_calc(low_filter *v){
int32_t tmp = 0;
tmp = ((int32_t)v->Kr*v->Input + v->Ky*v->Output[1])/1024;
if(tmp>32767){
tmp = 32767;
}
if( tmp < -32768){
tmp = -32768;
}
v->Output[0] = (int16_t)tmp;
v->Output[1] = v->Output[0];
return v->Output[0];
}
|