AN540
AN540 is Implementing IIR Digital Filters manufactured by Microchip Technology.
..
Implementing IIR Digital Filters
Implementing IIR Digital Filters
INTRODUCTION
This application note describes the implementation of various digital filters using the PIC17C42, the first member of Microchip’s 2nd generation 8-bit microcontrollers. The PIC17C42 is a very high speed 8-bit microcontroller with an instruction cycle time of 250ns (@ 16 MHz input clock). Even though PIC17C42 is an 8-bit device, it’s high speed and efficient instruction set allows implementation of digital filters for practical applications. Traditionally digital filters are implemented using expensive Digital Signal Processors (DSPs). In a system the DSP is normally a slave processor being controlled by either an 8- or 16-bit microcontroller. Where sampling rates are not high (esp. in mechanical control systems), a single chip solution is possible using the PIC17C42. This application note provides a few examples of implementing digital filters. Example code for 2nd order Infinite Impulse Response (IIR) filters is given. The following type of filters are implemented:
- -
- - Low Pass High Pass Band Pass Band Stop (notch) filter
THEORY OF OPERATION
Digital filters in most cases assume the following form of relationship between the output and input sequences. y(n) =
- ∑ aiy(n
- i) + ∑ bjx(n
- j) i=o j=o M N
The above equation basically states that the present output is a weighted sum of the past inputs and past outputs. In case of FIR filters, the weighted constants ai=0 and in case of IIR filters, at least one of the ai constant is non zero. In case of IIR, the above formula may be re written in terms of Z transform as:
H(z) =
Y(z) X(z)
=
1 + ∑ ak Z -k k=1 k=0 N
∑ bk Z -k
The above equation can further be rewritten in difference equation format as follows: y(n) =
- ∑ aiy(n
- i) + ∑ bjx(n
- j) i=1 j=o M N
This application note does not explain how to design a filter. Filter design theory is well established and is beyond the scope of this application note. It is...