# Anti-Aliasing files for sampler playback

DSP, Plug-in and Host development discussion.
KVRAF
3977 posts since 8 Mar, 2004 from Berlin, Germany
urosh wrote:
Sun Oct 10, 2021 3:10 am
Music Engineer wrote:
Sat Oct 09, 2021 12: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.
is the cheby2 filter actually maximally flat anyway? i mean, yes - it is flat, but as far as i know, maximum flatness was not a design criterion in this case. the design criterion was actually to be equiripple in the stopband - that the magnitude is flat in the passband seems to be a byproduct in this case.

but be that as it may - it may indeed be interesting to look at that question for a butterworth-like design. if M(w) denotes the magnitude response, the butterworth design requires that as many derivatives as possible should vanish at w=0. ...now we would apply the same requirement to M^2(w) instead. using the product rule, we would get M^2'(w) = M' * M + M * M' = 2*M*M' ...and now we need to require that to vanish at w=0....next: M^2'' = ...blablabla ...must vanish, too...etc. hmmm...am i on the right track? might indeed be useful to work that out.

or wait - no - in the case of the butterworth design, it is actually already required that the derivatives of M^2 should vanish. that seems to translate to the condition that M itself is also maximally flat. so maybe the same then also holds for (M^2)^2 = M^4? i don't know, but it seems plausible at first glance. squaring or taking the square-root doesn't seem to destroy the condition. but could also be a brainfart. i did not really think this through yet. edit: but then - no - linkwitz-riley is actually already well known as butterworth-squared filter and it is not maximally flat (because then it would be butterworth). ...maybe we need to design some sort of butterworth-sqrt filter. in the sense of: when the magnitude-squared response is squared, the result should be maximally flat

i'm not sure, if this is even possible. the polynomial in the denominator of the magnitude-squared funtion of an n-th order butterworth filters is: B_n(x) = 1 + x^(2*n). now we would look for a polynomial A_n(x) such that (A_n(x))^2 = B_n(x). but that would mean that B_n(x) must be factored into A_n(x)*A_n(x) which would require B_n(x) to have roots of even multiplicity. but for our given butterworth polynomial B_n(x), all roots are simple - so it can't be factored this way...take all with a grain of salt....these are just some quick ideas

KVRAF
6576 posts since 12 Feb, 2006 from Helsinki, Finland
Music Engineer wrote:
Sun Oct 10, 2021 1:07 am
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 actually do this for the IIR blur in my toolkit: it assumes the image is zero outside the blur region, but on backward pass initializes the state to what it would be had it filtered backwards the tail that extends past the bound (without computing any points outside the actual blur region). In that case it's fairly simple to do as the actual filter is just a pair of Euler one-poles (ie. second order, real poles, no zeroes), but in principle I think it should be doable for pretty much any filter. There's some comments on the topic in the source although there might be an "off-by-one sample" error in the computation (should really redo the math, but it's not exactly the most pressing issue since you probably won't notice a visual problem anyway).
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRAF
3977 posts since 8 Mar, 2004 from Berlin, Germany
mystran wrote:
Sun Oct 10, 2021 8:24 pm
I actually do this for the IIR blur in my toolkit: it assumes the image is zero outside the blur region, but on backward pass initializes the state to what it would be had it filtered backwards the tail that extends past the bound (without computing any points outside the actual blur region). In that case it's fairly simple to do as the actual filter is just a pair of Euler one-poles (ie. second order, real poles, no zeroes), but in principle I think it should be doable for pretty much any filter. There's some comments on the topic in the source
hmmm....i don't really understand the computations you are doing there. however, in the case of image processing, wouldn't it be better to assume that the final pixel value is repeated over and over instead of assuming that the signal goes down to zero? i did not yet experiment with that stuff very much but i think i would expect some sort of "dark-frame" artifact at the boundary from the assumption that the pixels are black outside the image (region). this is my implementation:

https://github.com/RobinSchmidt/RS-MET/ ... leFilter.h

rsFirstOrderFilterBase::applyForwardBackward is a high-level function doing the whole bidirectional filtering process. among other things, it calls prepareForBackwardPass which implements the state initialization formulas that i have derived in my messy textfile (either with assumption of zero or some other constant for the values outside the actual data range)

KVRAF
6576 posts since 12 Feb, 2006 from Helsinki, Finland
Music Engineer wrote:
Mon Oct 11, 2021 5:27 am
hmmm....i don't really understand the computations you are doing there. however, in the case of image processing, wouldn't it be better to assume that the final pixel value is repeated over and over instead of assuming that the signal goes down to zero?
There is no "better" here, it's a different boundary condition -> different result. Mirroring or repeat are also reasonable choices depending on what the image represents, but I was lazy and just implemented the one I want most often. I should probably clarify that "zero" in premultiplied alpha (which is what you always want when you're filtering stuff with transparency) doesn't mean "black" but rather just "fully transparent" ... which is not an entirely unreasonable boundary condition to choose.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRer

Topic Starter

27 posts since 8 Nov, 2020
Not totally related, but how about properly bandlimiting a waveform? From what I’ve been working with, not windowing the waveform prior to FFT causes there to be some harmonics that leak though (due to the phase messing up). However, windowing the waveform messes up the final waveform. How should this be done?

Edit: I’m not at my computer right now, but from GitHub the issue looks like a indexing bug instead of the FFT.

KVRAF
6576 posts since 12 Feb, 2006 from Helsinki, Finland
SNFK wrote:
Sun Oct 17, 2021 2:47 pm
Not totally related, but how about properly bandlimiting a waveform? From what I’ve been working with, not windowing the waveform prior to FFT causes there to be some harmonics that leak though (due to the phase messing up). However, windowing the waveform messes up the final waveform. How should this be done?
If by "waveform" you mean a single-cycle of a periodic signal where the period "happens" to match the FFT size, then literally the correct thing to do is to just zero out the high frequencies (without windowing).

If by "waveform" you mean something else, please be specific.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.