AN2168 PSoC 1 - Understanding Switched Capacitor Filters.pdf

AN2168
PSoC® 1 Understanding Switched Capacitor Filters
Author: Dave Van Ess
Associated Project: Yes
Associated Part Family: CY8C23x33,CY8C24xxx,
CY8C27x43,28xxx,29x66
Software Version: PSoC® Designer™
Related Application Notes: AN2041
Abstract
AN2168 presents the theory behind switched capacitor filters, and provides guidelines and examples for
implementing these filters in PSoC 1 devices. Filters discussed include low pass, band pass, high pass, notch, and
elliptical. Example projects for each type of filter are provided.
Contents
Introduction
Introduction .......................................................................1
Filter Basics 101................................................................1
Roll Off Frequency (f0)..................................................2
PSoC Switched Capacitor Universal Two Pole Filter ........2
Simple Rules for Filter Design...........................................4
FilterCalc ...........................................................................4
Low Pass Filter..................................................................5
Low Pass Filter Example...................................................5
Low Pass Filters, the Easy Method ...................................7
Band Pass Filter................................................................8
BPF2 Filter Example .........................................................9
May I have a Wizard Please............................................12
Alternate Band Pass Filter Example................................14
High Pass Filter...............................................................16
Why Not?....................................................................17
Notch Filter .................................................................17
Notch Filter Example .......................................................19
Elliptical Filter ..................................................................19
Elliptical Filter Example ...................................................20
Summary.........................................................................21
References......................................................................21
About the Author .............................................................21
Document History............................................................22
A filter is a device that passes or rejects certain frequencies
of a signal. Four common types of filters are:

Low pass filter

Band pass filter

High pass filter

Notch filter
All these filters can be built using PSoC switched capacitor
blocks. For a better understanding of switched capacitor
blocks in general, see Application Note AN2041
“Understanding Switched Capacitor Blocks.”
Filter Basics 101
The basic building block of second order filters is the second
order universal filter transfer function. It is defined in
Equation 1.
2
 s 
 s 
  hbp 
  hlp
hhp 
2f 0 
2f 0 


H ( s) 
2
 s 
 s 

  d 
  1
 2f 0 
 2f 0 
Equation 1
Five variables (hhp, hbp, hlp, d, and f0) allow construction of
all filters types. The definition of each is given below.
www.cypress.com
Document No. 001-43151 Rev. *C
1
PSoC® 1 Understanding Switched Capacitor Filters
Roll Off Frequency (f0)
This is the frequency where the “s” terms start to dominate.
Frequencies below these values are considered “low,”
above this value are considered “high,” and around this
value are considered in “band.”
Damping (d)
Damping is a measure of how a filter transitions from lower
frequencies to higher frequencies. It is an index of the filter’s
tendency to oscillate. Practical damping values range from 0
to 2. Table 1 shows the performance for different damping
values.
Table 1.Damping Values vs. Filter Performance
Damping Value
Filter Performance
d<0
Unstable
d=0
Oscillator
d = 1.414
Critically damped
d=2
Fully damped
d>2
Excessively damped
High Pass Coefficient (hhp)
This is the coefficient of the numerator that dominates for
frequencies greater than f0.
Band Pass Coefficient (hbp)
This is the coefficient of the numerator that dominates for
frequencies near f0.
Low Pass Coefficient (hlp)
This is the coefficient of the numerator that dominates for
frequencies lower than f0.
These second order filter stages can be cascaded to
produce higher order filters. Use the spreadsheet,
FilterPlot.xls, to experiment with different combinations of
these five variables and view the response. It is located in
the project file associated with this Application Note.
PSoC Switched Capacitor Universal Two Pole Filter
This section explains the detailed interworking and theory of switched capacitor filters, and how they are implemented in
PSoC 1.
A topology for a state variable (bi-quad) switched capacitor filter is shown in
Figure 1.
Figure 1. PSoC Bi-quad Filter
This bi-quad filter can be built with two switched capacitor blocks. They are both clocked with the same sample frequency, fs.
Equations 2 and 3 define the discrete time circuit operation of this filter.
Vout1  Vout1 z 1  Vin
Vout 2  Vout 2 z 1  Vout1 z 1
C1
C
C
C
 Vout 2 2  (Vout 2  Vout 2 z 1 ) 4  (Vin  Vin z 1 ) 4
CA
CA
CA
CA
C pp
C3
 (Vin  Vin z 1 )
CB
CB
Equation 2
Equation 3
Equations 2 and 3 are used to solve the transfer functions in Equations 4 and 5.
www.cypress.com
Document No. 001-43151 Rev. *C
2
PSoC® 1 Understanding Switched Capacitor Filters
2
2
2
2
Vout1  z C B C p  2 zC B C p  z C B C1  C B C p  zC B C1  z C pp C 2  z C pp C 4  2 zC pp C 4  zC pp C 2  C pp C 4

Vin
z 2 C B C A  2 zC B C A  zC 2 C3  zC 4 C3  C 4 C3  C B  C A
2
Vout 2 z C pp C A  2 zC pp C A  C pp C A  zC p C3  C p C3  zC1C3
 2
Vin
z C B C A  2 zC B C A  zC 2 C3  zC 4 C3  C 4 C3  C B  C A
Equation 4
Equation 5
Applying the bilinear transform given in Equation 6 to transform Equations 4 and 5 results in the Laplace transfer
Equations 7 and 8.
s
2 fs
z
s
1
2 fs
1
H ( s ) output1
Equation 6
C pp s 
C
 C C 
