任务要求.设计一个采样率fs=2048k,截止频率fc = 22k,step = 8;设计IIR的低通滤波器
1.基于matlab的滤波器设计工具导出系数
经过换算
double m_numer8Step[4][3] = { { 0.001123681664, 0.002247363328000, 0.001123681664 },
{ 0.001097349217, 0.002194698434000, 0.001097349217 },
{ 0.001078014262, 0.002156028524000, 0.001078014262 },
{ 0.001067831763, 0.002135663526000, 0.001067831763 } };
double m_denom8step[4][3] = { { 1, -1.969531655, 0.9740264416 },
{ 1, -1.923377514, 0.9277669191 },
{ 1, -1.88948822, 0.8938002586 },
{ 1, -1.871640801, 0.8759121299 } };
C++滤波器设计函数:
*******************************************************************/
//Name: IIRlowPassSignalModel
//Description: IIR lowPass step = 8, fs = 2048k, fc = 22k
//Calls:
//inputData: 滤波输入值
//Return: 滤波后的值
double CAlgorithm::IIRlowPassSignalModel(const double numer2Step[3], const double denom2Step[3], const double inputData)
{
static double DataIn[3] = { 0,0,0 };
static double DataOut[3] = { 0,0,0 };
DataIn[0] = inputData;
DataOut[0] = numer2Step[0] * DataIn[0] + numer2Step[1] * DataIn[1] + numer2Step[2] * DataIn[2] //正反馈
- denom2Step[1] * DataOut[1] - denom2Step[2] * DataOut[2]; //负反馈
DataOut[2] = DataOut[1];
DataOut[1] = DataOut[0];
DataIn[2] = DataIn[1];
DataIn[1] = DataIn[0];
return DataOut[0];
}
// 级联2阶低通滤波器
double CAlgorithm::CascadeFilter(const double numer8Step[4][3], const double denom8step[4][3], const double inputData)
{
double output1 = 0.0f;
double output2 = 0.0f;
double output3 = 0.0f;
double output4 = 0.0f;
output1 = IIRlowPassSignalModel(numer8Step[0], denom8step[0], inputData);
output2 = IIRlowPassSignalModel(numer8Step[1], denom8step[1], output1);
output3 = IIRlowPassSignalModel(numer8Step[2], denom8step[2], output2);
output4 = IIRlowPassSignalModel(numer8Step[3], denom8step[3], output3);
return output4;
}
void CAlgorithm::Algorithm(const float *pdInput, int InputSize, int& OutputSize, float& OutputRate, float** OutputA)
{
m_OutputBuf.resize(InputSize);
m_input.resize(InputSize);
for (int idx = 0; idx < InputSize; idx++)
{
m_OutputBuf[idx] = CascadeFilter(m_numer8Step, m_denom8step, pdInput[idx]);
m_input[idx] = pdInput[idx];
}
//输出信号速率
OutputRate = m_filterFsHz;
//输出数据大小
OutputSize = m_OutputBuf.size();
//端口输出
if (OutputSize>0)
{
*OutputA = &m_OutputBuf[0];
}
}