# Is there really no perfect digital filter?

In context of transition width vs. stopband attenuation, different windows (Blackman, Hamming, etc) are compared in terms of tradeoffs between the two, always noting that one cannot perfect both.

Why not? Make it long enough - problem solved. We're working with finite frequency and amplitude resolution, not infinitely granular as in continuous. If not per ADC, then float precision's dynamic range inherently limits a signal's very sample values, and any filtering thereafter - and it doesn't end there$$^1$$.

Then the actual limitations on frequency/amplitude filtering stem from ADC/DAC/float precision, not filter design. Of course, in practice, we also care for performance - and a trillion-sample filter just won't do, so tradeoffs matter. That said, isn't below the more accurate formulation?

For a given filter length, each design has tradeoffs. If length is limited, none resolve a signal perfectly - otherwise, the differences between filters vanish within ADC/float dynamic range.

1: The Universe itself, per standard model, is finitely-resolved. Electron energy levels, Planck length, etc - limit the smallest possible frequency/amplitude increment of a signal. (... probably. Not an expert.)

Note1: assume "the signal" here is post-ADC, rather than the analog input, which would then add ADC itself to the question. So take a "perfect" or "good enough to not distort/lose anything" ADC. With short filters, we can quantify transition bands, stopband attenuations, ripples, etc, and their deviations from "ideal", $$\Delta$$.

"Perfect", then, is defined as $$\Delta$$ being so small, that even with a mathematical function describing the signal (perfect resolution), and mathematically convolving with the filter (literal perfection), the resulting (discretely sampled) signal would be identical as if convolved discretely with a finite filter.

Note2: I'm not concerned with eliminating noise from the signal, or any other parameter besides what's explicitly named; consider noise as part of "the signal".

Note 3: Mathematically: Suppose we have the function for the input, $$i(t)$$, and for the filter, $$f(t)$$. Then, we can convolve mathematically ('ideally'); call the result $$g(t)$$. Now discretize: $$\rightarrow g[n]$$. Next, do all this digitally, with $$i[n]$$ and the finite filter $$f[n]$$; call the result $$h[n]$$. Then, the filter is "perfect" if $$h[n] = g[n]$$.

Re: Dan's answer -- Many practical points, but not quite addressing the question. See Note 3, in context of Note 1; former asks for much more than latter, implying any $$f(t)$$. The context here is frequency filtering, i.e. low-pass, band-pass, etc, example being windowed sinc.

To answer this question, one must show one or the other:

1. No perfect filter: there is no $$f[n]$$ satisfying Note 3. Approximation error, plus add/multiply float(64) error, exceed float's representation error (i.e. $$g(t) \rightarrow g[n]$$).
2. Yes perfect filter: present $$i(t),\ f(t),\ g(t),\ g[n],\ i[n],\ f[n],\ h[n]$$, and code for generating and computing the latter four, and $$\text{MAE}(g[n] - h[n])$$. If insufficient RAM, show that it'd work with more RAM.

By these criteria, 1 will obviously win, as float is notorious for add/multiply imprecisions. But that's not meaningful, nor useful; if add/multiply is the bottleneck, we can use better than float64 to compensate. Thus, the condition for "perfection" is a "negligible" $$\text{MAE}$$, or "very close" to float roundoff. The representation error is also a matter of granularity.

• Besides the accurate answer by Dan, one more practical limitation is numerical resolution: a very long filter will have very small coefficients, so small that they underflow an IEEE floating point number. You'd need arbitrary-prrecision aritmetic, which exists, but is very slow to compute with.
– MBaz
Sep 21, 2020 at 17:55
• @MBaz Good point, two forces at play, but again with a workaround. Sep 21, 2020 at 20:47
• I think I see what you are really trying to ask--- "perfect digital filter" would be interpreted by most as the "ideal" (brickwall) filter. Are you asking if the discrete time impulse response can sufficiently approximate a continuous time one (to be a "perfect" representation)? What exactly is the purpose of your filter? I am trying to read the comment under your first note: a mathematical function describing the signal with perfect resolution: do you mean a continuous time signal? And convolving that with a continuous time impulse response? Sep 21, 2020 at 20:53
• So your question is, is it possible to perfectly (within the accuracy of precision offered) represent a given continuous time filtering process in a discrete time system? Or what then does "perfect" mean? Sep 21, 2020 at 20:59
• @DanBoschen Yeah, brickwall, which is sinc, so if we have the mathematical function for the input signal, $i(t)$, then we can compute the convolution mathematically ('ideally'). Call the result $g(t)$. Now discretize: $\rightarrow g[n]$. Next, do it all digitally, with $i[n]$ and finite windowed sinc, call the result $h[n]$. The windowed sinc is "perfect" if $g[n] = h[n]$. Sep 21, 2020 at 21:00