1  s  4  1   p B  s

 C C  f
C3 f s 
f s  C 2
2 3  s


2
 C B C A 1 C 4 1  s 


  
 C 2 C3 2 C 2 4  f s 
2
H ( s ) output 2  
C pp C A  s 
C s 
s  C
   p
1    1
C 2 C 3  f s 
C 2 f s 
f s  C2
Equation 9
1 C4 1
 C 2 C3
2 C3 4
Note that the roll off frequency is directly proportional to
the sample frequency. This is a feature of switched
capacitor filters. A minor change in the sample frequency
changes the roll off frequency. Equation 10 defines the
over sample ratio as being the ratio of these two
frequencies.
Oversample 
fs
 2
f0
C4 s
1
C2 f s
 1  s 2 
1    
 4  f s  


Equation 8
 C B C A 1 C 4 1  s 
C s


    4
1
C
C
2
C
4
f
C2 f s
2
 2 3
 s 
C 2 C3
C AC B 

Equation 7
2
Note that the denominators for both Equations 7 and 8 are
identical. This means the roll off frequency and damping
values are identical for both outputs. Using Equation 1 as
a template, the roll off frequency is shown in Equation 9
f
f0  s
2
2
 C1C B s  1 s 
 
1 

C 2 C3 f s  2 f s 

1 C4 1
C AC B 
 C 2 C3
2 C3 4
Equation 10
C 2 C3
changed to 50 * 3.7 kHz or 185 kHz. Again, using
Equation 1 as a template and using the solution for f0 in
Equation 9, the damping value is shown in Equation 11.
d
C4
1 C4 1
C AC B 
 C 2 C3
2 C3 4
C3
C2
Equation 11
The high pass coefficient for the first output, from
Equation 7, is extracted and shown in Equation 12.
hhp1  
C pCB
1
1
C A C B  C3 C 4  C 2 C 3
2
4
Equation 12
Again, from Equation 7, the band pass coefficient is
extracted. For reasons that will later become clear, this
coefficient divided by the damping value is shown in
Equation 13.
For example, a 5 kHz filter that is sampled at 250 kHz is
said to have an over sample ratio of 50. Changing the roll
off to 3.7 kHz only requires that the sample frequency be
www.cypress.com
Document No. 001-43151 Rev. *C
3
PSoC® 1 Understanding Switched Capacitor Filters
hhp1
d

C1C B
C 2 C3
 1 s 
1 

 2 f s    C1C B
C4
C 4 C3
C2
Equation 13
From Equation 8, the high pass, band pass, and low pass
coefficients for the second output are extracted and shown
in Equations 14, 15, and 16.
hhp 2
C pp C A

1
1
C B C A  C 3C 4  C 2 C 3
2
4
hbp 2
hlp 2
Cp 
s 
1  
Cp
C
fs 
 2 

C4
C4
C2
Equation 14
The program then calculates all combinations of the
capacitors that meet these requirements. The acceptable
combinations, if any, are written to the output file. The
program also outputs to the terminal indicating the number
of acceptable solutions.
For example, Figure 2 shows the terminal count given the
following input:

Output file is “test.csv”

d = 1.414 +/- 5%

f0 = 5 kHz +/- 5%

fs = 250 kHz (fColumnClock = 1 MHz)
Figure 2. Monitor for FilterCalc
Equation 15
2
C1  1  s  
C



 1     1


C2
4  fs 
C2


Equation 16
Note that each coefficient is directly proportional to C1, Cp
or Cpp. Also note that none of these values are used to
determine the roll off frequency and damping value.
Simple Rules for Filter Design
There are three steps to design a PSoC switched
capacitor filter. They are:
1. Determine the roll off frequency, damping value and
pass coefficients for the desired filter.
2.
3.
Using Equations 9 and 11, determine the values
required for C2, C3, C4, CA and CB for the desired roll
off frequency f0 and damping value d.
Using Equations 12 through 16, set the appropriate
values to C1, Cp and Cpp to meet the desired pass
coefficients.
FilterCalc
The program finds 18 solutions that meet the input
constraints. Because the output file has a “.csv” extension
it can be viewed with a spread sheet. It is shown
in Figure 3. Any of these 18 solutions are acceptable. The
user can decide which best meets their specific
requirements.
FilterCalc.exe is a program to calculate all combinations of
capacitor values that result in an acceptable roll off
frequency and damping value. It is located in the project
file associated with this Application Note. When the
program is run, it will prompt you for the following
information:

Output file name

Damping value

Damping tolerance

The desired roll off frequency

Roll off tolerance

