# analog filter magnitude flatness problem

I have designed an analog filter that includes a high pass filter with a cut-off frequency of 5 Hz and a notch filter with a cut-off frequency of 50 Hz. I want to sample the output signal of the filter and get its amplitude value. But near the cut-off frequencies, the filter response is not flat and causes the gain to change. For example, if I give a signal with a frequency of 40 Hz and amplitude of 1 volt to the input, I receive the same 1 volt at the output. But if I change the frequency from 40 to 49, the amplitude gradually decreases. I can not sharpen the filter response. What is the general solution to improve this problem? I have to sample the output signal and get its true amplitude.

• I wouldn't describe this as a "problem" this is just how filters work. The value you see is the "true amplitude" Aug 4 '21 at 8:59

But near the cut-off frequencies, the filter response is not flat and causes the gain to change.

Well, that is necessarily true for any filter: the implementation of abrupt jumps in the amplitude response is impossible.

I can not sharpen the filter response. What is the general solution to improve this problem? I have to sample the output signal and get its true amplitude.

The true amplitude is what you get. You can of course just correct for the filter gain at the individual frequencies.

Other than that, you can of course build a better analog filter (more stages, more complicated, active filters...), but that comes at a high cost in complexity, effort and tolerances.

Instead, the usual solution is to use an analog filter that has a higher cutoff frequency, so that all the frequencies you care about are in the "sufficiently flat" part of your filter's amplitude response (however you define sufficiently flat), and sample at a rate high enough to for that filter. Then, you do the filtering in the digital domain: since your frequencies are very very low, there's really not much samples to deal with, even if your sampling rate is, say, 2000 times higher than your signal frequency.

Building a digital filter that is close to your ideal specification is much easier; but beware, you still can't do an abrupt jump from pass- to stopband; that's still not possible in digital domain.

So, no matter what you do, the first step is always writing down an explicit, hard numbers, no vague-statement filter specification as in, for example:

I need a filter that

• has no more ripple than 2 dB in the pass band
• the pass band goes from 0 Hz to 49.90 Hz
• has at least 50 dB of attenuation in the stop band
• the stop band starts at 50.08 Hz upwards.

A single number (3dB cutoff frequency) really isn't sufficient here!

I put in random numbers there – but it's really important that you think about what your application really needs to function. Almost certainly, you do not incur a significant error if, say, you don't suppress things at 49.9999 Hz. So, define a sensible width within you transition from pass- to stopband, and all the methods of digital filter design are open to you. In fact, in most cases, you just plug that very specification into a tool (e.g. pyfda) and just get a filter back.

• Thank you for your reply. Do you think I can get a relationship for gain by giving different inputs and measuring the output at different frequencies? Does this make sense? Aug 4 '21 at 10:12
• no, that doesn't make much sense. what you get is the true amplitude: this is just how a filter works. Aug 4 '21 at 10:19
• Not sure what you mean by "a relationship for gain". It sounds like you might mean the filter's amplitude response. If that's the case, then yes, you put a sine wave in and measure the sine wave out and determine the gain. If that's not the case then you're off the beaten path of signal processing, and quite possibly are lost. Aug 5 '21 at 2:18