参考出处:https://wenku.baidu.com/view/6a8eeeee9fc3d5bbfd0a79563c1ec5da50e2d6e5.html

实现:

MATLAB的filter滤波函数为:

a=[1.0000;
0;
0.4860;
0;
0.0177];
b=[0.0940;
0.3759;
0.5639;
0.3759;
0.0940];

SignalFilter=filter(b,a,OriginalSignal);

C代码的filter滤波程序为:

int OriginalSignal[100];
float a[5]={1,0,0.4860,0,0.0177};
float b[5]={0.0940,0.3759,0.5639,0.3759,0.0940};

//滤波 5阶的
SignalFilter[0]=b[0]*OriginalSignal[0];
SignalFilter[1]=b[0]*OriginalSignal[1] + b[1]*OriginalSignal[0] – a[1]*SignalFilter[0];
SignalFilter[2]=b[0]*OriginalSignal[2] + b[1]*OriginalSignal[1] + b[2]*OriginalSignal[0] – a[1]*SignalFilter[1]- a[2]*SignalFilter[0] ;
SignalFilter[3]=b[0]*OriginalSignal[3] + b[1]*OriginalSignal[2] + b[2]*OriginalSignal[1] + b[3]*OriginalSignal[0]- a[1]*SignalFilter[2]- a[2]*SignalFilter[1]- a[3]*SignalFilter[0] ;

for (int i=4;i<100;i++)
{
SignalFilter[i]=b[0]*OriginalSignal[i] + b[1]*OriginalSignal[i-1] + b[2]*OriginalSignal[i-2] + b[3]*OriginalSignal[i-3]+ b[4]*OriginalSignal[i-4]- a[1]*SignalFilter[i-1]- a[2]*SignalFilter[i-2] – a[3]*SignalFilter[i-3] – a[4]*SignalFilter[i-4] ;
}

SignalFilter结果相同

版权声明:本文为rjjhyj原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/rjjhyj/p/9254290.html