Quote of the Day
Torture the date, and it will confess to anything.
— Ronald Coase, data scientist
Introduction
During a recent circuit design review, I saw the need for a simple two-pole filter in one region of the circuit. As I thought about, this filter might be a good example to work through here in the blog. While the application is rather routine, it does illustrate the general process involved in designing one of the most common forms of a low-pass filter.
This is also good application for a computer algebra system. I chose Mathcad, which did a very nice job.
Requirements
I am constantly amazed at how many people try to "short-change" the amount of effort they spend on determining requirements. I make sure that I have the requirements fully determined before I start designing. As far as I am concerned, every minute spent working on the wrong problem is a minute wasted.
This does not mean that determining requirements is easy. I refer to this process as "The Treasure Hunt." Requirements are my treasure and, like any real treasure, you may have to look hard to find it. In this case, the requirements were pretty obvious:
- The output of the filter is a quasi-DC voltage level (i.e. it changes slowly and infrequently)
We are using the PWM generator followed by this filter to build a "poor man's" a digital-to-analog converter (DAC). We are working with a very low-cost device that has a PWM generator but not a DAC. Our cost goals are so tough that we cannot afford to add a DAC. - The input to the filter is a pulse train that is pulse-width modulated.
As mentioned above, we have a PWM generator available for free and we want to re-task it for use as a DAC. - The input level is from 0 to 1 V with a modulation rate of 100 kHz.
The PWM generator uses 100 kHz switching frequency and we need to filter this component out to achieve a smooth enough DC level. - The output level is from 0 to 5 V and is to be a DC level with less than 0.5 mV of ripple.
We need a relative steady voltage level. With an input amplitude of 1 V and an output amplitude of 5 V, it also means we need a circuit with some gain. - The circuit is not sensitive to offset voltage or any of the other op-amp imperfections.
Some applications are very sensitive to common-mode errors, offset voltage, or bias currents. This application in not one of those.
Design
Approach
Given the operational requirements listed above, we can derive some design requirements as shown below.
- I need to attenuate the PWM-induced voltage ripple by at least 4 orders of magnitude (5 V/10,000 = 0.5 mV).
- Attenuation by a factor of 10,000 means 80 dB of attenuation .
- As a working assumption, set fBW = 100 Hz.
This means we will have 3 decades of frequency rolloff to reduce the filter gain down by 80 dB or more. A wider transition region reduces the order of the filter required. - A 2-pole filter should provide more than enough attenuation.
A 2-pole filter provides 40 dB of attenuation per decade of frequency rolloff. A 2-pole filter should be able to meet 80 dB of attenuation over 2 decades of frequency rolloff. Since we have 3 decades of frequency rolloff to work with (100 Hz to the 100 KHz PWM frequency), I should actually see 120 dB of attenuation (more is good). So I will set the filter bandwidth at . - The circuit needs a gain of 5 at DC (0 Hz)
Basically, the circuit will need to amplify a pulse train with a 1 V peak amplitude to a DC level with a 5 V peak amplitude. - The circuit needs to have a low output impedance.
This means that I really would like to have the voltage come directly off of the output of an opamp.
The circuit does not have stringent transient response requirements. I just need a nice, stable, filter circuit (i.e. no high Q poles). In this situation, many engineers will choose a Sallen-Key circuit configured to implement a Butterworth filter. That is exactly what I will do here.
Butterworth Polynomial
Implementing a Butterworth filter means coming up with a physical realization of a Butterworth polynomial. Normally, I just read the polynomial from a table. For illustrative reasons, I will forgo the table look-up and will derive the second-order Butterworth polynomial using the key defining characteristic of a Butterworth polynomial – maximal flatness at 0 Hz.This same approach can be used to determine the Butterworth polynomial of any order. I will also show any other Butterworth polynomial can be found.
Maximal flatness means that the first n-1 derivatives of the magnitude-squared function equal 0 at 0 Hz. Most filter design work (analog and digital) is done using the magnitude-squared function . This is because can always be expressed as a real-function of ω2. As you will see below, this makes taking derivatives fairly simple.
We can set the first n-1 derivatives to zero because (1) we have n coefficients (i.e. n degrees of freedom), and (2) we use one degree of freedom when we set . With a second-order filter, this means that the first derivative of .
Equation 1 shows the general 2-pole, low-pass, magnitude-squared function.
Eq. 1 |
where
- K is the gain at 0 Hz (5 in this case).
- A, and B are polynomial coefficients.
In Figure 2, I use Mathcad's symbolic solver to show that A = 0 and B = 1.
In Figure 1, we derived the magnitude squared function . We can use the magnitude squared function to derive the Butterworth filter function (Figure 3).
Thus, the second order Butterworth polynomial is , where sn is the normalized Laplace frequency variable. This polynomial agrees with that listed for the second-order in this table of Butterworth polynomials.
We can prove that the general form of the magnitude-squared form of a Butterworth Polynomial of order n is . Figure 4 shows how Mathcad can be used to generate a table of Butterworth polynomials.
Sallen-Key Circuit
Figure 5 shows the Sallen-Key circuit, which is a very commonly used circuit for this type of application.
I have used this circuit many times with much success.
Analysis of Sallen-Key Circuit
Figure 6 shows a standard Kirchoff's Voltage Law (KVL) analysis of the Sallen-Key circuit.
Standard Solution
I usually do not work with filter equations in the form shown in Figure 5. I like to normalize the frequency variable, s, relative to the filter bandwidth ().
Normalized Form
Figure 7 shows the Butterworth equation normalized to the filter bandwidth. This is the equation form normally shown in the filter design tables.
Component Determination
Figure 8 shows how we can determine the component values required for this implementation using the equation solving abilities of Mathcad.
We can now generate a plot of the filter magnitude characteristic using these component values.
Gain Characteristic
Figure 9 shows the gain characteristic of this design. As expected, we are seeing 120 dB of ripple attenuation. The gain at 0 Hz is 5, so that requirement is also met.
Conclusion
This was a good example of a common filter design problem. I have used both circuit simulators and computer algebra software to design these filters. I have come to like computer algebra software for this kind of work because it gives me equations. These equations allow me to see how the output varies as a function of individual component values. This means that I can see useful approximations.
Very nice clear demonstration of mathcad for circuit design.
One caveat: If you actually build or even Spice this circuit you find the stopband will not follow the monotonic rolloff shown at higher frequencies in the graph. This is because the idealized response calculated, assumes ideal opamps with zero output impedance. At some higher frequency the complex opamp output impedance rises to levels where the overall transfer function allows HF signals to pass through the filter with little attenuation. Worse still opamp nonlinearities,slew rate assymetry etc, may even rectify those signals leading to DC offsets in the filtered DC output that you want to measure. For your particular PWM application this may or may not be an issue depending on opamps chosen,the frequencies used and precision required.
My blanket solution is to always**Avoid all second order Sallen and Key filters** and use 3rd order versions. These only add a single R + C (passive LPfilter) in front of the above second order filter. That greatly improves the HF roll off and keeps any large HF signals from opamp inputs which usually avoids the opamp-non-linear issues creating DC offsets.
Obscure fact : "slew induced offsets" in opamps can occur well below levels where slew rate limiting is actually occuring. This is internal opamp topology related and hard to predict from opamp data sheets, except that high GBWP opamps are generally better.
Excellent comment. I have to smile at your comments about slew rate and output impedance. My graduate adviser (Aram Budak) always told me to be wary of these two opamp characteristics. The rectification issue, in particular, is one that has thrown me for a loop a couple of times. I should also mention that many designers (e.g., Jim Williams) would not use this circuit because they have a rule that they "always invert" in order to avoid CMRR issues.
mark
>>I should also mention that many designers (e.g., Jim Williams) would not use this circuit because they have a rule that they "always invert" in order to avoid CMRR issues.<<
I agree in general that inverting amplifiers are better in many applications but there are some other trade-offs as well. This circuit at least for the unity gain versions may have lower noise gain and lower drift than some topologies. The third order version is also better for reduced common mode errors due to common mode slew rate. Inverting filters often have more matched parts in filter so that maybe why Sallen and Key filters are popular. A general criticism of Sallen and key filters is the component sensitivity can be worse than some other filter topologies and somewhat counter intuitively, as far as I remember, the GBP sensitivity is worse for these.
An obscure argument is sometimes made that you should always choose odd order filters but I can't remember the rationale.