# Amplitude and phase compensation of analog filter

My analog filter perform much needed antialiasing and input protection. Unfortunately, the filter adds undesired changes in the gain/phase across frequency. For example, here is an example of amplitude ripple across frequency:

My goal is to have a flat passband. However, as you can see, the passband is not flat. Is it possible to design a digital filter to remove the ripple in the passband, potentially even correcting the roll-off which will occur all the way to the stopband?

Thank You,

Ethan

• Depending on the details, It will be difficult. Maybe you could replace your antialias filter with a Butterworth filter and eliminate the ripple?
– MBaz
Sep 14, 2021 at 0:40

Is it possible to design a digital filter to remove the ripple in the passband

Yes, but it's difficult and it also depends on the specific filter and the exact requirements of your application.

Generally this can be done by designing either and IIR of FIR filter with a least square error optimization method using the inverse filter as a target. The tricky part is to formulate the error criteria to get the best trade off between passband flatness, causality, phase or group delay distortion, filter complexity, latency, ect.

In addition, least squares for IIR filters is a notoriously difficult mathematically (and numerical) problem and often requires some "intelligent" search algorithms.

It helps if your original filter is minimum phase. That means that it's inverse exists and is also minimum phase, so you could use that as a starting point.

Is it possible to design a digital filter to remove the ripple in the passband,

Yes, but.

In addition to the difficulty that Hilmar mentions, just pertaining to finding a filter, if you try this you'll find that a real analog filter also varies from part to part, and over temperature, aging, etc.

So if your need is critical, and you're designing for production, you'll find that some of your systems will work nicely some of the time (when the filters match what you designed to, because of part variation and environmental factors), but none of your systems will work all of the time.

You can get around this by choosing more precise components in your analog filter, but that's expensive, and introduces supply-chain difficulty. In fact, the general trend in this area has been to just sample faster, use a "looser" analog filter, and possibly put that really nice anti-alias filter into the digital realm, right before you down-sample the signal internally.

potentially even correcting the roll-off which will occur all the way to the stopband?

Probably not. Generally the analog to digital conversion process introduces quantization noise, which is spectrally flat. Trying to reconstruct the signal when it's been severely attenuated means amplifying that noise along with the signal -- you'll just end up with lots of high-frequency noise that's masking your high-frequency signal.