[SciPy-User] soft limiter function

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] soft limiter function

Neal Becker
I'm looking for a parameterized set of functions, similar to logistic, where
a parameter determines the 'sharpness' of the transition from the linear
region to the flat region.  I need to keep all the same scaling and
derivative near the origin - so like a family of logistic functions that
would overlay near the origin, but would become increasingly sharp limiters
as the parameter was varied.  In the limit, would approach the ideal limiter

      x |x<1|
y = { 1 x > 1
     -1 x < -1

--
Those who fail to understand recursion are doomed to repeat it

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: soft limiter function

Matt Newville
Neal,


On Tue, Mar 10, 2015 at 9:10 AM, Neal Becker <[hidden email]> wrote:
I'm looking for a parameterized set of functions, similar to logistic, where
a parameter determines the 'sharpness' of the transition from the linear
region to the flat region.  I need to keep all the same scaling and
derivative near the origin - so like a family of logistic functions that
would overlay near the origin, but would become increasingly sharp limiters
as the parameter was varied.  In the limit, would approach the ideal limiter

      x |x<1|
y = { 1 x > 1
     -1 x < -1

This might be too simplistic, but have you considered the "classic" step-like functions (here, going from 0 to 1, but not necessarily at x=+/-1):

    arctan:     y(a) = 0.5 + arctan(a) / pi
    error fcn:  y(a) = 0.5 * (1 + erf(a))
    logistic:   y(a) = 1.0 - 1.0 /(1.0 + exp(a))

 where a = (x-x0)/sigma ?
     That gives you a knob (sigma) to control the sharpness of the step.

--Matt

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: soft limiter function

Neal Becker
Matt Newville wrote:

> Neal,
>
>
> On Tue, Mar 10, 2015 at 9:10 AM, Neal Becker <[hidden email]> wrote:
>
>> I'm looking for a parameterized set of functions, similar to logistic,
>> where
>> a parameter determines the 'sharpness' of the transition from the linear
>> region to the flat region.  I need to keep all the same scaling and
>> derivative near the origin - so like a family of logistic functions that
>> would overlay near the origin, but would become increasingly sharp
>> limiters
>> as the parameter was varied.  In the limit, would approach the ideal
>> limiter
>>
>>       x |x<1|
>> y = { 1 x > 1
>>      -1 x < -1
>>
>
> This might be too simplistic, but have you considered the "classic"
> step-like functions (here, going from 0 to 1, but not necessarily at
> x=+/-1):
>
>     arctan:     y(a) = 0.5 + arctan(a) / pi
>     error fcn:  y(a) = 0.5 * (1 + erf(a))
>     logistic:   y(a) = 1.0 - 1.0 /(1.0 + exp(a))
>
>  where a = (x-x0)/sigma ?     That gives you a knob (sigma) to control the
> sharpness of the step.
>
> --Matt

Thanks, but I also need the derivative near the origin to be 1 - cannot
change the steepness near the origin

--
Those who fail to understand recursion are doomed to repeat it

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: soft limiter function

Athanasios Anastasiou-4
Hello Neal

I was going to go with Matt's suggestion as well but then I started thinking "Why does he want the derivative to be 1 near the origin?" and so I concluded that you are probably trying to do something like audio compression or limiting. The rest of my response is governed by this assumption. If that's wrong, stop reading :D

The compressor's curve is the "sum" of two curves. The linear part is 1:1, while the limiting part, past the threshold point becomes 1:2, 1:4 and in general it changes slope depending on how hard you want the compressor to be.

So, at its very minimum, you can define a function that accepts two parameters (threshold and compression ratio) and from these it works out the slopes of two curves. In your case it is even easier, you know you want 1:1 up to the threshold, so all you have to do is have one parameter that determines the slope of the limiter. (example: http://en.wikipedia.org/wiki/Dynamic_range_compression#mediaviewer/File:Audio-level-compresion-diagram-01.svg).  That's the basic idea.

Having said this, such a "kink" will be audible as high frequency noise. So you want to make the transition as soft as possible. You can check the responses of popular diodes used for this, they are all based on some exp() function and the parameters for it are available in the datasheets.

The other thing you can be doing is follow the original idea of setting up two lines of different slopes and then interpolating them via a spline. By controlling the "strength" of the node of the spline you can be changing the transition to avoid that "kink".

Finally, you can map the curve of an existing compressor that you like, in the steady state, to see the kinds of curves it uses for different settings and then interpolate through that family of curves through a single parameter.

Hope this helps.

All the best
Athanasios Anastasiou

P.S. You can still add a low pass filter right after the comp curve to reduce the audible effect of the "kink" much more easily.








On Tue, Mar 10, 2015 at 3:30 PM, Neal Becker <[hidden email]> wrote:
Matt Newville wrote:

> Neal,
>
>
> On Tue, Mar 10, 2015 at 9:10 AM, Neal Becker <[hidden email]> wrote:
>
>> I'm looking for a parameterized set of functions, similar to logistic,
>> where
>> a parameter determines the 'sharpness' of the transition from the linear
>> region to the flat region.  I need to keep all the same scaling and
>> derivative near the origin - so like a family of logistic functions that
>> would overlay near the origin, but would become increasingly sharp
>> limiters
>> as the parameter was varied.  In the limit, would approach the ideal
>> limiter
>>
>>       x |x<1|
>> y = { 1 x > 1
>>      -1 x < -1
>>
>
> This might be too simplistic, but have you considered the "classic"
> step-like functions (here, going from 0 to 1, but not necessarily at
> x=+/-1):
>
>     arctan:     y(a) = 0.5 + arctan(a) / pi
>     error fcn:  y(a) = 0.5 * (1 + erf(a))
>     logistic:   y(a) = 1.0 - 1.0 /(1.0 + exp(a))
>
>  where a = (x-x0)/sigma ?     That gives you a knob (sigma) to control the
> sharpness of the step.
>
> --Matt

Thanks, but I also need the derivative near the origin to be 1 - cannot
change the steepness near the origin

--
Those who fail to understand recursion are doomed to repeat it

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user


_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: soft limiter function

Neal Becker
Athanasios Anastasiou wrote:

> Hello Neal
>
> I was going to go with Matt's suggestion as well but then I started
> thinking "Why does he want the derivative to be 1 near the origin?" and so
> I concluded that you are probably trying to do something like audio
> compression or limiting. The rest of my response is governed by this
> assumption. If that's wrong, stop reading :D
>
> The compressor's curve is the "sum" of two curves. The linear part is 1:1,
> while the limiting part, past the threshold point becomes 1:2, 1:4 and in
> general it changes slope depending on how hard you want the compressor to
> be.
>
> So, at its very minimum, you can define a function that accepts two
> parameters (threshold and compression ratio) and from these it works out
> the slopes of two curves. In your case it is even easier, you know you
> want 1:1 up to the threshold, so all you have to do is have one parameter
> that determines the slope of the limiter. (example:
>
http://en.wikipedia.org/wiki/Dynamic_range_compression#mediaviewer/File:Audio-level-compresion-diagram-01.svg).

> That's the basic idea.
>
> Having said this, such a "kink" will be audible as high frequency noise.
> So you want to make the transition as soft as possible. You can check the
> responses of popular diodes used for this, they are all based on some
> exp() function and the parameters for it are available in the datasheets.
>
> The other thing you can be doing is follow the original idea of setting up
> two lines of different slopes and then interpolating them via a spline. By
> controlling the "strength" of the node of the spline you can be changing
> the transition to avoid that "kink".
>
> Finally, you can map the curve of an existing compressor that you like, in
> the steady state, to see the kinds of curves it uses for different
> settings and then interpolate through that family of curves through a
> single parameter.
>
> Hope this helps.
>
> All the best
> Athanasios Anastasiou
>
> P.S. You can still add a low pass filter right after the comp curve to
> reduce the audible effect of the "kink" much more easily.
>
>
>
>
>
>
>
>
> On Tue, Mar 10, 2015 at 3:30 PM, Neal Becker <[hidden email]> wrote:
>
>> Matt Newville wrote:
>>
>> > Neal,
>> >
>> >
>> > On Tue, Mar 10, 2015 at 9:10 AM, Neal Becker <[hidden email]>
>> wrote:
>> >
>> >> I'm looking for a parameterized set of functions, similar to logistic,
>> >> where
>> >> a parameter determines the 'sharpness' of the transition from the
>> >> linear
>> >> region to the flat region.  I need to keep all the same scaling and
>> >> derivative near the origin - so like a family of logistic functions
>> >> that would overlay near the origin, but would become increasingly
>> >> sharp limiters
>> >> as the parameter was varied.  In the limit, would approach the ideal
>> >> limiter
>> >>
>> >>       x |x<1|
>> >> y = { 1 x > 1
>> >>      -1 x < -1
>> >>
>> >
>> > This might be too simplistic, but have you considered the "classic"
>> > step-like functions (here, going from 0 to 1, but not necessarily at
>> > x=+/-1):
>> >
>> >     arctan:     y(a) = 0.5 + arctan(a) / pi
>> >     error fcn:  y(a) = 0.5 * (1 + erf(a))
>> >     logistic:   y(a) = 1.0 - 1.0 /(1.0 + exp(a))
>> >
>> >  where a = (x-x0)/sigma ?     That gives you a knob (sigma) to control
>> the
>> > sharpness of the step.
>> >
>> > --Matt
>>
>> Thanks, but I also need the derivative near the origin to be 1 - cannot
>> change the steepness near the origin
>>

The rapp amplifier model looks like it will do what I need (I'm modeling
amplifiers, nothing to do with audio)

http://www.ieee802.org/16/tg1/phy/pres/802161pp-00_15.pdf


_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: soft limiter function

Matthieu Brucher-2
In reply to this post by Neal Becker
You can still modify the functions to have such derivative at the
origin (this is often used to model amps in audio processing). Just
use a scaling factor.

Cheers,

2015-03-10 15:30 GMT+00:00 Neal Becker <[hidden email]>:

> Matt Newville wrote:
>
>> Neal,
>>
>>
>> On Tue, Mar 10, 2015 at 9:10 AM, Neal Becker <[hidden email]> wrote:
>>
>>> I'm looking for a parameterized set of functions, similar to logistic,
>>> where
>>> a parameter determines the 'sharpness' of the transition from the linear
>>> region to the flat region.  I need to keep all the same scaling and
>>> derivative near the origin - so like a family of logistic functions that
>>> would overlay near the origin, but would become increasingly sharp
>>> limiters
>>> as the parameter was varied.  In the limit, would approach the ideal
>>> limiter
>>>
>>>       x |x<1|
>>> y = { 1 x > 1
>>>      -1 x < -1
>>>
>>
>> This might be too simplistic, but have you considered the "classic"
>> step-like functions (here, going from 0 to 1, but not necessarily at
>> x=+/-1):
>>
>>     arctan:     y(a) = 0.5 + arctan(a) / pi
>>     error fcn:  y(a) = 0.5 * (1 + erf(a))
>>     logistic:   y(a) = 1.0 - 1.0 /(1.0 + exp(a))
>>
>>  where a = (x-x0)/sigma ?     That gives you a knob (sigma) to control the
>> sharpness of the step.
>>
>> --Matt
>
> Thanks, but I also need the derivative near the origin to be 1 - cannot
> change the steepness near the origin
>
> --
> Those who fail to understand recursion are doomed to repeat it
>
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/scipy-user



--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
Music band: http://liliejay.com/
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: soft limiter function

Athanasios Anastasiou-4

" I'm modeling
amplifiers, nothing to do with audio"

This is so "wrong" in so many levels!!! :D

I am just joking about the "wrong" but the clipping characteristics of instrument amplifiers, their "sound signature", is exactly why one would like to produce such a model. See here for example: http://en.m.wikipedia.org/wiki/Amplifier_modeling

Anyway, all the best for your project.
Athanasios Anastasiou

On 10 Mar 2015 17:21, "Matthieu Brucher" <[hidden email]> wrote:
You can still modify the functions to have such derivative at the
origin (this is often used to model amps in audio processing). Just
use a scaling factor.

Cheers,

2015-03-10 15:30 GMT+00:00 Neal Becker <[hidden email]>:
> Matt Newville wrote:
>
>> Neal,
>>
>>
>> On Tue, Mar 10, 2015 at 9:10 AM, Neal Becker <[hidden email]> wrote:
>>
>>> I'm looking for a parameterized set of functions, similar to logistic,
>>> where
>>> a parameter determines the 'sharpness' of the transition from the linear
>>> region to the flat region.  I need to keep all the same scaling and
>>> derivative near the origin - so like a family of logistic functions that
>>> would overlay near the origin, but would become increasingly sharp
>>> limiters
>>> as the parameter was varied.  In the limit, would approach the ideal
>>> limiter
>>>
>>>       x |x<1|
>>> y = { 1 x > 1
>>>      -1 x < -1
>>>
>>
>> This might be too simplistic, but have you considered the "classic"
>> step-like functions (here, going from 0 to 1, but not necessarily at
>> x=+/-1):
>>
>>     arctan:     y(a) = 0.5 + arctan(a) / pi
>>     error fcn:  y(a) = 0.5 * (1 + erf(a))
>>     logistic:   y(a) = 1.0 - 1.0 /(1.0 + exp(a))
>>
>>  where a = (x-x0)/sigma ?     That gives you a knob (sigma) to control the
>> sharpness of the step.
>>
>> --Matt
>
> Thanks, but I also need the derivative near the origin to be 1 - cannot
> change the steepness near the origin
>
> --
> Those who fail to understand recursion are doomed to repeat it
>
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/scipy-user



--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
Music band: http://liliejay.com/
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user