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

📄 iirfilter_8.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_8( 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 temp1, temp2, temp3, temp4, temp5;
    int temp6, temp7, temp8, temp9, temp10;
    int temp11, temp12, temp13, temp14, temp15;
    int temp16, temp17, temp18, temp19, temp20;
    int coeff_a0, coeff_a1, coeff_a2, coeff_b1, coeff_b2;
    int state_0, state_1, state_2, state_3;
    int inSample1, inSample2, inSample3, inSample4;
    int outSample1, outSample2, outSample3, outSample4;

    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];

    inSample1 = input[0];
    inSample2 = input[1];
    inSample3 = input[2];
    inSample4 = input[3];

    for( i=0; i < sampleNumber; i+=4 )
    {
        temp1 = IMULM( coeff_a0, inSample1 );
        temp2 = IMULM( coeff_a1, state_0 );
        temp3 = IMULM( coeff_a2, state_1 );
        temp4 = IMULM( coeff_b1, state_2 );
        temp5 = IMULM( coeff_b2, state_3 );
        
        outSample1 = ( temp1 + temp2 + temp3 - temp4 - temp5 ) << SHIFT;
        output[i] = outSample1;

        temp6  = IMULM( coeff_a0, inSample2 );
        temp7  = IMULM( coeff_a1, inSample1 );
        temp8  = IMULM( coeff_a2, state_0 );
        temp9  = IMULM( coeff_b1, outSample1 );
        temp10 = IMULM( coeff_b2, state_2 );
        
        outSample2 = ( temp6 + temp7 + temp8 - temp9 - temp10 ) << SHIFT;
        output[i+1] = outSample2;

        temp11 = IMULM( coeff_a0, inSample3 );
        temp12 = IMULM( coeff_a1, inSample2 );
        temp13 = IMULM( coeff_a2, inSample1 );
        temp14 = IMULM( coeff_b1, outSample2 );
        temp15 = IMULM( coeff_b2, outSample1 );
        
        outSample3 = ( temp11 + temp12 + temp13 - temp14 - temp15 ) << SHIFT;
        output[i+2] = outSample3;

        temp16 = IMULM( coeff_a0, inSample4 );
        temp17 = IMULM( coeff_a1, inSample3 );
        temp18 = IMULM( coeff_a2, inSample2 );
        temp19 = IMULM( coeff_b1, outSample3 );
        temp20 = IMULM( coeff_b2, outSample2 );
        
        outSample4 = ( temp16 + temp17 + temp18 - temp19 - temp20 ) << SHIFT;
        output[i+3] = outSample4;

        state_0 = inSample4;
        state_1 = inSample3;
        state_2 = outSample4;
        state_3 = outSample3;

	inSample1 = input[i+4];
	inSample2 = input[i+5];
	inSample3 = input[i+6];
	inSample4 = input[i+7];
    } 

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

    return 0;  
}      

⌨️ 快捷键说明

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