Anti-Aliasing files for sampler playback

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

A wavetable synth is pretty straightforward: you have a 2048 length buffer and use FFT to anti-alias it to fit the pitch, and then you oversample it to get ride of any remaining artifacts.

Let’s say that instead of a short waveform, I were to use a 3 second file as my “waveform”. You’ll need to do some sort of anti-aliasing if you play a note high enough. If the sample rate is 44.1k, the file is roughly 132,000 samples long and FFT will not work. You could use oversampling, but to completely remove the aliasing it would require a lot of cpu power.

So how should this be done with FFT? Splitting the sample up causes me phase issues. Oversampling with HIIR would cause to much cpu. Any ideas?

Post

Total newbie here, so total naive solution. The signal is already bandlimited and you know how much frequency headroom you require, so you could just brickwall lowpass and then transpose.

Post

SNFK wrote: Thu Oct 07, 2021 5:18 pm So how should this be done with FFT? Splitting the sample up causes me phase issues. Oversampling with HIIR would cause to much cpu. Any ideas?
The FFT trick (ie. zero out high harmonics) works because the wavetables are periodic single-cycles, but that approach doesn't work for anything else. For non-periodic audio, you need to filter with an actual brickwall lowpass (eg. windowed sinc or whatever).

You can still precompute multiple versions similar to what is done with wavetables, you just need to use a proper filter... although the filtering itself can be done using FFT convolution if desired (eg. search the web for "overlap add" or something).

Oversampling on it's own doesn't do you any good, it just makes it easier to interpolate without introducing additional aliasing once your source is already band-limited.

Post

For non-periodic audio, you need to filter with an actual brickwall lowpass (eg. windowed sinc or whatever).
What would you recommend? I saw somewhere on this forum a while ago that Chebyshev 2 filter would work well, but others also said a sinc FIR filter would work well too. It wouldn’t need to be a perfect brickwall low pass because then I could oversample the little artifacts off…?

Post

The point is that for oversampling you are going to zero stuff, interpolate (brickwall lowpass) and then lowpass (another brickwall) and then drop samples. So you have two brickwalls involved and if the filters are polyphase both brickwalls will work at the base rate.

To me it seems that the advantages of this vs a single brickwall before transposing are:

-There is no coefficient recalculation, should you use FIR.
-The cutoff will be set higher around FS/2. On the single lowpass version the higher octaves would require filters with a lower cutoff: long kernels for a FIR filter.

But it still may happen that the single filter variable cutoff version ends up doing less work. Especially if the filter is not a FIR.

Post

SNFK wrote: Fri Oct 08, 2021 2:20 pm
For non-periodic audio, you need to filter with an actual brickwall lowpass (eg. windowed sinc or whatever).
What would you recommend? I saw somewhere on this forum a while ago that Chebyshev 2 filter would work well, but others also said a sinc FIR filter would work well too. It wouldn’t need to be a perfect brickwall low pass because then I could oversample the little artifacts off…?
IIR filter like Chebychev's are going to cause some additional trouble here and can't be computed with FFT fast convolution, so I'd just go with windowed sinc (eg. Kaiser let's you tweak it easily).

Post

SNFK wrote: Fri Oct 08, 2021 2:20 pm What would you recommend? I saw somewhere on this forum a while ago that Chebyshev 2 filter would work well, but others also said a sinc FIR filter would work well too.
if you really want to create mip-maps of your samples before playback, then i would probably indeed go with a bidirectional (forward/backward) chebychev-2 or elliptic filter. that said, i'm not so sure that i would go down the mip-mapping route at all and would probably just use windowed-sinc interpolation at realtime, with the sinc stretched out in time when transposing upwards. i should mention that i did not yet implement this - it is just what i would try first. i'll soon have to implement some of this stuff anyway for a project i'm currently working on....so we'll see...

