Advertisement

Blog The Filter Wizard Remastered

An Excelent fit, Sir!

See an updated 2019 version of this article here.

 

The cat is out of the bag. PSoC3 , Cypress’s new family of programmable mixed-signal systems-on-chip, has been announced. Visit our website to learn why, whatever you do in electronics, it’ll be a paradigm-buster for you. Phew, it’s hot in here, off with that marketing hat …

This is the first of two columns showing a simple technique for designing, optimizing and implementing a response-equalizing filter. The second part will look at implementing it on PSoC3; this part is about the design process. Figure 1 is the first piece of our story. It’s the curve of the sensitivity of a sensor versus frequency (what kind of sensor, do you think?):

The customer wanted to equalize this so that the final sensitivity would be “independent of frequency”. Now, an elementary rule of Filter Wizardry is: the frequency response of a filter doesn’t stop at the edges of the graph . It’s important to understand what the response should do outside this range. “Don’t Care” doesn’t mean “Don’t Need To Care”.

Now, I’ll wager that the response of that sensor continues to fall off at 20dB/decade outside the graph limits. But it would be a terrible idea to boost the response with gain that continues to rise without limits. We’ll want the response to flatten off or even fall back down, to avoid noise problems. For a first try, let’s hold constant the response outside figure 1’s frequency range, for one extra decade in each direction; figure 2:

We want to design a realizable filter with a frequency response approximating this curve to an acceptable error. The low frequencies involved indicate using a digital filter to avoid bulky external passive components. That’s handy, because PSoC3 has a built-in 24bit digital filtering engine, so fast that it’ll hardly have to wake up to crunch out anything I’ll ask it to do here. The digital stuff is for the next column; first, let’s design it in the analogue domain.

Figure 2’s response is flat at one end, wavy in the middle and flat at the other end (apologies to Monty Python); that’s a second order ‘shelf’ equalizer. The amplitude response of the general second order transfer function or ‘biquad’ section:

is easily computed in a spreadsheet. With ω equal to the input frequency divided by the frequency to which the transfer function is normalized, a bit of manipulation gives:

Figure 3 is a clippet of a working spreadsheet, using one column for each biquad section, with the cell formula shown in glorious Excelcolor. The gains of all the sections used are multiplied up (linear gains, not dB) and deposited in column G:

Now we need an initial coefficient guess; here’s how I’d do it:

1 the middle of the frequency range is around 0.3Hz so that’s where we’ll normalize everything to.
2 at high frequencies we need a gain of 10, so that’s the ratio of the s2 terms.
3 at low frequencies we need a gain of 1, so that’s the ratio of the constant terms.
4 we need a guess at the dissipation, which is the reciprocal of the ‘Q’ of the denominator, and sets the denominator s1 term. The filter covers a frequency range of about 1000:1. My guess is the square root of this , say 30.
5 at mid frequencies we need a gain of 0.4, and very roughly indeed we can set the ratio of the s1 terms to this. In other words, I guess:

Check out the response ” not bad, figure 4:

It’s not perfect; let’s get the spreadsheet to find a better fit. We need response limits, and a measure for how far out the result is. We’ll use the “method of least squares”. For any point whose gain goes outside set limits, take the square of the relative gain error (1?”generated_gain/required_gain) at each frequency, and add ’em all up.

For the response limits shown in figure 5, I allowed 1% gain variation in the passband, and between 2xrequired and 0.1 in the bands outside. If a response point lies between these limits, it doesn’t contribute to the error function.

Now we use Excel’s Solver to ‘improve’ our response. Configure it to minimize cell A2’s value by adjusting the cells holding the filter coefficients (allowing only positive solutions), and click ‘solve’ to get figure 6:

Actually, I’m making it look a little easy. Excel’s solver is prone to settling on a poor local minimum if your initial guess is too far out, so you sometimes need to intervene to help it.

This seems good in the desired frequency range, but that gain is still high outside the passband, especially at the higher frequencies. How about adding another filter section to chop off the low and high frequencies? Separate single pole lowpass and highpass filters would do. But did you realize that you can combine those single pole filters into one two-pole bandpass? It means we can reuse the formula we already created. I’ll try a section with the same denominator as my first guess, but with only the s1 term in the numerator non-zero, set to match the denominator:

Let’s also be more aggressive with those upper gain limits, forcing them to fall outside the band, figure 7:

We invoke the solver again, and get figure 8:

which is falls away nicely on both sides. It’s still an analogue filter; in the next column we’ll look at issues involved with turning it digital – in the same spreadsheet – then implementing it and analyzing it. Let me know if this technique could prove useful for your filter curve-fitting – Kendall.

This guest column is written by Kendall Castor-Perry, Principal Architect, Precision Analog at Cypress Semiconductor. Kendall is an experienced analog designer, filter wizard, audio expert, systems engineer, technology marketer and product manager. Links to his previous columns can be found below:

One giant squeak for Mankind – Revisits an audio circuit project from ‘Practical Electronics’magazine, May 1969.

Use it or slew it – Provides advice on how to determine the slew rate needed from an opamp.

An E96 formula: how can you resist it? – Kendall discusses the value of spreadsheets when calculating component values.

Ping! And the accuracy is gone – Where exactly does the ringing come from when you sample the input voltage of a high-speed ADC?

Alias, damned alias and statistics – Does ‘aliasing’ need fixing, asks our filter wizard, and does fixing it cause problems elsewhere?

Who, what and why? – Analog DesignLine Europe’s expert columnist introduces himself.

0 comments on “An Excelent fit, Sir!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.