Output of the curve function for smoothly limiting parameters, signals and not only in Wolfram Mathematica

There are a number of problems in which the range of output values should be limited, while the input data can not guarantee this. In addition to forced situations, limiting the signal can also be a goal-oriented task - for example, when compressing a signal or implementing the "overdrive" effect.

The simplest implementation of a constraint is to force a certain value when a certain level is exceeded. For example, for a sinusoid with an increasing amplitude, it will look like this:

In the role of the limiter, the function Clip acts here, as the argument of which the input signal and the constraint parameters are transmitted, and the result of the function is the output signal.

Let's look at the graph of the Clip function separately:

It looks like on binomial coefficients. We make a bold assumption that they are, and proceeding from this, we will write down the generalized formula:

Let's check:

It looks like the truth ^{ [1] } . It remains only to calculate the scale factor to bring the edges to unity:

And after scaling and simplifying, we find that our knowledge of mathematics is somewhat outdated ^{ [2] } :

Thus, we have obtained a generating function of order n, in which n-1 first derivatives will be zero:

Let's see what happened:

And since our generalized formula has turned out to be continuous, if desired, you can also use non-integral values of the parameters:

It is also possible to plot the graphs of the derivatives reduced to one scale:

## Add stiffnesses

It would be tempting to be able to regulate and the degree of "rigidity" of the restriction.

Let's return to our inverted parabola and add a coefficient for degree x:

The larger n, the more our derivative is "square", and its antiderivative - accordingly, sharp:

We calculate the antiderivative and correct the scale:

Let's try now to specify a fractional step for the parameter:

As we see, in the negative part, not all n have a correct solution, but in the right (positive) part the necessary conditions are still observed - so for negative values, we can simply use it in an inverted form with a reversed argument. And since the domain of definition of the parameter is no longer limited only to positive integers, we can simplify the formula by replacing 2n by n:

And replacing n by n-? you can make the formula a little more beautiful:

Since for n equal to one we obtain division by zero, then we will try to find the limit:

The limit is, so, now you can define

^{ [3] }function for n equal to 1 and consider it for all n large zero:

If we initially build our inverted parabola into a square, we get an even smoother function:

And we can compare them on one chart:

## Rationalize this

Let's look at the following function:

It appeared not accidentally.

If you remove the unit from it, x

^{ 2 }will be reduced and there will be simply x, ie an inclined line. Thus, the smaller the value of x, the greater the influence of the unit in the denominator, creating the necessary curvature. And considering this function on different scales, it is possible to control the degree of this curvature:

Thus, we can rewrite the previous function with stiffness control, using only a rational 3-order polynomial:

## Automate this with

In order not to specify piecewise-continuous functions each time, we can define an auxiliary function that will do this on its own, taking the donor function as an argument.

If our function already has a diagonal symmetry and is aligned with the center of coordinates (as a sinusoid), then we can simply make

Example usage:

If you need to collect from pieces, as in the case with a parabola, and the center of coordinates defines the docking points, then the formula becomes slightly more complicated:

Example usage:

## Let's turn to the exponent

Quite any function can be a donor for solving this problem, it is necessary only aboutProvide it with points of inflection. Take, for example, an exponential shifted down by one:

Previously, to ensure the necessary inflection at the zero point, we raised the function in a square. But you can go in another way - for example, to sum up with another function whose derivative at the point zero is opposite in sign with the derivative of the exponent. For example, -x:

Depending on which side we are going to take the curve from, it will depend on the final form of the function. Now, using a previously defined auxiliary function and selecting one of the sides, we get:

Or

And now we can compare them on one chart:

It is seen that as k → 0 they tend to coincide; and since we can not calculate their values directly, since we obtain a division by zero, we use the limit:

And we have already obtained a piece function known to us from the parabola.

## Breaking the symmetry of

So far we have considered exclusively symmetric functions. However, there are times when we do not need symmetry, for example, to simulate distortions when tube amplifiers are played.

Take the exponent and multiply it by the inverted parabola in the square - to get the intersection with the abscissa at points -1 and ? and at the same time ensure the smoothness of the second derivative; The parameterization is realized by scaling the argument of the exponent:

Find the primitive and scale it:

Since for k = 0 we obtain a division by zero:

In addition, we find the limit,

which is a smooth third-order polynomial already known to us. Combining everything into one function, we get

Instead of initially designing an asymmetric function, you can go another way - to use the ready symmetric, but "bend" the value of this function with the help of an additional function of the curve defined on the interval {-?1}.

Consider, for example, the hyperbola:

