首先开启DSP库
然后添加DSP库的头文件
参考armbbs硬汉大佬的数字信号教程,使用matlab设计一个FIR数字滤波器 #define TEST_LENGTH_SAMPLES 1024 //采样点数
#define BLOCK_SIZE 1 //调用一次arm_fir_f32处理的采样点个数
#define NUM_TAPS 29 //滤波器系数个数
uint32_t blockSize = BLOCK_SIZE;
uint32_t numBlocks = TEST_LENGTH_SAMPLES/BLOCK_SIZE; //需要调用arm_fir_f32的次数
static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; //状态缓存,大小numTaps + blockSize - 1
//数字低通滤波器系数 通过matlab命令fadtool获取
const float32_t firCoeffs32LP[NUM_TAPS] = {
0.004408003297, 0.005197565537, 0.007328365929, 0.01079409383, 0.01550024934,
0.02126707509, 0.02783845738, 0.03489634395, 0.04207972065, 0.04900695756,
0.0552999489, 0.0606084317, 0.06463276595, 0.06714358181, 0.0679968819,
0.06714358181, 0.06463276595, 0.0606084317, 0.0552999489, 0.04900695756,
0.04207972065, 0.03489634395, 0.02783845738, 0.02126707509, 0.01550024934,
0.01079409383, 0.007328365929, 0.005197565537, 0.004408003297
};
//数字低通滤波器
void arm_fir_f32_lp(float32_t *in,float32_t *out)
{
arm_fir_instance_f32 S;
float32_t *inputF32, *outputF32;
inputF32 = in;
outputF32 = out;
arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32LP[0], &firStateF32[0], blockSize);
//FIR滤波,每次处理1个点
for(int i=0; i < numBlocks; i++)
{
arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
}
}
|