⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iirfilter_9.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的各种滤波器源码
💻 C
字号:
    
#include <stdlib.h>
#include <math.h>
#include <ops/custom_defs.h>

#define SHIFT 3  /* see case study on IIR filter in Cookbook */

int iirFilter_9( int *inputData, int *outputData, 
                 int *coeff, int *state, int sampleNumber )
{

/*    #pragma TCS_unroll=0 */
    #pragma apge unroll=0

    int i;
    int * restrict input, * restrict output;
    int temp1A, temp2A, temp3A, temp4A, temp5A;
    int temp6A, temp7A, temp8A, temp9A, temp10A;
    int temp1B, temp2B, temp3B, temp4B, temp5B;
    int temp6B, temp7B, temp8B, temp9B, temp10B;
    int coeff_a0, coeff_a1, coeff_a2, coeff_b1, coeff_b2;
    int state_0, state_1, state_2, state_3, state_4, state_5;
    int inSample1A, inSample1B;
    int outSample1A, outSample1B, outSample2A, outSample2B;

    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]; state_4 = state[4]; state_5 = state[5]; 

    inSample1A = input[0];
    inSample1B = input[1];

    for( i=0; i < sampleNumber; i+=2 )
    {
        temp1A = IMULM( coeff_a0, inSample1A );
        temp2A = IMULM( coeff_a1, state_0 );
        temp3A = IMULM( coeff_a2, state_1 );
        temp4A = IMULM( coeff_b1, state_2 );
        temp5A = IMULM( coeff_b2, state_3 );
        temp1B = IMULM( coeff_a0, inSample1B );
        temp2B = IMULM( coeff_a1, inSample1A );
        temp3B = IMULM( coeff_a2, state_0 );
        temp5B = IMULM( coeff_b2, state_2 );
        
        outSample1A = ( temp1A + temp2A + temp3A - temp4A - temp5A ) << SHIFT;
        temp4B = IMULM( coeff_b1, outSample1A );
        outSample1B = ( temp1B + temp2B + temp3B - temp4B - temp5B ) << SHIFT;

        temp6A  = IMULM( coeff_a0, outSample1A );
        temp7A  = IMULM( coeff_a1, state_2 );
        temp8A  = IMULM( coeff_a2, state_3 );
        temp9A  = IMULM( coeff_b1, state_4 );
        temp10A = IMULM( coeff_b2, state_5 );
        temp6B  = IMULM( coeff_a0, outSample1B );
        temp7B  = IMULM( coeff_a1, outSample1A );
        temp8B  = IMULM( coeff_a2, state_2 );
        temp10B = IMULM( coeff_b2, state_4 );
        
        outSample2A = ( temp6A + temp7A + temp8A - temp9A - temp10A ) << SHIFT;
        temp9B = IMULM( coeff_b1, outSample2A );
        output[i] = outSample2A;

        outSample2B = ( temp6B + temp7B + temp8B - temp9B - temp10B ) << SHIFT;
        output[i+1] = outSample2B;

        state_0 = inSample1B;
        state_1 = inSample1A;
        state_2 = outSample1B;
        state_3 = outSample1A;
        state_4 = outSample2B;
        state_5 = outSample2A;

	inSample1A = input[i+2];
	inSample1B = input[i+3];
    } 

    state[0] = state_0; state[1] = state_1; state[2] = state_2; 
    state[3] = state_3; state[4] = state_4; state[5] = state_5; 

    return 0;  
}      

⌨️ 快捷键说明

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