edit: oh - i just recall that i actually did implement windowed-sinc resampling - just not in the context of a sampler but rather for non-realtime sample-editing purposes. my experience there was: with a kernel-length of 64, you get a quite good quality. of course, the aliasing suppression will depend on your transposition factor - higher upward transpositions call for longer kernels
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Music Engineer wrote: Sat Oct 09, 2021 5:05 am
SNFK wrote: Fri Oct 08, 2021 2:20 pm What would you recommend? I saw somewhere on this forum a while ago that Chebyshev 2 filter would work well, but others also said a sinc FIR filter would work well too.
if you really want to create mip-maps of your samples before playback, then i would probably indeed go with a bidirectional (forward/backward) chebychev-2 or elliptic filter.
What is the supposed advantage over a windowed sinc or some such FIR design that you can quickly process with FFT convolution? When you do bidirectional filtering like that it isn't even Chebychev-optimal anymore.. so like.. why?

Post

mystran wrote: Sat Oct 09, 2021 7:18 am What is the supposed advantage over a windowed sinc or some such FIR design that you can quickly process with FFT convolution? When you do bidirectional filtering like that it isn't even Chebychev-optimal anymore.. so like.. why?
in this context, i like the flatness and monotonicity of the chebychev-2 response in the passband, which i would deem a desirable feature in this application. with windowed-sinc, i would expect some amount of passband ripple. yes, ok, it may perhaps be minimized via numeric optimization of the window - but that's costly and i like my filters to be easily tweakable*. i also generally tend to prefer IIR over FIR filters due to their higher bang-for-the-buck ratio. all that said, FIR should be fine, too :shrug:

(*) i also mentioned elliptic as an option because with an elliptic filter, you may "dial-in" some passband ripple in a controlled way to steepen the transition (chebychev-2 is the limiting case of an elliptic filter when the passband ripple goes to zero - just for the record, mystran knows this, of course).
Last edited by Music Engineer on Sat Oct 09, 2021 12:43 pm, edited 1 time in total.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Music Engineer wrote: Sat Oct 09, 2021 8:00 am
mystran wrote: Sat Oct 09, 2021 7:18 am What is the supposed advantage over a windowed sinc or some such FIR design that you can quickly process with FFT convolution? When you do bidirectional filtering like that it isn't even Chebychev-optimal anymore.. so like.. why?
in this context, i like the flatness and monotonicity of the chebychev-2 response in the passband, which i would deem a desirable feature in this application.
Here's the problem: your IIR is infinite by definition... and when you truncate it, you'll get passband ripple and this is not trivial, because with higher orders some of the poles have quite a high Q. For FIR the maximally flat pass-band condition leads to Lagrange interpolators, but those are kinda terrible for just about anything and I'm not sure if there's anything better that avoids passband ripple.

Now, don't get me wrong, I'm very much a fan of Cheb-2 in audio, it's just that I'm not convinced it's a good idea in this particular application. Note that Kaiser-windowed sinc is also very much "tweakable" (you get to adjust both the cutoff and the Kaiser-alpha), which is why I'm also a fan of Kaiser windows. As far as I'm concerned, by the time you tweak alpha high enough to get reasonable stop-band attenuation, the pass-band ripple is negligible.

Post

mystran wrote: Sat Oct 09, 2021 11:47 am Here's the problem: your IIR is infinite by definition... and when you truncate it, you'll get passband ripple
why do you assume truncation - or what sort of truncation? are you referring to the fact that when i reach the end of the forward pass, i would need to let the filter ring out infinitely long before reversing direction (and then processing this ring-out tail in reverse in the backward pass, to warm the filter up) ...and i have to truncate this ringout-phase at some point? or do you assume, i just turn around without giving the filter a ringout/warmup phase? what i conceptually do is to append enough zeros to the signal such that the filter has enough time to completely ring out after the forward pass, apply the backward pass, and then cut the resulting signal back to it's original length (that's not how it's implemented, but that's the idea). one could of course also keep the tail and also prepend a "forward tail" - the sample would get longer to both sides - but i usually cut it back to the original length. yes, i know - in theory, the filter never rings out completely - but from a practical point of view, when it's down to - say - 200 or 300 dB, you can safely call it done
which is why I'm also a fan of Kaiser windows. As far as I'm concerned, by the time you tweak alpha high enough to get reasonable stop-band attenuation, the pass-band ripple is negligible.
interesting - i did not yet have a close look at the kaiser window. maybe i should do. i happen to be a fan of the dolph-chebychev window ever since i learned about it. :-)
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Music Engineer wrote: Sat Oct 09, 2021 3:19 pm
mystran wrote: Sat Oct 09, 2021 11:47 am Here's the problem: your IIR is infinite by definition... and when you truncate it, you'll get passband ripple
what i conceptually do is to append enough zeros to the signal such that the filter has enough time to completely ring out after the forward pass, apply the backward pass, and then cut the resulting signal back to it's original length
IIR filter does not "completely ring out" which is why it's called "infinite impulse response" .. and when you cut the signal to it's original length, you're causing more issues (don't do this with a FIR either, unless you know there's a fade-in/out).

