%TPOSTS Determine transient characteristics of a response. % [tp, os, ts] = tposts(t, y) % Determines the peak time, overshoot, and % settling time for a response vector. % Inputs: % t: time vector % y: response vector % t and y must be of the same dimensions. If the response has not reached % steady state, there will be an error. In addition, there must be at % least ~100 samples in the response vector. Note that if there is no % overshoot in the response, the returned values for tp and os are % essentially meaningless. Also note that this function only works when % the steady state value is a constant (e.g. a step response). % Outputs: % tp: Peak time = the time at which the peak value in y occurs % os: Overshoot = percent difference between the peak and steady state values % ts: settling time = time at which steady state is reached (i.e. the % response stays within 2% of the steady state value) % % Edited by Luke Reisner. The author of the original version is unknown. function [tp, os, ts] = tposts(t, y) % Check for valid input vectors [mt,nt] = size(t); if (mt < nt) % If t is a row vector m = mt; mt = nt; % Swap indexes for the row vector nt = m; end [my,ny] = size(y); if (my < ny) % If y is a row vector m = my; my = ny; % Swap indexes for the row vector ny = m; end if (mt ~= my) error('Input vectors are not of same size.'); end if (nt ~= ny) error('Input vectors are not of same size.'); end if (nt ~= 1) % If time variable is a matrix, not a vector (N by 1 or 1 by N) error('t must be a vector, not a matrix.'); end m5pc = ceil(mt/20); % Determine the number of samples / 20 %if (m5pc < 10) % If not at least ~200 samples if (m5pc < 5) % If not at least ~100 samples error('Not enough data points.'); end if (y(my) < 0) y = -y; % Invert the signal if its last sample (steady state) is negative end for i=1:m5pc if (abs(y(mt-i)-y(mt)) / y(mt) >= 0.001) % If output y is not very steady by the end of the signal error('Steady state may not have reached.'); end end % Find the peak time and overshoot yss = y(mt); % Steady state = last sample in the y vector (assumes steady state is dc) [yp,kp] = max(y); % Peak value = max value in y os = (yp-yss) / yss; % Overshoot (os) = percent difference between the peak and steady state values tp = t(kp); % Peak time (tp) = the time at which the peak value in y occurs % Find the settling time via the following procedure: % Working backwards from the end of the response vector, find the first % sample whose value is more than 2% different from the steady state value. % Then select the subsequent sample, which will be <= 2% different from the % steady state value. This sample marks the beginning of the steady state. k = mt; while (abs((y(k)-yss) / yss) <= .02) k = k-1; end k = k+1; % to bring back y(k) within 2% of the steady state ys = y(k); % ys = first sample in the final group of samples % that are within +/- 2% of the steady state value. % i.e. it is the first sample that can be considered steady % enough to be steady state ts = t(k); % settling time (ts) = time at which the first sample of % the steady state portion of the signal occurs