Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to determine the time constant from the plot

Tags:

plot

matlab

In the following minimal working example,

M=2;
num=1/M;
den=[1 6/M];
G=tf(num,den);
step(G)

The output response of the system is shown

enter image description here

The characteristics of the system is missing the time constant which in this case Tc = M/6 (sec). Is there an option to activate this important characteristic? The time constant is the time that takes the step response to reach 63% of its final value. In this example, the plot via the steady state option, the final output is 0.167. To compute the time constant basically we compute the time of the magnitude of the output at 0.167*0.63 = 0.10521. From the plot, we can see

enter image description here

which matches Tc=M/6 where M=2. This is tedious workaround. Hopefully there is an option regarding this issue.

like image 728
CroCo Avatar asked Dec 18 '25 09:12

CroCo


1 Answers

You don't really need to plot output of step function to find Tc:

M=2;
num=1/M;
den=[1 6/M];
G=tf(num,den);

tvect = 0:0.0001:3;    % provide any time limits you want; 
                       % the smaller time increment the higher "accuracy"
[val, t] = step(G, tvect);
idx_Tc = find(val>=0.63*max(val), 1, 'first');

Tc = t(idx_Tc);        % Tc which you are looking for
val_Tc = val(idx_Tc);  % value at Tc

If you need a nice plot, you can easily create it afterwards, since you already have all required values (t, val, Tc, val_Tc).

EDIT:

You can extend context menu following example below:

M=2;
num=1/M;
den=[1 6/M];
G=tf(num,den);
step(G);

f = gcf;
c = f.CurrentAxes.UIContextMenu;
uimenu(c,'Label','Find Tc','Callback',@findTc);
f.CurrentAxes.UIContextMenu = c;

where function findTc is defined as:

function findTc(~,callbackdata)
    t = callbackdata.Source.Parent.Parent.CurrentAxes.Children(1).Children(2).XData;
    val = callbackdata.Source.Parent.Parent.CurrentAxes.Children(1).Children(2).YData;
    idx_Tc = find(val>=0.63*max(val),1, 'first');

    Tc = t(idx_Tc);
    val_Tc = val(idx_Tc);

    disp(['Tc: ' num2str(Tc) ' val_Tc: ' num2str(val_Tc)])
end

enter image description here

Instead of printing values in command window you can annotate the plot but I would say it's rather cosmetic change. The code above shows how you can have this feature as an option in context menu.

like image 187
machnic Avatar answered Dec 21 '25 06:12

machnic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!