iirfilter_3.c

来自「用于TM1300/PNX1300系列DSP(主要用于视频处理)的各种滤波器源码」· C语言 代码 · 共 43 行

C
43
字号
    
#include <stdlib.h>
#include <math.h>

int iirFilter_3( float *inputData, float *outputData, 
                 float *coeff, float *state, int sampleNumber )
{
    int i;
    float * restrict input, * restrict output;
    float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
    float coeff_a0, coeff_a1, coeff_a2, coeff_b1, coeff_b2;
    float state_0, state_1, state_2, state_3;

    input = inputData; output = outputData;
    coeff_a0 = coeff[0]; coeff_a1 = coeff[1]; coeff_a2 = coeff[2];
    coeff_b1 = coeff[3]; coeff_b2 = coeff[4];
    state_0 = state[0]; state_1 = state[1]; 
    state_2 = state[2]; state_3 = state[3];

    for( i=0; i < sampleNumber; i++ )
    {
        temp1 = coeff_a0*input[i];
        temp2 = coeff_a1*state_0;
        temp3 = coeff_a2*state_1;
        temp4 = coeff_b1*state_2;
        temp5 = coeff_b2*state_3;

        temp6 = temp1 + temp2; temp7 = temp3 - temp4;
        temp8 = temp6 - temp5; 
        output[i] = temp7 + temp8;

        state_1 = state_0;
        state_0 = input[i];
        state_3 = state_2;
        state_2 = output[i];
    } 

    state[0] = state_0; state[1] = state_1; 
    state[2] = state_2; state[3] = state_3;

    return 0;  
}      

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?