Column clock (4x fs)
www.cypress.com
Document No. 001-43151 Rev. *C
4
PSoC® 1 Understanding Switched Capacitor Filters
Figure 3. FilterCalc Generated Spreadsheet
Table 2. Selected Points on Low Pass Transfer Function
Gain
Condition
H(s)lp = hlp
s/2πf0 = 0
H(s)lp ≈ hlp
s/2πf0 = 1/10
H(s)lp = hlp/d
s/2πf0 = 1
H(s)lp ≈ hlp/102
s/2πf0 = 10
H(s)lp ≈ hlp/1002
s/2πf0 = 100
Note that the cut off frequency, fcutoff, is defined as the
frequency where the output is attenuated by 3 dB. It is not
necessarily equal to f0. Fortunately, many filter reference
books have tables with the necessary roll off and damping
values calculated for different types and orders of filters [1].
The transfer function shown in Equation 17 can be made
by taking the Vout2 transfer Equation 8 and setting Cp and
Cpp to zero. The low pass coefficient is shown in Equation
18.
The rest of this Application Note will deal in the specifics
for each type of filter.
Low Pass Filter
A low pass filter allows the passing of signals from DC up
to some cutoff frequency, fcutoff. The transfer equation for a
two-pole low pass filter is given in Equation 17.
H ( s ) lp 
hlp
hlp 
C1
C2
Equation 18
The topology for a PSoC switched capacitor low pass filter
in shown in Figure 5.
Figure 5. PSoC Two-Pole Low Pass Filter
Equation 17
2
 s 
 s 

  d 
  1
 2f 0 
 2f 0 
A plot of a typical low pass filter is shown in Figure 4.
Figure 4. FilterPlot-Generated Low Pass Filter
This is the topology used to implement the LPF2 User
Module.
Low Pass Filter Example
The goal of this example is to construct the following filter:

Two pole Bessel low pass filter

Cut off frequency of 5 kHz

An over sample ratio of 50 (fs = 250 kHz)

Unity gain
Standard tables from filter reference books[1] show that the
filter is constructed with:
This plot and Table 1 show that the response is relatively
flat for frequencies less than f0. For frequencies greater
than f0, the signal falls off as the square of the frequency.
At f0 the output is attenuated by the damping value.
www.cypress.com

f0 = 1.274 * 5 kHz = 6,370 kHz

d = 1.732
Document No. 001-43151 Rev. *C
5
PSoC® 1 Understanding Switched Capacitor Filters
The following figure shows the FilterCalc monitor.
Figure 8. Bessel Filter Parameters
Figure 6. FilterCalc for Low Pass Example
The user module placement is shown in Figure 9.
Figure 9.Bessel Example Block Placement
There are 13 solutions that meet the design constraints.
Figure 7 is the spreadsheet that lists them.
Figure 7. Bessel Example Solutions
Figure 10 is a spectral plot for the filter.
Figure 10. Spectral Plot for Bessel50x Filter
Any of these solutions meet the requirements. If a solution
with the smallest roll off error is important, then the row 6
solution would be best. If the smallest damping error is
important, the row 7 solution is best. If the largest value of
C2 is important, then choose the row 9 solution. (To reduce
DC offset error caused by charge injection from the
switches, it is desirable to keep the value of C2 as high
possible). For this example, the solution in row 9 is
selected.
A value for C1 can be calculated using Equation 18. For
unity gain, C1 must equal to C2.The user module
parameters are shown in Figure 8.
www.cypress.com
Examination of the plot shows that the signal is down 3 dB
around 5 kHz.
Document No. 001-43151 Rev. *C
6
PSoC® 1 Understanding Switched Capacitor Filters
Low Pass Filters, the Easy Method
.Figure 11. Filter Design Spreadsheets
The earlier method was a lot of work to calculate a single
set of filter values. Cypress has provided a more
automated solution. From PSoC Designer, go to Help >>
Documentation >>Filter Design. Figure 11 shows the
spreadsheets available
Figure 12. Two-Pole Low Pass Filter Design Spreadsheet
Opening up LPF2 Design.xls brings up a low pass filter
design spreadsheet. See Figure 12. The filter
characteristics are entered in the yellow cells. For this
specific case, the filter is selected to have:

A cutoff frequency of 5 kHz

A Unity Gain (0 dB)

A Bessel Response

250kHz Sample Freq
The derived filter requirements for damping value roll off
frequency, and gain are shown in rows 16, 18, and 19.
A plot of the filter response including the effects of
sampling and Nyquist frequency is provided. The design
www.cypress.com
procedure is included in the box at the top right of the
spreadsheet. This tool does not guarantee the best-fit
solution; however, it does quickly provide a solution that
meets all design requirements.
All of this is done without the user needing to know the
damping and roll off values for their desired filter
response. This same spreadsheet is available from
PSoC Designer as a “Wizard” by selecting the Filter User
Module then right clicking to get access to the Filter
Design Wizard. The wizard has the advantage of
automatically transferring the calculated values into that
filter’s parameter locations. Also included with PSoC
Designer is a spreadsheet for designing four-pole low
pass filters (LPF4 Design.xls).
Document No. 001-43151 Rev. *C
7
PSoC® 1 Understanding Switched Capacitor Filters
Band Pass Filter
A band pass filter allows the passing of signals around a
defined median frequency. The transfer equation for a
two-pole band pass filter is given in Equation 19.
An important parameter of band pass filters is the filter
selectivity (Q). It is defined as the center frequency divided
by the bandwidth and is shown in Equation 22.
Q
 s 

hbp 
2f 0 

H ( s) 
2
 s 
 s 

  d 
  1
 2f 0 
 2f 0 
Equation 19
A plot of a typical band pass filter is shown in Figure 13.
f upper f lower
f center

BWbp
f upper  f lower
Equation 22
To calculate the upper and lower cutoff points,
Equation 19 is converted to the frequency format shown in
Equation 23.
H ( f )bp 
Figure 13. FilterPlot-Generated Band Pass Filter
hbp
 f
f 
  0   1  d
f 
 f0