Considering its segment in different scales, it is possible to regulate the degree of curvature in both directions. How to find this piece? Starting from the graph, one could search for the intersections of the hyperbola with the line. However, since such an intersection does not always exist, this creates some difficulties. Therefore, we will go the other way.

First, we add the scaling factors to the hyperbola:

then we will compose a system of equations defining the conditions for the passage of the hyperbola through given points-and its solution will give the coefficients of interest to us:

Now we substitute the solution into the initial formula and simplify:

Let's see what we got depending on the parameter k:

It is noteworthy that for k = 0 the formula naturally collapses in x and there are no special situations - although with respect to the initial hyperbola this is equivalent to a segment of zero length, and two at once. It is also noteworthy that the inverse function is the same, but with the negative parameter k:

Now we can use it to modify an arbitrary constraint function, and the parameter k thus specifies the point of intersection with the ordinate axis:

Similarly, it is possible to construct curves from other functions, for example, power-law with a variable base:

Or back to it logarithmic:

## More accuracy is needed

We may want to have a guaranteed linear span of the function at some interval. It is logical to organize by introducing a straight line into a piecewise continuous function,

empty spaces in which it is necessary to fill with some function. Obviously, for a smooth docking with a linear section, its first derivative must be equal to one; and all subsequent (if possible) zero. In order not to output this function anew, we can take it already ready and adapt to this task. Also, you can see that the extreme points are a little further than one - this is necessary to maintain the slope of the linear section.

We take the function PolySoft derived earlier and move it so that in the center of coordinates we get the unit:

It follows from its properties that the n-1 subsequent derivatives at points 0 and 2 will be zero:

Now integrate it:

The function was shifted downward relative to the abscissa axis. Therefore, it is necessary to add a constant (equal to the value of the function at point 0) in order to combine the coordinate centers:

Here we have zero in degree n. It has not shrunk, since the value of zero to the power of zero is undefined; we can remove it manually, but we can explicitly state, with simplification, that n is more than zero:

Let's check just in case. The value at points 0 and 2 for all n:

Derivatives at the ends of the interval (for a polynomial of order 5):

As you can see, the function turned out to be rather cumbersome. In order not to drag it and not to overcomplicate the calculations, we will further manipulate with a specific polynomial, for example, the 4th order:

And now it can fill the free space:

Let's check:

## We go to infinity

Sometimes there may be a need for functions that tend to the unit, but do not reach it. Wikipedia suggests Several known solutions:

Since these functions do not reach unity, it is more convenient to normalize them by the derivative at the center of coordinates.

We can modify the form of such functions through their argument using some diagonally symmetric function, for example:

This function, by the way, is also the inverse of itself;

And, with reference to the arctangent as an example, we get

that, in particular, with the parameter k = 1 will give us function of Guderman .

As you can see, with this approach one can get undesirable excesses, therefore it is more preferable to control the rigidity of the constraint directly through the property of the function itself. We consider several such functions with a parameter whose derivation is omitted for brevity.

From the power function:

From the sum of two v-shaped functions with displacement:

From the generalized error function:

Integration of a rational polynomial:

It is interesting that its particular case is arctangent:

## Conclusion

The construction of this kind of functions can be an exciting activity, during which you will get both simple and complex, both beautiful and not so, formulas. It may seem that all of them are strongly similar to one another and there is no need for such a variety. This is not necessarily so.

The difference can be more visible in other scales - for example, logarithmic. Moreover, in addition to the tasks outlined in the title, similar functions can be used in other tasks-mixing signals, when a smooth attenuation of one signal is combined with a smooth increase in the other, or the construction of acoustic filters-and then the difference will be perceived by ear, or for constructing gradients - and then the difference will be perceived by eye. In addition, they can also be used as donors for other, more complex functions - for example, window .

In conclusion, it is worthwhile to clarify a few more points.

All functions here were defined in the range from -1 to 1. In case you need another range (for example, from 0 to 1), you can easily recalculate it either manually:

Or using the built-in scaling function:

And to facilitate the export of the resulting formulas to the program code, the function CForm:

can be useful.

The source document Mathematica can be downloaded here .

Notes:

^{ [1] }a real mathematician will certainly be able to rigorously prove (or refute) this assertion.

^{ [2] }In the standard course of mathematical analysis, hypergeometric functions are not considered.

^{ [3] }this overload is only defined for a character unit; A unit in a floating-point format (for example, when plotting a chart) will not be recognized.

It may be interesting

#### weber

Author**27-09-2018, 22:36**

Publication Date
#### Development / Mathematics

Category- Comments: 0
- Views: 334