Yes Virginia, There is a perfect digital filter.

I assume the OP means by "perfect filter" what we would typically call an "ideal filter": which is a filter that passes a finite block of frequencies with no alteration and completely removes all other frequencies, which is referred to as a "brick wall filter". Otherwise if the OP simply means a filter whose distortion is less than our "increment of concern", well then all properly designed filters will do this, achieving sufficient rejection, minimum passband distortion and minimum transition bandwidth so as to not degrade our requirements often for use in communication waveforms summarized in an SNR metric on our waveform-- I would prefer to refer to these as "sufficient filters" as referring to this as a perfect filter would confuse most with the brickwall filter previously mentioned- which, like Santa Claus, "exist in our hearts and minds as certainly as love and generosity and devotion exist".

That said, let me elaborate in the challenges to achieve the "perfect filter". The transition band requirement is often the most challenging, especially when the OP has clarified performance is limited by ADC technology, and there is no ADC available that would surpass the precision available in the remaining digital system (meaning for any ADC available we can easily design a digital system with passband ripple or stop band rejection that is less than the ADC quantization). For transition band requirements this is not the case, as it is not the amplitude quantization, or time quantization (sampling rate) that limits the transition band. What limits the achievable transition band specifically is the time duration of the filter's impulse response, which applies equally to digital as well as analog filters. At a given sampling rate, the number of samples is directly proportional to the time duration, but focusing on time provides more direct insight into the restriction. This is the time frequency duality that in order to have infinitely small frequency resolution (brick wall filter) we need to have an infinitely long time duration. By choosing the number of samples in the filter, we are choosing the time duration which then drives filter complexity for any given sample rate. Further for real-time filters, there will be an inevitable delay due to causality that is proportional to this time duration: filters with steeper rejection (higher selectivity) must have longer delay. Adding delay in many applications is a concern and is far from "perfect".

