Waveshaper with polynomials
- KVRer
- Topic Starter
- 3 posts since 29 May, 2018 from Kyiv
Hi, KVR community
I'm wondering if someone could help me with developing saturation function. I'm looking for wave shapes as in the attachment (simple sine wave in the input). I know that it's can be done with Chebyshev polynomials but I'm bit confused that this waves are not symmetrical as sine wave - peaks and zero are shifted. I'm not shure about simple polynomials with powers. So I'm looking for advice what functions can be my starting point to play with
Thanks
I'm wondering if someone could help me with developing saturation function. I'm looking for wave shapes as in the attachment (simple sine wave in the input). I know that it's can be done with Chebyshev polynomials but I'm bit confused that this waves are not symmetrical as sine wave - peaks and zero are shifted. I'm not shure about simple polynomials with powers. So I'm looking for advice what functions can be my starting point to play with
Thanks
You do not have the required permissions to view the files attached to this post.
-
Music Engineer Music Engineer https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=15959
- KVRAF
- 4289 posts since 8 Mar, 2004 from Berlin, Germany
in order to get these exact waveshapes from a sinewave input, i'd probably try to first apply an arc-sine to turn the sine back into a phase/position variable (should be a sawtooth shape) and then use that as index to a table that contains the exact waveshape that you want. ...just as a first idea.
...but - it's actually a bit more complicated, since the arc-sine is ambiguous. there are multiple angles (to be exact, 2, within one cycle) that would have the same sine and the arc-sin function can't know which one you want (and just give you the first) - but if you look at two successive samples instead of just one (i.e. x[n] and x[n-1]), you could figure out, whether you are in first quarter (ascending values -> x[n] > x[n-1]) or second quarter (x[n] < x[n-1]) and add pi/2 to asin's output in the 2nd case - and similar for the 2nd half-wave
...but - it's actually a bit more complicated, since the arc-sine is ambiguous. there are multiple angles (to be exact, 2, within one cycle) that would have the same sine and the arc-sin function can't know which one you want (and just give you the first) - but if you look at two successive samples instead of just one (i.e. x[n] and x[n-1]), you could figure out, whether you are in first quarter (ascending values -> x[n] > x[n-1]) or second quarter (x[n] < x[n-1]) and add pi/2 to asin's output in the 2nd case - and similar for the 2nd half-wave
Last edited by Music Engineer on Wed May 30, 2018 8:09 pm, edited 1 time in total.
-
Music Engineer Music Engineer https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=15959
- KVRAF
- 4289 posts since 8 Mar, 2004 from Berlin, Germany
hmmm...thinking more closely, such a strategy could fail very close to the minima and maxima - if the actual min/max occurs between two samples. ...maybe x[n-2] should also be taken into consideration
- KVRer
- Topic Starter
- 3 posts since 29 May, 2018 from Kyiv
AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Thank you for your response. I thought about it too and decided that I want to find flexible functions instead of presaved wave tables. I believed that there are some tricky things instead of chebyshev and hyperbolic tangent.Music Engineer wrote:in order to get these exact waveshapes from a sinewave input, i'd probably try to first apply an arc-sine to turn the sine back into a phase/position variable (should be a sawtooth shape) and then use that as index to a table that contains the exact waveshape that you want. ...just as a first idea.
Arcsin function to get sawtooth is looks promising, but as you mentioned it fails in the local extremums so i can even get some crackles in the output. I still playing with it and looking for more advices.
My current approach is https://www.desmos.com/calculator/w2ay1jeuci (https://www.desmos.com/calculator/w2ay1jeuci).
It's mix of Chebyshev and tanh functions (a is drive from 0 to 1, gain = 6):
Code: Select all (#)
y(i) = (x - a / 8 * (2*x^2 - 1));
y(i) = y(i) - (a / 2) * (4 * x^3 - 3*x);
y(i) = y(i) - (a / 8) * (8 * x^4 - 8 * x^2 + 1);
y(i) = y(i) * (1 - a) + (a / gain) * tanh (gain * y(i));
Also if take into account harmonic analysis of the output, with my approach i have lack of the highest harmonics in the spectrum.
-
- KVRian
- 1153 posts since 11 Aug, 2004 from Breuillet, France
These curves in the first post suggest that you are not looking for a static waveshaper, but for a combination of waveshaping and filtering instead. There is no static function / waveshaper which could give a curve with f(x) = a on rising and f(x) = b on falling, with x being a sine wave... Or maybe you have some hysteresis happening there as well ?
- KVRer
- Topic Starter
- 3 posts since 29 May, 2018 from Kyiv
Thanks a lot! This brings me directly to the point. can't believe I didn't think about it. Now I'm playing with [tanh -> eq] and get much better results and closer to what i'm looking for. Thanks againIvan_C wrote:These curves in the first post suggest that you are not looking for a static waveshaper, but for a combination of waveshaping and filtering instead. There is no static function / waveshaper which could give a curve with f(x) = a on rising and f(x) = b on falling, with x being a sine wave... Or maybe you have some hysteresis happening there as well ?
- KVRAF
- 7890 posts since 12 Feb, 2006 from Helsinki, Finland
Well, you probably could turn an analytic sinusoids (ie. take the input sine and put it through a Hilbert transform) to pretty much anything with a complex polynomial of sufficient order (which can produce asymmetry just fine now, since you get to control harmonic phases too), but yeah.. most likely the original pictures are the result of some combination of saturation (and maybe other waveshaping) and filtering, which might or might not be coupled in some way.Ivan_C wrote:There is no static function / waveshaper which could give a curve with f(x) = a on rising and f(x) = b on falling, with x being a sine wave... Or maybe you have some hysteresis happening there as well ?