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

📄 iirfilter_10.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_10( int *inputDataA,  int *inputDataB, 
                  int *outputDataA, int *outputDataB,
                  int *coeffA, int *coeffB, int *stateA, int *stateB,
                  int sampleNumber )
{
    int i;
    int * restrict inputA, * restrict inputB;
    int * restrict outputA, * restrict outputB;
    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 coeffA_a0, coeffA_a1, coeffA_a2, coeffA_b1, coeffA_b2;
    int coeffB_a0, coeffB_a1, coeffB_a2, coeffB_b1, coeffB_b2;
    int stateA_0, stateA_1, stateA_2, stateA_3, stateA_4, stateA_5;
    int stateB_0, stateB_1, stateB_2, stateB_3, stateB_4, stateB_5;
    int inSampleA, inSampleB;
    int outSample1A, outSample1B, outSample2A, outSample2B;

    inputA = inputDataA; outputA = outputDataA;
    inputB = inputDataB; outputB = outputDataB;
    coeffA_a0 = coeffA[0]; coeffA_a1 = coeffA[1]; coeffA_a2 = coeffA[2];
    coeffA_b1 = coeffA[3]; coeffA_b2 = coeffA[4];
    coeffB_a0 = coeffB[0]; coeffB_a1 = coeffB[1]; coeffB_a2 = coeffB[2];
    coeffB_b1 = coeffB[3]; coeffB_b2 = coeffB[4];
    stateA_0 = stateA[0]; stateA_1 = stateA[1]; stateA_2 = stateA[2]; 
    stateA_3 = stateA[3]; stateA_4 = stateA[4]; stateA_5 = stateA[5]; 
    stateB_0 = stateB[0]; stateB_1 = stateB[1]; stateB_2 = stateB[2]; 
    stateB_3 = stateB[3]; stateB_4 = stateB[4]; stateB_5 = stateB[5]; 

    inSampleA = inputA[0];
    inSampleB = inputB[0];

    for( i=0; i < sampleNumber; i++ )
    {
        temp1A = IMULM( coeffA_a0, inSampleA );
        temp2A = IMULM( coeffA_a1, stateA_0 );
        temp3A = IMULM( coeffA_a2, stateA_1 );
        temp4A = IMULM( coeffA_b1, stateA_2 );
        temp5A = IMULM( coeffA_b2, stateA_3 );
        temp1B = IMULM( coeffB_a0, inSampleB );
        temp2B = IMULM( coeffB_a1, stateB_0 );
        temp3B = IMULM( coeffB_a2, stateB_1 );
        temp4B = IMULM( coeffB_b1, stateB_2 );
        temp5B = IMULM( coeffB_b2, stateB_3 );
        
        outSample1A = ( temp1A + temp2A + temp3A - temp4A - temp5A ) << SHIFT;
        outSample1B = ( temp1B + temp2B + temp3B - temp4B - temp5B ) << SHIFT;

        temp6A  = IMULM( coeffA_a0, outSample1A );
        temp7A  = IMULM( coeffA_a1, stateA_2 );
        temp8A  = IMULM( coeffA_a2, stateA_3 );
        temp9A  = IMULM( coeffA_b1, stateA_4 );
        temp10A = IMULM( coeffA_b2, stateA_5 );
        temp6B  = IMULM( coeffB_a0, outSample1B );
        temp7B  = IMULM( coeffB_a1, stateB_2 );
        temp8B  = IMULM( coeffB_a2, stateB_3 );
        temp9B  = IMULM( coeffB_b1, stateB_4 );
        temp10B = IMULM( coeffB_b2, stateB_5 );
        
        outSample2A = ( temp6A + temp7A + temp8A - temp9A - temp10A ) << SHIFT;
        outputA[i] = outSample2A;

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

        stateA_1 = stateA_0; stateA_0 = inSampleA; stateA_3 = stateA_2;
        stateA_2 = outSample1A; stateA_5 = stateA_4; stateA_4 = outSample2A;
        stateB_1 = stateB_0; stateB_0 = inSampleB; stateB_3 = stateB_2;
        stateB_2 = outSample1B; stateB_5 = stateB_4; stateB_4 = outSample2B;

	inSampleA = inputA[i+1];
	inSampleB = inputB[i+1];
    } 

    stateA[0] = stateA_0; stateA[1] = stateA_1; stateA[2] = stateA_2; 
    stateA[3] = stateA_3; stateA[4] = stateA_4; stateA[5] = stateA_5; 
    stateB[0] = stateB_0; stateB[1] = stateB_1; stateB[2] = stateB_2; 
    stateB[3] = stateB_3; stateB[4] = stateB_4; stateB[5] = stateB_5; 

    return 0;  
}      

⌨️ 快捷键说明

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