Equation 23
The amplitude of the transfer function will be down 3 db
from the peak value when the imaginary part of the
denominator in Equation 23 equals the real part of the
denominator. This results in Equations 24 and 25.
f upper
f0
f0
f lower
This plot and Table 3 show that the response peaks at f0.
It is equal to the pass coefficient divided by the damping
value. For frequencies greater than 10f0, the signal falls off
proportionally to the frequency. For frequencies less than
f0/10, the signal falls off inversely to the frequency.

f0
f upper

Condition
H(s)hp ≈ hlp/100
s/2πf0 = 1/100
H(s)hp ≈ hlp/10
s/2πf0 = 1/10
H(s)hp = hlp/d
s/2πf0 = 1
H(s)hp ≈ hhp/10
s/2πf0 = 10
H(s)hp ≈ hlp/100
s/2πf0 = 100
BWbp  f upper  f lower
Equation 20
f center 
Equation 21
www.cypress.com
Equation 25
Solving these equations results in Equations 26 and 27.
f upper  f 0
d2  4  d
2
Equation 26
f lower  f 0
d2 4 d
2
Equation 27
Substituting the values in Equation 26 and 27 into the
center frequency and bandwidth of Equations 20 and 21,
results in Equations 28 and 29.
The bandwidth of the band pass filter is defined as the
difference between the upper (fupper) and lower (flower)
cutoff frequencies where the amplitude falls 3 dB below
the peak value on its way out of the pass band. The center
frequency (fcenter) is the geometric mean of these two
limits. They are shown in Equations 20 and 21.
f upper f lower
Equation 24
f lower
d
f0
Table 3. Selected Points on Band Pass Transfer Function
Gain
d
f center  f 0
BWbp  f 0
d2  4  d
2
d2  4  d
 f 0 Equation 28
2
d2 4 d
d2 4 d
 f0
 f0d
2
2
Equation 29
These equations are used to calculate Q. It is shown in
Equation 30.
Q
f center
f
1
 0 
BWbp f 0 d d
Document No. 001-43151 Rev. *C
Equation 30
8
PSoC® 1 Understanding Switched Capacitor Filters
Multiple band pass filters can be cascaded to form higher
order filters. As with low pass filters, many filter reference
books have tables with the necessary center frequency
and Q values calculated for different types and orders of
band pass filters[1].
unwanted extra harmonics. A block diagram is shown in
Figure 16.
Figure 16. 1 kHz Sinusoid Generator Block Diagram
The band pass transfer function shown in Equation 19 can
be implemented two ways. One method is to take the Vout1
transfer Equation 7 and set Cp and Cpp to zero. The band
pass coefficient is shown in Equation 31.
hbp1
d

C1C B
C4C3
Equation 31
The topology for a PSoC switched capacitor band pass
filter is shown in Figure 14.
Figure 14. PSoC Two-Pole Band Pass Filter
Note that the input to the filter is Vref. It is converted to a
+/-Vref square wave by connecting the PWM output to the
filter block’s analog modulator input. The modulator
toggles the input between +Vref and -Vref (RefHi and
RefLo), these values are controlled by the RefMux
parameter in the Global Resources of PSoC Designer.
The block placement is shown in Figure 17.
Figure 17. Band Pass Example Block Placement
This is the topology used to implement the BPF2 User
Module.
An alternative method is to take the Vout2 transfer Equation
8 and set C1 and Cpp to zero. The alternative band pass
coefficient is shown in Equation 32.
hbp 2
d

Cp
C4
Equation 32
The alternative topology is shown in Figure 15.
The requirements for the PWM8 are:
Figure 15. Alternative PSoC Band Pass

200 kHz input clock

Period of 200

Pulse width of 100

Output connected to a modulator input (GOE[0])
Figure 18 shows the parameters required to implement a
PWM with these requirements:
Filter
While there is no user module implementation of this
alternate topology, a method for modification of an LPF2
User Module to perform this band pass function will be
shown later.
BPF2 Filter Example
The goal of this example is to build a 1 kHz, 4 Vpp sinusoid
generator. It is constructed by passing a 1 kHz square
wave through a 1 kHz band pass filter to remove the
www.cypress.com
Document No. 001-43151 Rev. *C
9
PSoC® 1 Understanding Switched Capacitor Filters
Figure 18. Parameters for PWM8_1
Figure 19. FilterCal for Band Pass Example
Equation 33 gives the Fourier series for a 1 kHz square
wave with a +/- Vref amplitude.
Vref
4  sin 2f 0 2n  1 

 n0
2n  1
Equation 33
The frequency components are at f0, 3f0, 5f and so on. The
hardest harmonic to remove is 3f0. A band pass filter with
a Q of four attenuates the third harmonic by 20 dB. (The
third harmonic is already 10 dB lower than the primary
frequency for a total attenuation of 30 dB.)
One requirement for this filter is to have a Pk-Pk value of
4 V. +Vref(RefHi) is 3.9 V and –Vref(RefLo) is 1.3 V, this is
only 2.6 V Pk-Pk, so some gain is needed. Equation 34
calculates the peak gain required for an output of +/- 2
volts and a reference voltage of 1.3 volts.
PeakGain 
hbp
d

4V pp
C1C B

 1.208
C 4 C3 2V 4
ref

Equation 34
There are 34 solutions that meet the requirements for Q
and center frequency. They are shown in the spreadsheet
in Figure 20.
The requirements for the band pass filter are summarized
below:

Two pole Bessel band pass filer

Center Frequency of 1 kHz

Q of approximately 4 (d = ¼)

