2x oversampled IIR HP/LP filter code?

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

I need some simple HP/LP 12dB/Oct filters (similar to RBJs) that are oversampled so as to hold their shape as fc approaches Nyquist. Can someone point me to code for such - or explain the approach to "oversample" inside the filter code? I did it once before but don't recall the tricks so that gain, fc and Q remain as intended.

Any info appreciated!

Post

I'm not sure about upsampling "inside" the filter. Typically you would upsample the input signal, filter then down sample.

But it's probably more efficient to use some kind of modified matched z transform filter and get a very closely matched frequency response at the base sample rate. Like this example:

Matched Second Order Digital Filters

Post

Thank you for the info and link. It was several years ago when I did the oversampled IIR but I remember it was straightforward and simple - like running the filter twice (with coefficients calculated at 2x samplerate) than summing the 1st and second outputs. I've tried that now but it doesn't seem to be working right, so there's something I'm missing.

Post

Something like that should work. Feeding the same sample twice is equivalent to a really low quality low pass filter, so you'll just have to deal with that causing roll off in your passband. You'll also have aliasing in your frequency response. But other than that it should work

Post

matt42 wrote: Sat Apr 17, 2021 11:00 pm Feeding the same sample twice is equivalent to a really low quality low pass filter, so you'll just have to deal with that causing roll off in your passband. You'll also have aliasing in your frequency response.
LOL - sounds horrible (pun intended). Maybe that's why I abandoned it!

Will study your link. Thank you.

Post

I remember what I did. It's simply the classic oversampling technique using "zero stuffing".

Run the filter twice (with coefficients calculated at 2 * samplerate) but use 2 * input as the first pass input and 0 as the second pass input. The 2 * input is for gain compensation and 0 input on the second pass (rather than repeating the input sample) eliminates aliasing. That second pass allows the filter to settle to a more accurate end than it would with just a single sample (i.e., it's "oversampled").

I tried it with RBJ filters and it works. AFAIK this technique can be used with nearly any IIR filter (watch out for levels with 2 * input) and can be expanded/looped for any desired integer oversample rate.

Cool. Now I have a lot of other ideas on where to use this....

Post

It'll work, but aliasing will effect the frequency response. The amount will vary depending of the filter parameters

Post

matt42 wrote: Sun Apr 18, 2021 6:53 pm It'll work, but aliasing will effect the frequency response. The amount will vary depending of the filter parameters
Yes...seems I spoke too soon. It works pretty well on LPF but not on HPF.

Post

When zero padding, the spectral content of the signal is mirrored above the original nyquist. For decent resampling a steep low pass filter, centred around the nyquist frequency, can be used to remove the mirrored frequencies.

In your case the low pass will act, to some degree, as an anti aliasing filter by removing some of the content above the original nyquist frequency. Whereas the high pass removes non of it, so the frequency response will suffer more as a result

Post

matt42 wrote: Sun Apr 18, 2021 8:25 pm When zero padding, the spectral content of the signal is mirrored above the original nyquist. For decent resampling a steep low pass filter, centred around the nyquist frequency, can be used to remove the mirrored frequencies.

In your case the low pass will act, to some degree, as an anti aliasing filter by removing some of the content above the original nyquist frequency. Whereas the high pass removes non of it, so the frequency response will suffer more as a result
Yes, I understand. I use oversampling w/FIR methods in other applications but I was hoping there was, perhaps, a shortcut to be found here that would that avoid that complication and FIR latency. I saw a similar "run it twice" approach described in Music DSP but it didn't work well here so I tried to roll my own. Will try some other things.

BTW - I am using RBJ filters - which produce fairly accurate response curves over most of the audio range - but I'm getting some erratic phase shifts at different Fcs which is messing with transient response. Not sure what's causing that. I tried a State Variable algo and got smooth phase response but it had gain drift with Fc, so it's no good either. Any favorite, well-behaved, filter algos you use? I need 2nd order HP and LP with variable Q and Fc.

Post

For the best behaved under modulation I'd recommend a zero delay feedback/TPT state variable filter. You could look up The Art of VA filter design , also there's an implementation in the technical papers area of the cytomic website

Post Reply

Return to “DSP and Plugin Development”