IIR-filter implementation on a DSPIC

M

Mads

Guest
I am implementing a digital filter on a dsPIC using the dsplib library, dsPIC30F DSP Library.

I have designed my filter using MATLAB.

clc; clear all;
filter=designfilt('lowpassiir', 'FilterOrder', 4, 'PassbandFrequency', 3900, 'PassbandRipple', 1, 'SampleRate', 16000);
hd = dfilt.df2tsos(filter.Coefficients);

coef = fi(hd.sosMatrix)

fvtool(coef)

coef =

0.3949 0.7897 0.3949 1.0000 -0.0807 0.7538
0.1279 0.2559 0.1279 1.0000 -0.7783 0.3203


From matlab dofumentation:

SOS = [ b01 b11 b21 1 a11 a21
b02 b12 b22 1 a12 a22
...
b0L b1L b2L 1 a1L a2L ]


From the datasheet: There are 5 coefficients per second order (biquadratic) section arranged in the ordered set {b0, b1, a1, b2,a2}, 0 ≤ s < S.

I have implemented my coefficients as suggested, see below

const float filter[10] = {0.3948975, 0.7897339, -0.0807495,
0.3948975, 0.7538452, 0.1279297, 0.2558594, -0.77825928, 0.1279297,
0.3203125};

const float filter_float[10] = {0.3948975, 0.7897339, -0.0807495,
0.3948975, 0.7538452, 0.1279297, 0.2558594, -0.77825928, 0.1279297,
0.3203125};

fractional filter[10]; // 5

for(i=0; i<10; i++){
filter=Float2Fract(filter_float);
}

fractional dbIr_1[2], dbIr_2[2]; // Delay-Line-Buffer I-Filte
(Segment 1 and 2)
IIRTransposedStruct Filter;
Filter.coeffsBase=filter; // Sets the filtercoefficients
Filter.numSectionsLess1=1; // Define number of sections
Filter.finalShift=0; // Define shift of output (-1
Filter.delayBase1=dbIr_1; // Sets the delayline buffer
Filter.delayBase2=dbIr_2; // --
Filter.coeffsPage=COEFFS_IN_DATA; // Coefficient are stored in data
IIRTransposedInit(&Filter); // Initialize the filter

int blockLength=16;
int iyr[blockLength] = {0};

main{
IIRTransposed (blockLength, iyl, xl, &Filter);
}


When I sent a 500hz signal through the filter, there is no signal left, actually, all signal gets damped to zero.

I did expect that the 500hz signal would remain almost unchanged. Did I do something wrong when designing the filter?

Continue reading...
 
Top