# How to design a resampling filter?

All the references I can find only describe how to design an idealized lowpass filter for doing resampling. For example, MATLAB's documentation describes how to choose a "cutoff frequency" (for rational-ratio resampling):

Something like this:

We can't implement an ideal filter, so a slightly better approximation would be to introduce a transition band:

So, how should I set the passband edge $$f_{pass}$$ and stopband edge $$f_{stop}$$?

The only idea I have is to consider halfband filters. In halfband filters, there is symmetry about $$f_c$$. So, for example, in a halfband decimator, we could set $$f_{pass} = 0.9f_c$$ and we would get $$f_{stop} = 1.1f_c$$. This works rather nicely because anything input between $$f_c$$ and $$f_{stop}$$ will only alias back into the transition band (so the passband $$0$$ - $$f_{pass}$$ is clean).

Is that a reasonable approach in general? We just place $$f_{pass}$$ and $$f_{stop}$$ symmetrically about the theoretical cutoff frequency $$f_c$$?

• Hay did you get my email? I presume you have MATLAB, but if you don't, I dunno how to convert it to Python or something easy. Maybe it's can work in Octave. Commented Aug 13 at 3:10
• @robertbristow-johnson Yes - received with thanks. I hope to find time to take a look this weekend. At a first glance, the default behavior looks the same as in my question above. Commented Aug 15 at 5:59

Like most filter designs, choosing the "best" resampling filter involves a fairly complicated tradeoff that depends on the requirements of your specific application and the properties of the signals you want to resample.

1. Usable bandwidth
2. Passband artifacts in magnitude, phase and group delay
3. Amount and frequency range of residual aliasing
4. Causality and pre-ringing in the time domain.
5. Transient preservation in the time domain.
6. Edge effects
7. Latency
8. Implementation properties (CPU, memory, real-time requirements, etc.)

You typically need to figure out what's the best combination of all of these depending on what you need and, even more so, which type of artifacts or residual error you are most sensitive to.

• Do you know anywhere that these trade-offs are discussed? In many cases (perhaps even the majority), some/most of the points you mentioned are unknown to me. So, I'm also interested in "typical" general-purpose (safe, albeit sub-optimal) approaches. Commented Aug 4 at 12:35
• Maybe this?
– Jdip
Commented Aug 4 at 12:42
• @Harry: this will be covered in most college-level classes on filter design. I don't think there is much of a shortcut to be had there: the math behind all of this fairly complex and without a good math foundation its very hard to get a hold on how all these trade-offs are interlinked. Matlab has a default filter for their resample() function, which is probably based on whatever they consider to be "typical". I don't know what thought process or analysis went into that choice. Commented Aug 4 at 15:05
• @Harry: "one size fits all" is a problematic choice here. For example: in a control loop application like an acoustic noise canceling headset even the smallest amount of latency is a huge problem. For resampling an audio file from 48kHz to 44.1kHz you don't care about latency at all. Commented Aug 4 at 15:07
• @Hilmar My college (one of the good ones) didn't have a class covering filter design in this kind of detail. And my web searches didn't pick up any useful lecture notes from other colleges. Please let me know if you can recommend any specific books on filter design. (A couple of my DSP textbooks cover the basics, but not this kind of detail). My math foundation is reasonably good (PhD in EE), but I'm forever trying to fill in the gaps! Commented Aug 4 at 16:22