An over sample ratio of 50 (fs = 50 kHz)

Peak Gain of 1.208
Figure 19 shows the FilterCal monitor.
www.cypress.com
Document No. 001-43151 Rev. *C
10
PSoC® 1 Understanding Switched Capacitor Filters
Figure 20. Band Pass Example Solutions
Figure 21. Q and PeakGain Included
This data is then sorted by peak gain value. It is shown in
Figure 22.
Figure 21 shows the value of Q for each solution in
column K. The value for the peak gain, when C1 = 1, has
also been calculated in column L.
www.cypress.com
Document No. 001-43151 Rev. *C
11
PSoC® 1 Understanding Switched Capacitor Filters
Figure 22. Data Sorted by Peak Gain Value
The modulator connection is made by selecting
Modulator Clock to be GlobalOutEven_0, the output of
the PWM.
Figure 24 shows that the output is in fact 4Vpp and has a
frequency of 1 kHz.
Figure 24. 4Vpp 1 KHz Output
Note that the output is made up of 50 discrete samples per
cycle. This is what is to be expected with a 50-kHz
sampling clock (200-kHz column clock).
May I have a Wizard Please
There is design spreadsheet for two-pole and four-pole
band pass filters. BPF2 Design.xls is opened and shown
in Figure 25.
Three solutions have a peak gain value close to 1.208.
The solution in row 26 is selected. The BPF2_1
parameters are shown in Figure 23.
Figure 23. Band Pass Filter Parameters
www.cypress.com
The filter characteristics are entered in the yellow cells.
For this specific case, the filter is selected to have:




A center frequency of 1 kHz
Gain of 1.208 (1.64 dB)
Bandwidth of 250 Hz
Sample Frequency of 50kHz
Document No. 001-43151 Rev. *C
12
PSoC® 1 Understanding Switched Capacitor Filters
Figure 25. Two-Pole Band Pass Filter Design Spreadsheet
The derived filter requirements for Q, roll off frequency,
and gain are shown in rows 12, 14, and 15.
The user manipulates the C2 (the cell in orange) while
keeping track of the calculated Q in row 27. When
satisfied with these two values, the calculated values for
CA, CB, C3, C4 and C1 can be found in rows 19, 20, 22, 24,
and 26.
www.cypress.com
A plot of the filter response including the effects of
sampling and Nyquist frequency is provided. For this
example, the best fit came out with a gain of one. This is
16% below the desired value of 1.208. Some leeway is
allowed in the Q value. Figure 26 shows the solution when
the bandwidth requirement is lowered to 200 Hz.
Document No. 001-43151 Rev. *C
13
PSoC® 1 Understanding Switched Capacitor Filters
Figure 26. Spreadsheet with Bandwidth Requirement Altered
With the same C2, C4 calculates to 13 and the gain is now
1.231 (a 2% error).
Figure 27. FilterCalc Monitor for Alternate Band Pass Filter
Example
This same spreadsheet is available from PSoC Designer
as a “Wizard” by selecting the Filter User Module then
right clicking to get access to the Filter Design Wizard.
The wizard has the advantage of automatically transferring
the calculated values into that filter’s parameter locations.
Also included with PSoC Designer is a spreadsheet for
designing four pole band pass filters (BPF4 Design.xls)
Alternate Band Pass Filter Example
The goal of this example is to construct the following filter:

Two pole band pass filter
Four Solutions meet the design constraints. They are
shown in Figure 28.

Center frequency of 5 kHz

Q of 10 (d = .1)

An over sample ratio of 50 (fs = 250 kHz)

Unity Peak Gain.
Figure 27 shows the FilterCalc monitor given these
constraints.
www.cypress.com
Document No. 001-43151 Rev. *C
14
PSoc® 1 Understanding Switched Capacitor Filters
Figure 28. Alternate Band Pass Example Solutions
Figure 30. FauxBP Parameters
The solution in row 7 has the smallest center frequency
error. It is the one selected.
The topology of the alternate band pass filter shown in
Figure 13 is very close to the low pass filter topology
shown in Figure 6. A low pass filter can be converted to an
alternate band pass filter by:


Note that C1 is set to zero. The correct value and input
connection must be set for Cp. C1 is the ACap of the filter’s
input block, while Cp is the CCap of the same block.
Setting C1 to zero
Setting Cp value in software
The user module placement is shown in Figure 29.
Figure 29. Alternate Band Pass Block Placement
Cp must be connected to the buffer located in ACB00.
Figure 31 shows that setting the input for ACap (C1) to
ACB00 also set the CCap (Cp) input to ACB00.
Figure 31. C1 and Cp Input Selection
Figure 31 confirms the A and C inputs are correctly
configured to connect to ACB00.
The user module parameters are shown in Figure 30.
Example Code 1 shows the program that starts the filter
and also configures the Ccap (Cp) value.
Equation 32 shows that for unity peak gain, Cp must equal
C4. Software is used to set the lower 5 bits of the register
ASC10CR to 13. This is shown in example Code 2.
www.cypress.com
Document No. 001-43151 Rev. *C
15
PSoc® 1 Understanding Switched Capacitor Filters
Code 1
Figure 33. FilterPlot-Generated High Pass Filter
Figure 32 shows a spectral plot of this filter.
Figure 32. Q=10 Alternate Band Pass Filter Spectral Plot
Table 4. Selected Points on High Pass Transfer Function
Gain
Examination of the plot shows that the signal has a center
frequency of 5 kHz. It also is 40 dB down a decade away
from the center frequency. This is consistent for a 5 kHz
band pass filter with a Q of 10.
High Pass Filter
Condition
H(s)hp = 0
s/2πf0 = 0
H(s)hp ≈ hlp/1002
s/2πf0 = 1/100
H(s)hp ≈ hlp/102
s/2πf0 = 1/10
H(s)hp = hlp/d
s/2πf0 = 1
H(s)hp ≈ hhp
s/2πf0 = 10
H(s)hp ≈ hlp
s/2πf0 = 100
Note that the cut off frequency, fcutoff, is defined as the
frequency where the output is attenuated by 3 dB. It is not
necessarily equal to f0.
Fortunately, many filter reference books have tables with
the necessary roll off and damping values calculated for
different types and orders of filters [1].
The high pass transfer function shown in Equation 35 can
be implemented two ways.
A high pass filter allows the passing of signals greater
than some cutoff frequency fcutoff. The transfer equation
for a two-pole high pass filter is given in Equation 35.
One method is to take the Vout1 transfer Equation 7 and set
C11 and Cpp to zero. The high pass coefficient is shown in
Equation 36.
2
 s 

