FIR Filter Library

mikroC PRO for dsPIC30/33 and PIC24 includes a library for finite impulse response (FIR) filter. All routines work with fractional Q15 format.

A finite impulse response (FIR) filter is a type of a digital filter, whose impulse response (the filter's response to a delta function) is finite because it settles to zero in a finite number of sample intervals.

Library Routines

FIR_Radix

Prototype

unsigned FIR_Radix(unsigned FilterOrder, const unsigned *ptrCoeffs, unsigned BuffLength, unsigned *ptrInput, unsigned Index);

// For dsPIC33EP family of MCUS :

unsigned FIR_Radix(unsigned FilterOrder, far const unsigned *ptrCoeffs, unsigned BuffLength, far unsigned *ptrInput, unsigned Index);

Description

This function applies FIR filter to ptrInput.

Parameters
  • FilterOrder: order of the filter + 1
  • ptrCoeffs: pointer to filter coefficients in program memory
  • BuffLength number of input samples
  • ptrInput: pointer to input samples
  • Index: index of current sample
Returns

with :
N - buffer length
k - current index
Requires

Nothing.

Example
const unsigned BUFFFER_SIZE  = 32;
const unsigned FILTER_ORDER  = 20;   
const COEFF_B[FILTER_ORDER+1] = {
      0x0000, 0x0048, 0x0133, 0x02D3, 0x052B, 0x0826,
      0x0BA0, 0x0F62, 0x1329, 0x16AA, 0x199A, 0x16AA,
      0x1329, 0x0F62, 0x0BA0, 0x0826, 0x052B, 0x02D3,
      0x0133, 0x0048, 0x0000
};

ydata unsigned input[BUFFFER_SIZE];       // Input buffer
unsigned inext;                           // Input buffer index
...
unsigned CurrentValue;
CurrentValue = FIR_Radix(FILTER_ORDER+1,  // Filter order
                         COEFF_B,         // b coefficients of the filter
                         BUFFFER_SIZE,    // Input buffer length
                         input,           // Input buffer
                         inext);          // Current sample
Notes

Input 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