If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Gain compensation for asymmetrical waveshaping
8 posts
• Page 1 of 1
Gain compensation for asymmetrical waveshaping
I'm working on something where I'd like to compensate for the output level dropping when a parameter is turned up.
I've measured the curve to look about like this (using a sine wave input and peak detection on the output), where the x-axis is the parameter value and the y-axis is the output level.
I know you can invert a function like this with 1 - x but I don't know what the function actually is mathematically speaking.
Might anyone be able to help me figure it out? I'm looking for a close approximation.
Edit: If it helps, what I'm doing exactly is pushing a sine wave into a tanh transfer function with a DC offset. As the offset increases the sine gets squished. Then the offset is removed, and the resulting output level is reduced.
I've measured the curve to look about like this (using a sine wave input and peak detection on the output), where the x-axis is the parameter value and the y-axis is the output level.
I know you can invert a function like this with 1 - x but I don't know what the function actually is mathematically speaking.
Might anyone be able to help me figure it out? I'm looking for a close approximation.
Edit: If it helps, what I'm doing exactly is pushing a sine wave into a tanh transfer function with a DC offset. As the offset increases the sine gets squished. Then the offset is removed, and the resulting output level is reduced.
Last edited by Perfect Human Interface on Tue Mar 15, 2016 10:37 pm, edited 1 time in total.
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: Inverting an unknown function
if you post the formula you have, one can easily get the inverted function
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: Inverting an unknown function
Hm, let me see, you are doing this:
output = tanh(input + DC)
correct? Then Taylor expansion to first order gives
output = tanh(DC) + input/cosh^2(DC)
so the output has some offset tanh(DC) and there is a gain reduction by the factor cosh^2(DC). So you want to remove the offset (I'd use a DC blocker filter for that) and multiply by the factor cosh^2(DC) to make up for the gain loss.
Something like this:
The resulting level is somewhat higher than the input level. This is because we are using only a first order Taylor expansion.
output = tanh(input + DC)
correct? Then Taylor expansion to first order gives
output = tanh(DC) + input/cosh^2(DC)
so the output has some offset tanh(DC) and there is a gain reduction by the factor cosh^2(DC). So you want to remove the offset (I'd use a DC blocker filter for that) and multiply by the factor cosh^2(DC) to make up for the gain loss.
Something like this:
The resulting level is somewhat higher than the input level. This is because we are using only a first order Taylor expansion.
- Attachments
-
- RestoreLevel.fsm
- (13.39 KiB) Downloaded 926 times
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: Inverting an unknown function
Wow, couldn't have asked for a more straightforward answer. Thanks Martin!
Is there more that can be done about that? I understand that the asymmetry will create higher peaks inherently but if I could get it closer to matching perceived volume that would be cool.
martinvicanek wrote:The resulting level is somewhat higher than the input level. This is because we are using only a first order Taylor expansion.
Is there more that can be done about that? I understand that the asymmetry will create higher peaks inherently but if I could get it closer to matching perceived volume that would be cool.
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: Inverting an unknown function
That's possible if you know the input signal amplitude. For instance if A denotes the input RMS, then third order Taylor expansion yields the following expressions for the output DC offset and the gain, respectively:Perfect Human Interface wrote:[...]get it closer to matching perceived volume[...]
offset = tanh(DC)*[1 - A^2/cosh^2(DC)]
gain = [1 + A^2*(tanh^2(DC) - 1/3)]/cosh^2(DC)
Note that if you set A = 0 you recover the results of my first post above, so the terms with A are the correction to that.
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: Inverting an unknown function
Thank you for this. I'm glad there are people out there who've studied math.
It seems to me that with varying input and other parameters in play this is never going to be exact. Though with the fix you recommended earlier Martin the project is already functioning much better.
I was also considering adding some different waveshaping functions besides tanh, possibly even user-custom ones, which I'm afraid may just complicate this beyond hope.
If I can throw this out there, does anyone know if there's a "better" way to apply asymmetry to waveshaping? I know that there are custom waveshapers out there like this where you can edit the positive and negative independently, which is powerful, but I just wanted to use a knob.
It seems to me that with varying input and other parameters in play this is never going to be exact. Though with the fix you recommended earlier Martin the project is already functioning much better.
I was also considering adding some different waveshaping functions besides tanh, possibly even user-custom ones, which I'm afraid may just complicate this beyond hope.
If I can throw this out there, does anyone know if there's a "better" way to apply asymmetry to waveshaping? I know that there are custom waveshapers out there like this where you can edit the positive and negative independently, which is powerful, but I just wanted to use a knob.
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: Inverting an unknown function
Perfect Human Interface wrote:If I can throw this out there, does anyone know if there's a "better" way to apply asymmetry to waveshaping?
I don't know about "better" necessarily (depends what you're going for), but here's some links that both have parts that talk about asymmetrical distortion/waveshaping:
https://ccrma.stanford.edu/~dtyeh/papers/DavidYehThesissinglesided.pdf
http://www.music.mcgill.ca/~ich/classes/dafx_book.pdf
- noisenerd
- Posts: 69
- Joined: Sun Feb 14, 2016 11:31 pm
Re: Inverting an unknown function
Thank you for that. Massive amounts of stuff there. The second link provides an example code for simulating (asymmetrical) tube distortion so that's cool. I am thinking I will want to use different waveshape functions though and keep the asymmetry control.
Is it possible to translate the function vertically instead of using DC offset on the audio?
I might try something else like logarithmically scaling positive and negative waveshape functions separately.
Is it possible to translate the function vertically instead of using DC offset on the audio?
I might try something else like logarithmically scaling positive and negative waveshape functions separately.
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 53 guests