Sure, at some point the tail is floating point noise, but the point I was trying to make is that for a high-order Chebychev there's poles right next to the unit circle.

Post

mystran wrote: Sat Oct 09, 2021 3:36 pm Sure, at some point the tail is floating point noise, but the point I was trying to make is that for a high-order Chebychev there's poles right next to the unit circle.
i just ran a little numerical experiment: took the impulse response of a chebychev-2 lowpass of 10th order with cutoff at 1 kHz, sample-rate at 44.1 kHz, stopband rejection of 80 dB. converted the raw impulse response to dB and took a look. the impulse response decays down to around -200dB in around 1200 samples. that translates to around 27.21... ms. so, if you would just (conceptually) add a (pre- and post) zero-padding of 50 ms (let's be generous), it should actually be fine - or shouldn't it? fine in the sense of giving the filter enough time to ring out for practical purposes. granted, if the cutoff would be 100Hz instead of 1000, you would need ten times as much padding. still, half a second may be not totally unreasonable, if your actual audio data is several seconds long.
.. and when you cut the signal to it's original length, you're causing more issues (don't do this with a FIR either, unless you know there's a fade-in/out).
well, you could of course also just keep the filtered (pre- and post) padding. that would be the theoretically correct thing to do. but in larger algorithms, it may often be somewhat inconvenient when each filtering process makes your signal longer at both ends. depending on what you want to achieve, this may nevertheless be an option, though
Last edited by Music Engineer on Sun Oct 10, 2021 2:34 pm, edited 2 times in total.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

a mathematically more sophisticated approach would be to not just run the filter through the ringout/warmup phases but to derive equations for how it's state variables should be initialized before the backward pass (i think, we mentioned that in at least two other threads without ever really fleshing it out). i've actually worked out the math for first order filters. then tried second order and got stuck with unmanagably unwieldy expressions coming out of the CAS. here is what i've got so far (this is kind of work in progress and at the bottom of the document (under the last boxed equation) is just garbage). the boxed equations are what is needed for an implementation (i've implemented and tested them and - lo and behold - they actually work):

https://github.com/RobinSchmidt/RS-MET/ ... States.txt

the derivation was actually quite messy - much more so than i expected it to be. maybe my CAS skills are just not good enough and/or i took the wrong approach (if anyone knows a better one, please let me know). i guess, the best way to generalize to higher order filters would be to just split it into (complex) 1st order filters (partial fraction expansion) and then use the solution for the first order filter. one day, i will work this out. but today is not this day.

btw . i wonder, how matlab's filtfilt handles it. the doc says: "filtfilt minimizes start-up and ending transients by matching initial conditions."

https://www.mathworks.com/help/signal/ref/filtfilt.html

but i have no idea what that means. match them to what? to each other? why would that make any sense? maybe in case of a periodic signal - but periodicity can't really be the general assumption of such a routine or can it?
Last edited by Music Engineer on Sun Oct 10, 2021 3:32 pm, edited 1 time in total.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Music Engineer wrote: Sat Oct 09, 2021 8:00 am in this context, i like the flatness and monotonicity of the chebychev-2 response in the passband,
But, two pass Cheb2 is not as flat. We would need filter designed in such way that two such filters in series give maximally flat response, have no idea how simple/hard/doable that is.

Post Reply

Return to “DSP and Plugin Development”