Polynomial shapers and oversampling insanity
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
I have wondered for the last several years why does everybody insist that in order to use a polynomial wave-shaper you need to oversample equal to the order of the polynomial, when simple math says that with K times oversampling, you can calculate polynomial of order 2K-1 without the aliasing extending below the original Nyquist. In the limit when K tends to infinity, this translates to half the oversampling, which seems like a good deal to me.
What I mean is, let's assume original Nyquist is at N. We'll resample to twice the samplerate, which gives us a new Nyquist at 2N. Suppose we have a sine at frequency N-e where e is some small positive constant, and we want to calculate x^3:
sin(2*Pi*t*(N-e)) * sin(2*Pi*t*(N-e))
= 1/2 + sin(4*Pi*t*(N-e))/2
Right? So far we are above the oversampled Nyquist of 2N. However, it turns out that:
(1/2 + sin(4*Pi*t*(N-e))/2) * sin(2*Pi*t*(N-e))
= sin(2*Pi*(N-e))/2 + cos(2*Pi*t*(N-e))/4 + cos(6*Pi*t*(N-e))/4
Now the last term at 3*(N-e) will alias, but it'll land at:
4*N - 3*(N-e) = N+3*e
And that's still above N, so it'll still get filtered out when downsampling (with a brickwall) no matter how small is our constant e. You can work the generalized proof (for arbitrary oversampling K and polynomial terms up to 2*K-1) as an exercise if you want (it's not hard but I'm not in the mood for formalizing).
Another way to look at discrete-time time-domain multiplication as convolution around the unit-circle on z-plane, which gives you the same result (of course, but the point is I find it much easier to mentally visualize this way): you'll get aliasing, but it won't extend below the original Nyquist as long as all your polynomial terms are of order 2*K-1 or less for an oversampling factor of K.
What I mean is, let's assume original Nyquist is at N. We'll resample to twice the samplerate, which gives us a new Nyquist at 2N. Suppose we have a sine at frequency N-e where e is some small positive constant, and we want to calculate x^3:
sin(2*Pi*t*(N-e)) * sin(2*Pi*t*(N-e))
= 1/2 + sin(4*Pi*t*(N-e))/2
Right? So far we are above the oversampled Nyquist of 2N. However, it turns out that:
(1/2 + sin(4*Pi*t*(N-e))/2) * sin(2*Pi*t*(N-e))
= sin(2*Pi*(N-e))/2 + cos(2*Pi*t*(N-e))/4 + cos(6*Pi*t*(N-e))/4
Now the last term at 3*(N-e) will alias, but it'll land at:
4*N - 3*(N-e) = N+3*e
And that's still above N, so it'll still get filtered out when downsampling (with a brickwall) no matter how small is our constant e. You can work the generalized proof (for arbitrary oversampling K and polynomial terms up to 2*K-1) as an exercise if you want (it's not hard but I'm not in the mood for formalizing).
Another way to look at discrete-time time-domain multiplication as convolution around the unit-circle on z-plane, which gives you the same result (of course, but the point is I find it much easier to mentally visualize this way): you'll get aliasing, but it won't extend below the original Nyquist as long as all your polynomial terms are of order 2*K-1 or less for an oversampling factor of K.
- KVRAF
- 4030 posts since 7 Sep, 2002
This is knowledge I've been using for quite a lot of time. So, textbooks may stop you from using best practices.mystran wrote:I have wondered for the last several years why does everybody insist that in order to use a polynomial wave-shaper you need to oversample equal to the order of the polynomial, when simple math says that with K times oversampling, you can calculate polynomial of order 2K-1 without the aliasing extending below the original Nyquist. In the limit when K tends to infinity, this translates to half the oversampling, which seems like a good deal to me.
-
Music Engineer Music Engineer https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=15959
- KVRAF
- 4379 posts since 8 Mar, 2004 from Berlin, Germany
cool. i never thought about that. much thanks.
-
- KVRian
- 1153 posts since 10 Dec, 2003
Interesting post. I'd read the oversampling per polynomial power in a few places but never really understood the proof of it till i read that. I thought it was just a general estimate of what the bandwidth would be.
You still need to limit / hard clip the signal before putting them through a polynomial waveshaper dont you? I mean after a point the higher power terms in the polynomial will dominate and you'll be at extremes of the y axis, and rising ever faster?
So for a practical waveshapper, you have to hard clip, and then waveshape that clipped range with the polynomial?
And antialiased hard clipping is still a process which requires a lot of cpu i think.
You still need to limit / hard clip the signal before putting them through a polynomial waveshaper dont you? I mean after a point the higher power terms in the polynomial will dominate and you'll be at extremes of the y axis, and rising ever faster?
So for a practical waveshapper, you have to hard clip, and then waveshape that clipped range with the polynomial?
And antialiased hard clipping is still a process which requires a lot of cpu i think.
- KVRAF
- Topic Starter
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
For general case yes, but especially in synths (or if you have a limiter before your waveshaper) you might know the maximum signal levels involves in which case you can design the polynomial to handle that.nollock wrote: You still need to limit / hard clip the signal before putting them through a polynomial waveshaper dont you? I mean after a point the higher power terms in the polynomial will dominate and you'll be at extremes of the y axis, and rising ever faster?
As far as I know, anti-aliased hard clipping isn't exactly a solved problem? I guess it should be possible to use either some BLEP-like trick or some frequency domain solution, but so far I have to report that I haven't been able to figure out the details.And antialiased hard clipping is still a process which requires a lot of cpu i think.
- KVRAF
- 4030 posts since 7 Sep, 2002
Please read my post here:mystran wrote:As far as I know, anti-aliased hard clipping isn't exactly a solved problem? I guess it should be possible to use either some BLEP-like trick or some frequency domain solution, but so far I have to report that I haven't been able to figure out the details.
http://www.kvraudio.com/forum/viewtopic.php?t=208318
Since symmetrical hard-clipping requires x^3, x^5, x^7 etc terms only. You can implement it pretty easily (on each step multiply by pre-calculated x^2 instead of x). The only problem with polynomials exist is that you can't put a large value range into it. Basically, it is 1 point per 1 polynomial term. So, you can easily cover sample range -2 to 2, but going wider will require a higher power polynomial. So, it's all about CPU demand - but algorithm is there.