hhp 
2f 0 

H ( s) hp 
2
 s 
 s 

  d 
  1
 2f 0 
 2f 0 
Equation 35
hhp1  
C pCB
1
1
C A C B  C3 C 4  C 2 C3
2
4
Equation 36
The topology for a PSoC switched capacitor high pass
filter in shown in Figure 34.
A plot of a typical high pass filter is shown in Figure 33.
www.cypress.com
Document No. 001-43151 Rev. *C
16
PSoc® 1 Understanding Switched Capacitor Filters
Figure 34. PSoC Two-Pole High Pass Filter
This is not unique to PSoC switched capacitor filters.
Implementing a well performing high pass filter requires
very high over sample ratio (at least several thousand).
Hyper large over sample ratios require a large ratio of
capacitor sizes. This uses a significant amount silicon
area, thus, rendering them economically impractical.
Notch Filter
An alternative method is to take the Vout2 transfer Equation
8 and set C1 and Cp to zero. The alternative high pass
coefficient is shown in Equation 37.
A notch filter allows the passing of signals except around a
defined median frequency. It is a combination of equal
amounts of the low pass and high pass coefficients. The
transfer equation for a two-pole notch filter is given in
Equation 38.
2
hhp 2
C pp C A

1
1
C A C B  C 3C 4  C 2 C 3
2
4
Equation 37
H ( s) notch 
The alternative topology is shown in Figure 35.
 s 
  hlp
hhp 
 2f 0 
2
 s 
 s 

  d 
  1
 2f 0 
 2f 0 
: hhp  hlp
Equation 38
A plot of a typical notch filter is shown in Figure 36..
Figure 35. Alternative PSoC High Pass Filter
Figure 36. Filter Plot-Generated Notch Filter
There are no user module implementations in either
topology.
Why Not?
Switched capacitor filters sample the input at some
sample frequency, fs. At the Nyquist limit (fs/2), the signal
frequency will start to alias back toward DC. Switched
capacitor filters cannot distinguish a DC input from an
input at the sampling frequency.
This is not a problem for low pass filters. The Nyquist
point, being half the over sample ratio, is far down the
attenuation curve. For a 100 over sample two-pole low
pass filter, the output signal is down 68 dB at the Nyquist
point. It is 56 dB down for a filter with an over sample ratio
of 25.
It is just the opposite for a high pass filter. At the Nyquist
point, pretty much all the signal is passed through. Signals
past the Nyquist frequency are aliased and are generally
useless. This limits the bandwidth of a high pass filter to
be from the cutoff frequency up to the Nyquist frequency
effectively a band pass filter.
www.cypress.com
This plot and Table 5 show that the response is zero at f0.
At some distance away from f0, the signal is passed
relatively unattenuated.
Table 5. Selected Points on Notch Transfer Function
Gain
Condition
H(s)notch ≈ h
s/2πf0 = 1/100
H(s)notch ≈ h
s/2πf0 = 1/10
H(s)notch = 0
s/2πf0 = 1
H(s)notch ≈ h
s/2πf0 = 10
H(s)notch ≈ h
s/2πf0 = 100
The bandwidth of the notch is defined as the difference
between the upper (fupper) and lower (flower) cutoff
frequencies where the amplitude falls 3 dB. The center
frequency (fcenter) is the geometric mean of these two
limits. They are shown in Equations 39 and 40.
Document No. 001-43151 Rev. *C
17
PSoc® 1 Understanding Switched Capacitor Filters
BW notch  f upper  f lower
f center 
H ( s ) notch 
f upper f lower
Equation 40
To calculate the upper and lower cutoff points, the
amplitude of Equation 38 is shown in Equation 41.
H ( f ) notch 
f
f 
h  0  
f0 
 f
 C pp C A 1 C1

 C C 4C
2
 2 3
Equation 39
2
Equation 41
2
 f
f 
h   0   d2
 f0 f 


2
 s 
C
   1
 f 
C2
 s 
Equation 47
2
 C B C A 1 C 4 1  s 
C s


    4
1
C
C
2
C
4
f
C2 f s
2
 2 3
 s 
The topology for such a filter is shown in Figure 37. The
low pass and high pass coefficients are shown in Equation
48.
1
C pp C A  C1C 3
Equation 48
C
4
hhp 2 
 hlp 2   1