The last statement by the OP that the filter is to not eliminate noise from the signal, and that the signal represents everything the ADC presents- well in this case if the "filter" is not rejecting any other noise (where noise can be interference, other signals we aren't interested in, quantization and thermal noise etc), then this is not a "filter" at all in any traditional sense of the word- and the simple answer of what the "perfect filter" is that would not change the ADC in any way is a one-tap FIR filter with coefficient = 1 (the unit-sample function). I don't think this is the question, and then that last statement and this trivial answer doesn't really make sense.

If the OP assumes that all noise is only introduced by quantization, this is not typically true in a well designed system since we are interested in measuring or being limited by the noise that is in the original waveform that was sampled. We would typically choose quantization so that we are observing the actual noise in the signal (rather than drowning that out with more noise that we artificially add) --so it is not necessarily the quantization that allows for a "perfect filter" since regardless of quantization we still filter to reject the noise components in the signal itself that the quantized samples are representing.

For example, if we had a continuous-time sine-wave with an SNR of 20 dB, I would typically choose a quantization such that the additional noise added is at least 10 dB lower in the final filtered signal (limiting the SNR degradation to 0.4 dB), so for a full-scale sine-wave this would be a quantization of approximately 5 bits. Thus the noise that we would observe in this case is NOT the quantization noise that is 30 dB down but the noise in the original waveform itself that is 20 dB down. Any less quantization and would simply be further degrading the SNR.

So given a filter with interest in passing frequencies up to $$f_1$$, the signal will have noise components at $$f_1+\Delta$$ that the ideal filter would need to remove but for all practical filters there will exist a $$\Delta$$ that would be in the inevitable "transition band" of the filter. Thus we have the trade of filter complexity, sampling rate and frequency planning considerations in our digital filter designs.

This graphic may help illustrate what occurs in the digital filter design and how "windowing" can help improve rejection at the expense of widening the transition band:

In the upper left we see the ideal filter with a "brick-wall" frequency response. To realize such a response, the filter would need to have a Sinc function as the impulse response (the inverse Fourier Transform of the desired frequency response is the impulse response). The Sinc function on its own is non-causal: extending to $$\pm \infty$$, so we need to both delay the Sinc function in time and truncate it in length to be realizable. This step alone is delaying and then multiplying the desired Sinc function with a rectangular window (in time). The discrete version of this window is $$N$$ samples long, and the product in the time domain results in a convolution of our desired brickwall filter in the frequency domain with the Dirichlet Kernel (which is the Fourier Transform of the rectangular window, basically an aliased Sinc function in the frequency domain: for very large $$N$$ the Dirichlet Kernel approaches a Sinc function). The main lobe of the Dirichlet Kernel has a first null at $$2\pi/N$$ in frequency where the sampling rate is $$2\pi$$ radians/sample. Thus our perfect brickwall filter will now because of the windowing have a transition band that is $$2\pi/N$$ to the first null in frequency. It will also have significant sidelobes in the stop band and passband ripple in the passband due to the this convolution. Windowing with improved windows (Kaiser, Hannning, Blackman-Harris, etc) serve to significantly reduce the sidelobes and passband ripple but in all cases they will have an even wider transition band! The transition band is usually what limits the performance or drives the complexity of the filter and is typically a design consideration at the system level.

This result here with the rectangular window where the transition to the first null at $$\Delta \omega 2\pi/N$$ factor is not coincidental to the estimates for the number of taps needed to realize a digital filter with a certain transition band requirement as detailed here: How many taps does an FIR filter need? when you make the frequency axis normalized radian frequency. Here we get with a rectangular window $$N = 2\pi/(\Delta \omega)$$ (which works out to be $$\Delta F = 1/T$$ in continuous time), while with fred harris' estimate (for windowed and least squares designs) we get:

$$N \approx \frac{A}{22}\frac{2\pi}{\Delta \omega}$$

Where $$A$$ is the stopband attenuation needed in dB, and $$\Delta \omega$$ is the fractional radian frequency of the transition band, and $$N$$ is the number of taps needed to realize this rejection within this frequency distance from the passband.

This is detailed further at this post, which also contains "Kaiser's Formula" which also has the $$\Delta \omega/(2\pi)$$ factor but includes the effects of passband and stopband ripple explicitly. These are estimators and the typical approach is to use these as starting points and then iterate the number of taps needed once the performance of the filter with a given number of taps is reviewed in comparison to target requirements.

Next as MBaz has suggested in a comment to the OP below the question, the precision of the coefficients themselves will limit our ability to achieve a filter that can provide rejection beyond the dynamic range of the precision of those coefficients. But as I stated, if we are limited by ADC technology then achieving this is trivial and failure here would be a result of poor design rather than limits of technology. However, if "perfect" means provide a rejection beyond the noise floor of the precision of the number system, this too is not achievable.

The typical guideline is to use 2 more bits of quantization for the coefficients over the datapath. The rejection is limited by coefficient precision by a typical factor of 5 to 6 dB/bit (5 dB/bit due to correlation in the coefficients as fred harris points out, 6 dB/bit is what would be expected for uncorrelated samples). So if we limited the coefficients to 8 bits (for example) the rejection of the filter would be degraded to 40 to 48 dB even if we had designed the filter for more (such as in the graphic below which in this case resulted in being closer to 6 dB/bit). An 8 bit datapath can provide 50 dB SNR otherwise to a sine-wave so the filter with 8 bit coefficients would fall far short of perfect. The same argument would apply to a filter with double-precision floating point data-path and coefficients if "perfect" means we wish the filter rejection to exceed this.

• What do you mean by "time duration"? As for duality - what I'm saying is we don't need infinite resolution, since the signal itself is not infinitely resolved to begin with. i.e., even if we have the exact function describing the input signal, and we filter it mathematically and exactly, the results at the output of a digital filter, limited by DAC/ADC/float dynamic range, will be the same as with a sufficiently long digital filter. Sep 21, 2020 at 16:31
• The discrete-time signal in frequency is continuous with regards to the filter so we are concerned with the filter performance at all frequencies on the continuous domain. If you say the signal is exactly the same then you are saying the noise that exists in the continuous-time signal that was ultimately sampled is less than your limits of concern. This is not the definition of a "perfect filter" but of a "sufficient filter". Time duration is the span in time for the coefficients in the filter (the amount of memory in the filter). Sep 21, 2020 at 16:38
• This may also help: dsp.stackexchange.com/questions/38564/… Finite passband ripple, stop band ripple and transition bandwidth is usually not referred to as a "perfect filter" while perfect filter is typically a brickwall filter. Sep 21, 2020 at 16:42
• @OverLordGoldDragon there is really no perfect (ideal) analog filter as well... ;-) so it's not the fault of the digital domain. An ideal brickwall filter cannot be implemented in any domains. Sep 21, 2020 at 17:23
• @Fat32 Exactly hence my first sentence in the second paragraph. Although any filter I design is certainly perfect in most eyes! :) Sep 21, 2020 at 17:25