User manual

637
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
IIR_Radix
Prototype
function IIR_Radix(BScale: integer; AScale: integer; ptrB: word; ptrA: word;
FilterOrder: word; ptrInput: word; InputLen: word; ptrOutput: word; Index:
word) : word;
Description This function applies IIR lter to ptrInput.
Parameters - BScale: B scale factor.
- AScale: A scale factor.
- ptrB: pointer to B coefcients (in program memory).
- ptrA: pointer to A coefcients (in program memory).
- FilterOrder: order of the lter + 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 BUFFER_SIZE = 8;
const FILTER_ORDER = 6;
const COEFF_B: array[FILTER_ORDER+1] of word = (0x0548, 0x1FAE, 0x4F34,
0x699B, 0x4F34, 0x1FAE, 0x0548);
const COEFF_A: array[FILTER_ORDER+1] of word = (0x4000, 0xB3FE, 0x5389,
0xD4D8, 0x10DD, 0xFCB0, 0x0052);
const SCALE_B = 2;
const SCALE_A = -1;
var inext : word; // Input buffer index
input : array[BUFFER_SIZE] of word; ydata; // Input buffer
output : array[BUFFER_SIZE] of word; ydata; // Output buffer
...
var CurrentValue : word;
CurrentValue := IIR_Radix(SCALE_B,
SCALE_A,
word(@COEFF_B), // b coefcients of the lter
word(@COEFF_A), // a coefcients of the lter
FILTER_ORDER+1, // Filter order + 1
word(@input), // Input buffer
BUFFER_SIZE, // Input buffer length
word(@output), // Input buffer
inext); // Current sample
Notes Input and output samples must be in Y data space.
IIR Filter Library
mikroPascal PRO for dsPIC30/33 and PIC24 includes a library for Innite Impulse Response (IIR) lter. All routines
work with fractional Q15 format.
A innite impulse response (IIR) lter is a type of a digital lter, whose impulse response (the lter’s response to a delta
function) is non-zero over an innite length of time.
Library Routines
IIR_Radix