用matlab实现
/*
*@breif: low filter
*
*pSourceDataBuf[in] : source data to input to filter
*u8SourceDataBufLen[in] : source data length
*pDestDataBuf[out] : filtered data buffer
*Y_PRE[in/out]: global variant
*X_PRE[in/out]: global variant
*
*return: 0(SUCCESS)/-1(FAILURE)
*/
//psource--6
int8 low_filter_N5(double *pSourceDataBuf,uint8 u8SourceDataBufLen,double *pDestDataBuf,double *Y_PRE,double *X_PRE)
{
double Y[N_LOW + 1] = {0.0};
int8 iLopOut = 0;
int8 iLopIn = 0;
// init
for(iLopOut = 0; iLopOut < N_LOW + 1; iLopOut++)
{
Y[iLopOut] = 0.0;
}
A_LOW[0] = 0.0;
// calculate 0~5
for(iLopOut = 0; iLopOut < N_LOW + 1; iLopOut++)
{
// 前面这部分说明过去的X,可以在输入中找到。比如Y(2),
// 那输入的X(0) X(1)可以使用。剩下的Xpre(0)-X(2)Xpre(1)-X(3)
// Xpre(2)-X(4) Xpre(3)-X(5)就使用全局变量。这里计算分开了两次,
// 根据输入序列是否可作为历史记录使用来区分。这里的X(5)是指过去的第5个数据。
for(iLopIn = 0; iLopOut >= iLopIn; iLopIn++)
{
Y[iLopOut] += B_LOW[iLopIn]*pSourceDataBuf[iLopOut - iLopIn] - A_LOW[iLopIn]*Y[iLopOut - iLopIn];
}
//iLopIn=1 <= iLopOut=0
//Y[0] = B_LOW[0]*pSourceDataBuf[0] - A_LOW[0]*Y[0];
//iLopIn=5<6 iLopOut=0
//Y[0] = B_LOW[0]*pSourceDataBuf[0] - A_LOW[0]*Y[0];
// +B_LOW[1]*X_PRE[0] - A_LOW[1]*Y_PRE[0]
// +B_LOW[2]*X_PRE[1] - A_LOW[2]*Y_PRE[1]
// +B_LOW[3]*X_PRE[2] - A_LOW[2]*Y_PRE[2]
// +B_LOW[4]*X_PRE[3] - A_LOW[4]*Y_PRE[3]
// +B_LOW[5]*X_PRE[4] - A_LOW[5]*Y_PRE[4]
// iLopOut = 1; Int 5
//Y[1] = B_LOW[0]*pSourceDataBuf[1] - A_LOW[0]*Y[1]
// + B_LOW[1]*pSourceDataBuf[0] - A_LOW[1]*Y[0]
// +B_LOW[2]*X_PRE[0] - A_LOW[2]*Y_PRE[0]
// +B_LOW[3]*X_PRE[1] - A_LOW[2]*Y_PRE[1]
// +B_LOW[4]*X_PRE[2] - A_LOW[4]*Y_PRE[2]
// +B_LOW[5]*X_PRE[3] - A_LOW[5]*Y_PRE[3]
for(; iLopIn < N_LOW + 1; iLopIn++)
{
Y[iLopOut] += B_LOW[iLopIn]*X_PRE[iLopIn - iLopOut - 1] - A_LOW[iLopIn]*Y_PRE[iLopIn - iLopOut - 1];
}
}
A_LOW[0] = 1.0;
for(iLopOut = 0; iLopOut < N_LOW; iLopOut++)
{
X_PRE[iLopOut] = pSourceDataBuf[N_LOW - iLopOut];
Y_PRE[iLopOut] = Y[N_LOW - iLopOut];
}
// backwards 6 datas
// X_PRE[0] = pSourceDataBuf[N]; Y_PRE[0] = Y[N_LOW ];
// X_PRE[1] = pSourceDataBuf[N-1]; Y_PRE[1] = Y[N_LOW-1];
// X_PRE[2] = pSourceDataBuf[N-2]; Y_PRE[2] = Y[N_LOW-2];
// X_PRE[3] = pSourceDataBuf[N-3]; Y_PRE[3] = Y[N_LOW-3];
// X_PRE[4] = pSourceDataBuf[N-4]; Y_PRE[4] = Y[N_LOW-4];
// X_PRE[5] = pSourceDataBuf[N-5]; Y_PRE[5] = Y[N_LOW-5];
for(iLopOut = 0; iLopOut < N_LOW + 1; iLopOut++)
{
pDestDataBuf[iLopOut] = Y[iLopOut];
}
return 0;
}
,