1
1
C2
C B C A  C 3C 4  C 2 C3
2
4
Figure 37. PSoC Two-Pole Notch Filter
Equation 42 shows the point where the signal is 3 dB
down.
H ( f ) notch 
h
2
Equation 42
Equations 40 and 41 are combined to find the two
solutions. They are shown in Equation 43 and
Equation 44.
f upper  f 0
f lower  f 0
d2  4  d
2
d2 4 d
2
Equation 43
Equation 44
Substituting the values in Equation 43 and 44 into the
center frequency and bandwidth in Equations 39 and 40,
results in Equations 45 and 46.
f center  f 0
BWbp  f 0
d2  4  d
2
d2  4  d
 f0
2
Equation 45
d2 4 d
d2 4 d
 f0
 f0d
2
2
Equation 46
This filter has the advantage of only using two switched
capacitor blocks. The disadvantage is that interaction
between the two blocks near the roll off frequency keeps it
from functioning well for values of Q much greater than
one. The second way the notch filter transfer Equation 38
can also be expressed is as the original input minus a
band pass filter output. This is shown in Equation 49.
2
 s 

hbp 
hbp
2f0 

H (s)notch  h 
:h 
2
d
 s 
 s 

  d 
 1
 2f 0 
 2f0 
Equation 49
A block diagram of such a filter is shown in Figure 38.
Figure 38. Notch Filter Block Diagram
The notch bandwidth is proportional to the damping value.
The center frequency is the roll off frequency. The transfer
function shown in Equation 38 can made two different
ways.
The first is by taking the Vout2 transfer Equation 8 and
setting Cp to zero. This is shown in Equation 47.
www.cypress.com
This filter is implemented using a band pass filter plus an
additional switched capacitor block functioning as a
DiffAmp. It requires an additional block to implement but is
more able to implement high Q notch filters.
Document No. 001-43151 Rev. *C
18
PSoc® 1 Understanding Switched Capacitor Filters
Figure 41 is a spectral plot of this filter.
Notch Filter Example
For this example, the alternate band pass example will be
modified to include a notch output. The block placement is
shown in Figure 39.
Figure 41. Q=10 Alternate Band Pass Filter Spectral Plot
Figure 39. Band Pass/Notch Block Placement
Examination of the plot shows that the signal has a notch
at 5 kHz. The 3 dB points are approximately 500 Hz apart.
This is consistent for a 5 kHz notch filter with a Q of 10.
Elliptical Filter
A DiffAmp has been added to subtract the buffer input
from the band pass filter output. The parameters for the
DiffAmp block are shown in Figure 40.
Figure 40. DiffAmp Parameters
Similar to the notch filter, an elliptical filter allows the
passing of signals only when they are passed around a
defined median frequency. The difference is that they are
no longer equal amounts of the low pass and high pass
coefficients. The transfer equation for a two-pole notch
filter is given in Equation 50.
2
H ( s) elliptical
 s 
  hlp
hhp 
2f 0 


: hhp  hlp
2
 s 
 s 

  d 
  1
 2f 0 
 2f 0 
Equation 50
A plot of a typical elliptical low pass filter is shown in
Figure 42.
Figure 42. FilterPlot-Generated Elliptical Low Pass Filter
The filter connection is made to the BCap input. It is the
negative input. The band pass filter inverts the gain so the
input into the ACap input must be inverted. Setting ASign
negative does this. The only software change is to start
the extra PGA User Module.
www.cypress.com
This plot and Table 6 show that the response is zero at
points determined by f0, hhp, and hlp. At some distance
away from f0, the signal is determined by its relative pass
coefficient.
Document No. 001-43151 Rev. *C
19
PSoc® 1 Understanding Switched Capacitor Filters
Table 6. Selected Points on Elliptical Transfer Function
Gain
Condition
Elliptical Filter Example
For this example, the Bessel low pass example will be
modified to add a high pass coefficient one-tenth the low
pass value.
H(s)elliptical ≈ hlp
s/2πf0 = 1/100
H(s)elliptical ≈ hlp
s/2πf0 = 1/10
H(s)elliptical = 0
s/2πf0 = (hlp/hhp)½
H(s)elliptical ≈ hhp
s/2πf0 = 10

Two pole Bessel low pass filer
H(s)elliptical ≈ hhp
s/2πf0 = 100

Cut off frequency of 5 kHz

An over sample ratio of 50 (fs = 250 kHz)

Unity low pass gain

-20 dB high pass gain
Note that an elliptical filter can either be high pass or low
pass. At some defined point, the output rapidly drops to
zero.
The transfer function shown in Equation 38 can be made
two different ways. The first is by taking the Vout2 transfer
Equation 8 and setting Cp to zero. This is shown in
Equation 51.
2
H ( s) elliptical
 C pp C A 1 C1  s  C1

  

 C 2 C3 4 C 2  f s  C 2

2
 C B C A 1 C 4 1  s  C 4 s


   
1
 C 2 C3 2 C 2 4  f s  C 2 f s
Equation 51
The low pass and high pass coefficients are shown in
Equation 52.
hhp 2
1
C pp C A  C1C 3
C
4

 hlp 2   1
1
1
C2
C B C A  C 3C 4  C 2 C 3
2
4
Equation 52
The topology for a PSoC switched capacitor elliptical filter
is shown in Figure 43.
The requirements are:
Standard tables from filter reference books [1] show that the
filter is constructed with:

