FIR Filter Library

mikroPascal PRO for PIC32 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

function FIR_Radix(const ptrCoeffs : ^q15; FilterOrder : word; ptrInput : ^q15; InputLength : word; Index : word) : integer;

Description

This function applies FIR filter to ptrInput.

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

Function returns value of the Index-th sample of the filtered signal :



with :
N - filter order
k - current index
Requires

Nothing.

Example
// Filter setup:
//     Filter kind: FIR
//     Filter type: Lowpass filter
//     Filter order: 3
//     Filter window: Blackman
//     Filter borders:
//       Wpass:4000 Hz

program FIR;

var   FILTER_ORDER  : word;
      inputSamples  : array[3] of integer;
      outputSamples : array[6] of integer;
      i             : word;
const COEFF_B       : array[4] of integer = (0x0000, 0x1255, 0x1255, 0x0000);

procedure Init();
  begin
  inputSamples[0] := 0x4000;
  inputSamples[1] := 0x2000;
  inputSamples[2] := 0x1000;
  BUFFFER_SIZE := 32;
  FILTER_ORDER := 3;
  end;

begin
  Init();
  for i:= 0 to 5 do
    outputSamples[i] := FIR_Radix(@COEFF_B, FILTER_ORDER+1, @inputSamples, 3,  i);

  // outputSamples[0] = COEFF_B[0]*inputSamples[0];
  // outputSamples[1] = COEFF_B[0]*inputSamples[1] + COEFF_B[1]*inputSamples[0];
  // outputSamples[2] = COEFF_B[0]*inputSamples[2] + COEFF_B[1]*inputSamples[1] + COEFF_B[2]*inputSamples[0];
  // .
  // .
  // .

end.
Notes

None.

Copyright (c) 2002-2012 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