smooth step function with rise time
Mostrar comentarios más antiguos
Hi everyone,
I know this question is more related to math than Matlab, but I know there are many gurus out there who can easily solve this problem.
I would like to have a smooth step function with specified rise time, with some control of the output. I try to explain better. It is pretty simple to create a piece-wise linear step function and the correspondent smooth function with controlled slope using a parametrized logistic function:
% time axis
t = linspace(0,5,10000);
% step function params
Tr = 1;
a = 2;
t50 = 2;
% piece-wise linear step function
x = @(t)(t > t50-Tr/2 & t < t50+Tr/2).*(a/Tr.*(t-t50)+a/2)+(t >= t50+Tr/2).*a;
% logistic function
y = @(t)a./(1+exp(-4*(t-t50)/Tr));
% plot
figure, hold on
plot(t,x(t))
plot(t,y(t))
grid on
However I would like to control the shape of the rounded corners, making them more or less close to the original function according to an additional parameter (but keeping the slope of the original function) as suggested by the arrows in the following picture

I'm not in love with the logistic function, so any other function is welcome.
Thank you in advance for your help
Fabio
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 23 de Oct. de 2021
Editada: John D'Errico
el 23 de Oct. de 2021
You cannot solve the problem you claim to want to solve using a simple logistic. It does not have the flexiibility to control both the amplitude of the rise, as well as the location and the slope at the midpoint. There are not sufficient free parameters in that functional form for the task at hand.
A simple variation on the question would allow you to write the problem in the form of a piecewise polynomial though.
Break it down into the subproblem: Can you find a low order polynomial that passes through the point with (x,y) coordinates (T50,1), with a given slope? As well, require that the curve must pass through a point (T100,2), with a slope of 0 at that point. See that since you could control how close T100 is to T50, then it would allow you to control the shape of the curve over that rise.
Once you have done the above task, then you would do exactly the same thing, effectively reflecting the form you just found to complete the bottom half of this curve.
A straight line is not sufficiently complex. But perhaps a 2nd or 3rd order polynomial would suffice. In fact, you can show that the polynomial must be at least a cubic to satisfy all of those conditions.
So, write down the requirements. A cubic polynomial has 4 coefficients. Call them a,b,c,d. I'll use syms here to do the work, since I'm too lazy myself. We would have:
syms a b c d T50 T100 t dT
P(t) = a*t^3 + b*t^2 + c*t + d;
DPdt = diff(P,t);
eq(1) = P(T50) == 1; % force the curve to pass through (T50,1)
eq(2) = P(T100) == 2; % force it through (T100,2)
eq(3) = DPdt(T100) == 0; % force the slope at the upper endpoint to be 0
Finally, what is the slope at the midpoint? It must match the slope of a straight line segment. So pick some dT, such that dT is greater than 0, but less than T100-T50. The line segment will be chosen so that it passes through the points (T50 - dT,0) and (T50 + dT,2). (This is the linear segment you have drawn. The slope of that line segment is 2/(2*dT) = 1/dT.
eq(4) = DPdt(T50) == 1/dT;
Now we can solve for a,b,c,d.
abcdsol = solve(eq,[a,b,c,d])
And yes, the solution looks a bit messy, but that is why we have computers. It is also why I did not do this with pencil and paper.
Pupper = subs(P,abcdsol)
Again, a mess, but still easy enough to use.
First, I'll pick some values for T50, T100, and dT. In this example, I'll pick T50=2, and then we will leave T100 and dT to be controlled at a later time.
Pupperfun = matlabFunction(subs(Pupper,T50,2))
Now, plot the curve.
% line segment for comparison. Here, I'll choose
T50 = 2;
dT = 1;
T100 = 4;
plot([T50-dT, T50, T50+dT],[0 1 2],'-r')
hold on
fplot(@(T) Pupperfun(T,3.5,dT),[T50,3.5],'g')
fplot(@(T) Pupperfun(T,4,dT),[T50,4],'b')
xlabel T
grid on
legend('Line segment','T100 = 3.5','T100 = 4','Location','SouthEast')
See how you can control the shape of the curve by adjusting T100 and dT. You can now reflect that upper functional form to the bottom half of the curve. I won't do that part as this is surely a student project of some form.
1 comentario
Fabio Freschi
el 28 de Oct. de 2021
Editada: Fabio Freschi
el 28 de Oct. de 2021
Categorías
Más información sobre Stability Analysis en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





