IIR Filter Library

mikroC PRO for dsPIC30/33 and PIC24 includes a library for Infinite Impulse Response (IIR) filter. All routines work with fractional Q15 format.

A infinite impulse response (IIR) filter is a type of a digital filter, whose impulse response (the filter's response to a delta function) is non-zero over an infinite length of time.

Library Routines

IIR_Radix

Prototype

unsigned IIR_Radix (const int BScale, const int AScale, const signed *ptrB, const signed *ptrA, unsigned FilterOrder, unsigned *ptrInput, unsigned InputLen, unsigned *ptrOutput, unsigned Index);

// For dsPIC33EP family of MCUS :

unsigned IIR_Radix (const int BScale, const int AScale, far const signed *ptrB, far const signed *ptrA, unsigned FilterOrder, far unsigned *ptrInput, unsigned InputLen, far unsigned *ptrOutput, unsigned Index);

Description

This function applies IIR filter to ptrInput.

Parameters
  • BScale: B scale factor.
  • AScale: A scale factor.
  • ptrB: pointer to B coefficients (in program memory).
  • ptrA: pointer to A coefficients (in program memory).
  • FilterOrder: order of the filter + 1.
  • ptrInput: address of input samples.
  • InputLen: number of samples.
  • ptrOutput: pointer to output samples. Output length is equal to Input length.
  • Index: index of current sample.
Returns

Requires

Nothing.

Example
const unsigned int BUFFER_SIZE = 8;
const unsigned int FILTER_ORDER = 6;
const signed int COEFF_B[FILTER_ORDER+1] = {0x0548, 0x1FAE, 0x4F34, 0x699B, 0x4F34, 0x1FAE, 0x0548};
const signed int COEFF_A[FILTER_ORDER+1] = {0x4000, 0xB3FE, 0x5389, 0xD4D8, 0x10DD, 0xFCB0, 0x0052};
const unsigned int SCALE_B = 2;  
const unsigned int SCALE_A = -1;  
unsigned int inext;                       // Input buffer index
ydata unsigned int input[BUFFER_SIZE];    // Input buffer
ydata unsigned int output[BUFFER_SIZE];   // Output buffer
...
unsigned int CurrentValue;
CurrentValue = IIR_Radix(SCALE_B,         
                         SCALE_A,         
                         COEFF_B,         // b coefficients of the filter
                         COEFF_A,         // a coefficients of the filter
                         FILTER_ORDER+1,  // Filter order + 1
                         input,           // Input buffer
                         BUFFER_SIZE,     // Input buffer length
                         output,          // Input buffer
                         inext);          // Current sample
Notes

Input and output samples must be in Y data space.

Copyright (c) 2002-2018 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code