This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DSPLIB DSPF_sp_iir function usage (error in documentation?)

Hi, 

I am working with the latest version (3.2.0.1) of the C66x DSP library. Specifically, I'd like to use the DSPF_sp_iir function for IIR filtering, but it looks to be poorly documented: the fourth parameter is supposed to contain the auto-regressive coefficients, but the source code (DSPF_sp_iir.c file) handles them as if they were the moving average part of the filter. Conversely, the fifth parameter is reported to point to the moving average coefficients, but it's used to implement the auto-regressive part of the filter. 

This is what DSPLIB user's manual reports:

void  DSPF_sp_iir (float *restrict y1, const float *x, float *restrict y2, const float *hb, const float *ha, int nr)

The IIR performs an auto-regressive moving-average (ARMA) filter with 4 auto-regressive filter coefficients and 5 moving-average filter coefficients for nr output samples. The output vector is stored in two locations. This routine is used as a high pass filter in the VSELP vocoder. The 4 values in the r1 vector store the initial values of the delays.

Parameters:

y1[nr+4] Delay element values (i/p and o/p).

x[nr] Pointer to the input array.

y2[nr+4] Pointer to the output array.

hb[5] Auto-regressive filter coefficients.

ha[5] Moving average filter coefficients.

nr Number of output samples.

And this is taken from the source code:

void DSPF_sp_iir(float *restrict y1,
const float * x,
float *restrict y2,
const float * hb,
const float * ha,
int nr)
{
float sum1,sum2, sum3, sum4, sum5;
int i;

sum1 = ( hb[0] * x[4]
+ hb[1] * x[3] - ha[1] * y1[3]
+ hb[2] * x[2] - ha[2] * y1[2]
+ hb[3] * x[1] - ha[3] * y1[1]
+ hb[4] * x[0] - ha[4] * y1[0]
);

....

for (i = 0; i < nr-1; i++ ) {

y1[i+4] = sum1;
y2[i] = sum1;

sum1 = sum2 + hb[0] * x[i+5] - ha[1] * y1[i+4];
sum2 = sum3 + hb[1] * x[i+5] - ha[2] * y1[i+4];
sum3 = sum4 + hb[2] * x[i+5] - ha[3] * y1[i+4];
sum4 = sum5 + hb[3] * x[i+5] - ha[4] * y1[i+4];
sum5 = hb[4] * x[i+5];
}

y1[nr+3] = sum1;
y2[nr-1] = sum1;
}


Is my observation correct? Did anyone notice the same problem before?

Thanks

Davide

  • Davide

     

    It looks like you are right.

     

    I looked at the natural C code DSPF_sp_iir_cn.c (which is the "gold standard" or the model for the optimized code. It clearly shows that hb[] are the fir coefficients, and ha[] are the iir (or the auto-regressive and moving average correspondently)

    void DSPF_sp_iir_cn (float *y1,               
        const float *x,                                    
        float *y2,                                
        const float *hb,                                   
        const float *ha,                                   
        int n)                                             
    {                                                      
        int i, j;                                          
        float sum;                                         
                                                           
        for (i = 0; i < n; i++)                            
        {                                                  
            sum = hb[0] * x[4+i];                          
            for (j = 1; j <= 4; j++)                       
                sum += hb[j] * x[4+i-j] - ha[j] * y1[4+i-j];
                                                           
            y1[4+i] = sum;                                 
            y2[i] = y1[4+i];                               
        }                                                  
    }    

     

    I will submit a bug report to fix the documentation

     

    Ran