f0 = 1.274 * 5 kHz = 6,380 kHz

d = 1.732
The coefficients calculated for the low pass part were:

C1= 3

C2 = 3

C3 = 8

C4 = 31

CA = 32

CB =32
Substituting the known values into Equation 52 results in
Equation 53 with a single unknown variable.
1
C pp 32  3  8
4
hhp  0.1 
1
1
32  32  8  31  3  8
2
4
Figure 43. PSoC Two Pole Elliptical Filter
Equation 53
Solving Equation 53 results in Equation 54.
C pp  2.98  3
Equation 54
Substituting this value into Equation 53 results in the
actual coefficient show in Equation 55.
You may notice this topology looks similar to notch filter.
The only difference is that the pass coefficients are no
longer equal. This filter has the advantage of only using
two switched capacitor blocks. The disadvantage is that
interaction between the two blocks near the roll off
frequency keeps it from functioning well for values of Q
much greater than one. Fortunately, when implementing
low pass and high pass elliptical filters, the desired Q is
most certainly never much larger than one.
www.cypress.com
1
3  32  3  8
4
hhp  0.1 
 1.007  .1
1
1
32  32  8  31  3  8
2
4
Equation 55
The block placement is shown in Figure 44.
Document No. 001-43151 Rev. *C
20
PSoc® 1 Understanding Switched Capacitor Filters
Figure 44. Elliptical Filter Example Block Placement
Note that the output goes to zero at about 21 kHz. This is
consistent for a filter with f0 = 6.38 kHz and a low
pass-to-high pass ratio of 10 (6380*10½). Frequencies
past this notch are a little over 20 dB below the low
frequency inputs. Again, this is consistent with the design
constraints.
Summary
Universal two pole filters are the building blocks of all
filters. It can be thought of as having five variables:
The topology of the elliptical filter is very close to a low
pass filter. All that is required to convert the LPF2 User
Module to an elliptical filter is to set the value and input
connection for Cpp. This is done in software.
Cpp is the BCap of the filter’s output block. It must be
connected to the buffer located in ACB0.
The default setting for the input for BCap (Cpp) is ACB00.
No software is required to connect it.
Example Code 4 shows the program that starts the filter
and also configures the BCap (Cpp) value.
Code 4

Roll frequency, f0

Damping Value, d

Low pass coefficient, hlp

Band Pass Coefficient, hbp

High Pass Coefficient, hhp
PSoC has the ability to control and implement all five of
these variables. These filter blocks can be cascaded
together to implement more complex filters. Filter
reference books will have tables of damping values and
roll off frequencies required to implement more complex
filters.
FilterCalc is a program that will assist the user in
determining the best possible capacitor values for their
specific filter requirements.
Filter design spreadsheets are available with the PSoC
Designer documentation. Automated design wizards are
available for placed filter modules.
Filter design for a PSoC system is very straight forward
given a good filter reference book and the tools shown in
this Application Note.
References
1.
Figure 45 is a spectral plot of this filter.
Figure 45 Elliptical Low Pass Filter Spectral Plot
Active Filter Cook Book, Don Lancaster, Synergetics
Press, 2002
About the Author
Name:
Dave Van Ess
Title:
Principal Applications Engineer,
Cypress MicroSystems
Contact:
[email protected]
1
www.cypress.com
Document No. 001-43151 Rev. *C
21
PSoc® 1 Understanding Switched Capacitor Filters
Document History
®
Document Title: PSoC 1 Understanding Switched Capacitor Filters – AN2168
Document Number: 001-43151
Revision
ECN
Orig. of
Change
Submission
Date
Description of Change
**
1779508
TDU
11/28/2007
New application note.
*A
3161559
TDU
02/03/2011
Fixed blurry images and equations.
Fixed Structure and Grammar issues.
Updated Projects to PSoC Designer 5.1.
*B
3433875
QUS
11/09/2011
Template Update
*C
4288471
SEG
02/21/2014
No changes, sunset ECN only
Minor Grammatical Edits.
www.cypress.com
Document No. 001-43151 Rev. *C
22
PSoc® 1 Understanding Switched Capacitor Filters
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Products
Automotive
cypress.com/go/automotive
psoc.cypress.com/solutions
Clocks & Buffers
cypress.com/go/clocks
PSoC 1 | PSoC 3 | PSoC 5
Interface
cypress.com/go/interface
Lighting & Power Control
cypress.com/go/powerpsoc
cypress.com/go/plc
Cypress Developer Community
Community | Forums | Blogs | Video
| Training
cypress.com/go/memory
Memory
Optical Navigation Sensors
cypress.com/go/ons
PSoC
cypress.com/go/psoc
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
PSoC is a registered trademark of Cypress Semiconductor Corp. "Programmable System-on-Chip," and PSoC Designer are trademarks of Cypress
Semiconductor Corp. All trademarks or registered trademarks referenced herein are the property of their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
Phone
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation, 2007-2014. The information contained herein is subject to change without notice. Cypress Semiconductor
Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any
license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or
safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as
critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The
inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies
Cypress against all charges.
This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide
patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a
personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative
works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source
Code except as specified above is prohibited without the express written permission of Cypress.
Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the
right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or
use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a
malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems
application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
Use may be limited by and subject to the applicable Cypress software license agreement.
www.cypress.com
Document No. 001-43151 Rev. *C
23