Professional Documents
Culture Documents
Working With Digital Filters PDF
Working With Digital Filters PDF
Working With Digital Filters PDF
WO R K I N G W I T H
DIGITAL FILTERS
by Peter Best
Filter Basics
There are three common filter types that are used to
describe the behavior of both digital and analog filters. The
three filter models — or approximations — are called
Chebyshev, Bessel, and Butterworth. You’ll sometimes see
Chebyshev spelled in many other ways, including
Tschebyshceff. To understand the characteristics of each
of the filter types, you must first understand the terminology
used to describe a typical digital or analog filter.
A filter will pass signals at their maximum amplitude in
an area known as the filter’s passband. Conversely, a filter
will severely attenuate and block signals in its stopband area.
A high-pass filter passes frequencies above its cut-off frequency
and blocks them below its cut-off frequency. A low-pass filter
passes signals below its designed cut-off frequency and
blocks them above the cut-off frequency. A bandpass filter
passes signals that are inside a particular frequency range
and a bandstop filter blocks signals in a frequency range. All
of these filter types have one thing in common. They can all
be derived from a low-pass filter design.
A high-pass filter is the spectral inversion of a low-pass
filter. To spectrally invert a filter kernel, you only need to
apply opposite signs to each filter kernel point and add 1
to the center filter kernel sample. I used an application
called ScopeFIR to generate the low-pass filter kernel in
Figure 1 and its spectrally inverted high-pass kernel in
Figure 4. The physical low-pass filter configurations in
Figures 2 and 3 can be converted to high-pass filter
configurations by simply swapping the locations of the
JUNE 2004 Circle #112 on the Reader Service Card.
61
Best.qxd 5/6/2004 8:40 AM Page 62
Figure 4. This says it all.The top sine wave’s amplitude Figure 5. A relatively slow change in attenuation over the transition
decreased as I increased the input frequency towards band translates into a filter that doesn’t require as many poles and
the digital filter’s1 kHz bandstop value. zeros and, thus, isn’t as responsive as the filter shown in Figure 6.
Butterworth filter is good for separating bands of frequencies. response. There are no zeros in the transfer function of a
The Butterworth filter stands in the middle as far as Butterworth filter. Thus, like the Chebyshev and Bessel
transition band attenuation is concerned. Butterworth’s filter models, the Butterworth filter is an all pole filter.
filter transition band attenuation is better than the Bessel’s, Butterworth and Chebyshev filter models work best in
but worse than the Chebyshev’s. The step response of a the frequency domain, while the Bessel is a better time
Butterworth filter is slightly better than the Chebyshev step domain signal filter. It’s easy to determine if you’re looking
6XUSOXV6DOHVRI1HEUDVND 36;
<HV ZH VWLOO KDYH D JRRG VXSSO\
:HVWRQ6HULHV0HWHUV RI WKLV QHZ ZRQGHUIXO 'HOWURQ
WULSOH YROWDJH RSHQ IUDPH OLQHDU
075 075 075
&DP'ZHOO 9DFXXP3UHVVXUH 530
VXSSO\ 6R YHUVDWLOH 7ULP WKH
XDGFIXOOVFDOH DPSV LQ¶VPDGFIXOO YGF IXQGDPHQWDO VXSSOLHV RQ WKH
1HHGOHUHYHUVHG '&IXOOVFDOH VFDOH FLUFXLW ERDUG Y RU UHPRWH
PRXQW D WXUQ N 2KP SRW DQG
WXUQLWLQWRDYUHJXODWHGODEVXSSO\,W¶VVLPSOH
075 075 075
DPSV'& YGF NYGF
WR GR ,QVWUXFWLRQV LQFOXGHG 6HULHV RU SDUDOOHO WKH
PDGFIXOOVFDOH PDGFIXOOVFDOH DIXOOVFDOH WZRVXSSOLHVIRUDFRPELQHGY#DPSV
5HTEOHHGHUUHVLVWRU %RDUG WULPPDEOH FXUUHQW OLPLWLQJ WRR 1HZ ER[HG
IURP &ROOLQV VXUSOXV SRXQGV HDFK ´ [ ´
[´ORQJ
HDFKRUPRUHIRUHDFK0L[ 0DWFK HDFK
6FUHHQ<RXU2ZQ0HWHUV%ODQN:KLWH0HWHU)DFHVDYDLODEOHHDFK
3OHDVHYLVLWRXUZHEVLWHZLWKRYHUSDJHVDQGLPDJHVZZZVXUSOXVVDOHVFRP
+,0DQXDOVVRIUDGLRPLOLWDU\DQGWHVW &HUDPLF7UDQVPLWWLQJ&DSDFLWRUV2I$OO
$QWLTXH*DOYDQRPHWHUVE\-+%XQQHOO
HTXLSPHQWPDQXDOVRQKDQG 6L]HV'RRUNQREV)HHGWKUX:DWHU&RROHG
6SOLW%HDGV)RUDUHDOORI\RXULQWHUIHUHQFH (QFORVXUHV5DFN&DELQHWV%XLOGHU
9DULDEOH&DSDFLWRUV$LU0LFD9DFXXP
SUREOHPV %R[HV6KLSSLQJ&RQWDLQHUV
-RQHV6WUHHW2PDKD1()D[HPDLOJULQQHOO#VXUSOXVVDOHVFRP9LVD0DVWHUFDUG$PHULFDQ([SUHVVRU'LVFRYHU
&DOORUHPDLOIRUVKLSSLQJDQGWRWDOFKDUJHV$OO63(&,$/6LQWKLV$GRQO\JRRGIRUGD\DGYHUWLVLQJF\FOH1RH[FHSWLRQVSOHDVH
9LVLWRXUZHEVLWH#
ZZZVXUSOXVVDOHVFRP
JUNE 2004 63
Best.qxd 5/6/2004 8:47 AM Page 64
digital low-pass filter design. You also know that, once you
design a low-pass filter, you can derive any other filter
type from your low-pass filter kernel. You’ve also been
introduced to two applications: ScopeFIR and Filter Lab,
which help take the tedious math out of designing filters.
In the text that follows, we will design and build some
analog and digital filters using ScopeFIR and Filter Lab.
in a standard way to the Sipex SP233ACP RS-232 board and a full complement of components, I’ve made
converter, which, in turn, interfaces to the outside world arrangements with the folks at EDTP Electronics to
via a standard nine-pin shell connector as a DCE device. provide a full kit of parts — which they call the Digital
By making the digital filter board’s RS-232 port DCE, the Filter Development Kit. The digital control panel
need for an RS-232 crossover cable is eliminated. application and the digital filter PIC18F452 firmware are
The SPI module of the PIC18F452’s MSSP (Master free downloads and you can get them from the Nuts &
Synchronous Serial Port) drives the digital potentiometers Volts website at www.nutsvolts.com or the EDTP
and a 40 MHz crystal oscillator provides the clocking Electronics website at www.edtp.com
for 100 nS instruction cycles within the PIC18F452. A
standard Microchip ICSP port is also a part of the digital Coding and Using the Digital
filter board and allows the use of the MPLAB ICD2 Filter
hockey puck for programming and debugging.
You can easily assemble the digital filter electronics The firmware for the digital filter is written using a
using point-to-point techniques. If you go the point-to- combination of PIC C and PIC assembler. The PIC
point route, you can substitute a DIP version of the Sipex assembler code is used for speed. Sampling at 8 kHz
SP233ACP for the SMT version on the digital filter printed means that we have 125 µS to perform the digital filter
circuit board. For those of you that prefer a printed circuit work before a new sample is taken. We want to cram
every possible digital filter instruction we can between the
Note 1 taking of the samples. Therefore, assembler is used for
coding of the math and digital filter routines.
Enter as many taps as you can to make your filter the best it can Using PIC C allows the easy allocation of memory
be. However, remember that, with an 8 kHz sampling rate, you have
elements to hold the digital filter coefficients and data. The
to process all of those taps in less than 125 mS.
C constructs also eliminate having to code all of the house-
+5VDC +5VDC
ICSP CONNECTOR
U3 U4 JR1 R3
*CS 1 14 1 14 6 3 10K
2 *CS VDD 13 2 *CS VDD 13 PGC 5 6 3 2 RESET
SCK
3 SCK SO 12 3 SCK SO 12 PGD 4 5 2 1
SDO 1N5819
4 SI *SHDN 11 4 SI *SHDN 11 4 1
5 VSS *RS 10 5 VSS *RS 10 D2 C6 .1uF
6 PB1 PB0 9 6 PB1 PB0 9 MCLR
7 PW1 PW0 8 7 PW1 PW0 8
PA1 PA0 PA1 PA0 C2
MCP42XXX MCP42XXX .1uF
4
3
+
+5VDC 1
2 U1
- PGD
U5A 1 40
.1uF C4 5 MCP604 DIGITAL FILTER IN 2 *MCLR RB7 39 PGC
+ RA0 RB6
11
SIGNAL OUT 7 R1 C1 3 38
6 100K .01uF 4 RA1 RB5 37
- C3 RA2 RB4
U5B 5 36
MCP604 SIGNAL IN 6 RA3 RB3 35
7 RA4 RB2 34
.1uF 8 RA5 RB1 33 +5VDC
R2 9 RE0 RB0 32
100K +5VDC 10 RE1 VDD 31
C5 11 RE2 VSS 30
.01uF 12 VDD RD7 29
13 VSS RD6 28
14 OSC1 RD5 27
*CS 15 OSC2 RD4 26 RXD
16 RC0 RC7 25 TXD
DIGITAL FILTER OUT 17 RC1 RC6 24 SDO
Y1 SCK 18 RC2 RC5 23
+5VDC 19 RC3 RC4 22
DIGITAL POTENTIOMETER/FILTER ELEMENT BASIC SCHEMATIC 4 3 20 RD0 RD3 21
RD1 RD2
FLC11 1 2 PIC18F452
U5D
40MHz
U2 12
FLR11 FLR12 +
JR3A 14
3 TXD 2 5 TXOUT 9 13
+ 1 T1IN T1OUT 18 9 -
1 T2IN T2OUT 8
2 RXD 3 4 RXIN 7 8 MCP604
- 20 R1OUT R1IN 19 7
FLR11 = DIGITAL POT 1 R2OUT R2IN 6
FLR12 = DIGITAL POT 0 MCP604 5 6
FLC12 5 4
RXIN 3 4
12 3 2 TXOUT
C2+ 2 U5C
15 1
10 C2+ 16 1
NUTS & VOLTS
V- C2- 10
17 11 +
V- C2- 8
+9VDC DB9 FEMALE 9
SP233ACT -
JR2 VR1 +5VDC
D1 LM340S-5.0 INTERNAL TO LED SP233ACT PIN 7 = +5VDC +5VDC MCP604
1 1 3 SP233ACT PINS 6,9 = GND
IN OUT
1N5819 C8 C9 C10 C11 C12 C13 C14
Everything For Electronics
GND
C7 + .1uF LED1
2
JUNE 2004
66
Best.qxd 5/6/2004 8:54 AM Page 67
Figure 14. With the help of Microchip’s Filter Lab and Figure 15. This photo says it all.The top sine wave’s
ScopeFIR, the digital filter control panel provides a means of amplitude decreased as I increased the input frequency
quickly evaluating analog and digital filters. Note that I dialed in towards the digital filter’s 1 kHz bandstop value.
as close asthe potentiometers would allow.
NUTS & VOLTS
Everything For Electronics
JUNE 2004
68