十分感谢两位,这个是我写的关于此滤波算法的试验程序 。
#include <stdio.h>
#define NUM_sig 110
const float come[NUM_sig]={1,2,124,3,-80,5,6,7,8,9,-60,11,12,13,254,15,16,17,78,100,20,21,22,23,
24,25,26,27,28,-100,30,31,32,33,134,35,36,37,38,123,40,41,42,43,44,45,46,47,48,49,50,51,52,
53,54,55,56,57,123,59,60,61,62,63,64,65,66,67,68,69,70,123,72,73,74,75,76,77,10,79,80,81,
82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,12,104,105,106,107,108,109
};
float DT_LB(float Yn_1,float a,float get_AD)
{
float Yn ;
Yn=a*get_AD+(1-a)*Yn_1;
return Yn ;
}
void main(int argc, char* argv[])
{
float Y=1 ;
float LB_xs=0.01 ;
int i;
for(i=0;i<NUM_sig;i++)
{
Y=DT_LB(Y,LB_xs,come[i]) ; //滤波处理
printf("%0.0f,",Y);
}
}
|
假设定义的数流为
const float come[NUM_sig]={1,2,124,3,-80,5,6,7,8,9,-60,11,12,13,254,15,16,17,78,100,20,21,22,23,
24,25,26,27,28,-100,30,31,32,33,134,35,36,37,38,123,40,41,42,43,44,45,46,47,48,49,50,51,52,
53,54,55,56,57,123,59,60,61,62,63,64,65,66,67,68,69,70,123,72,73,74,75,76,77,10,79,80,81,
82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,12,104,105,106,107,108,109
}
系数是0.01 处理后的结果为
1,1,2,2,1,1,2,2,2,2,1,1,1,1,4,4,4,4,5,6,6,6,6,7,7,7,7,7,8,6,7,7,7,7,9,9,9,10,10,
11,11,12,12,12,12,13,13,13,14,14,15,15,15,16,16,16,17,17,18,19,19,20,20,20,21,21
,22,22,23,23,24,25,25,25,26,26,27,27,27,28,28,29,29,30,30,31,32,32,33,33,34,34,3
5,36,36,37,37,38,38,39,40,40,41,41,41,42,43,43,44,44
可以看到红色的值都滤掉了,可是这样的算法滞后特别严重,110个数据到最后只有44,我现在定义的滤波系数是0.01,这是否就得根据实际情况找个合适的值了???
系数是0.1的结果:
1,1,13,12,3,3,4,4,4,5,-2,-0,1,2,27,26,25,24,30,37,35,34,32,31,31,30,30,29,29,16,
18,19,20,22,33,33,33,34,34,43,43,43,43,43,43,43,43,44,44,45,45,46,46,47,48,48,49
,50,57,57,58,58,58,59,59,60,61,61,62,63,63,69,70,70,70,71,71,72,66,67,68,70,71,7
2,73,74,76,77,78,79,80,81,82,83,84,85,87,88,89,90,91,92,93,85,87,88,90,92,93,95, |