阶跃响应指标的matlab计算
最近師兄讓幫忙計算階躍響應的指標,就是改定實驗數據或仿真數據,求響應指標(概念見程序中)。編程代碼和效果如下
%% 求階躍響應的典型指標
function main_GetPerformanceOfStepResponse
clc
clear all
close all
global gTolerance
gTolerance = 0.05; % 調整時間的偏差容許范圍
%% test
wn = 1;
xi = 0.3;
g = tf(wn^2, [1, 2*xi*wn, wn^2]);
t = 0:0.01:15;
y = step(g,t);
%% 計算階躍響應的指標
stepvalue = 1;
[OverShoot, RiseTime, PeakTime, AdjustTime, SteadyStateError] = GetPerformanceOfStepResponse(t, y, stepvalue);
% 繪圖
figure
plot(t,y)
grid on
line([PeakTime, PeakTime], [0, (1 + OverShoot/100)*stepvalue], 'color', 'r')
text(PeakTime, stepvalue*0.05, sprintf('峰值時間%.2f',PeakTime))
text(PeakTime, (1 + OverShoot/100 + 0.05)*stepvalue, sprintf('超調量%.2f%%',OverShoot))
line([RiseTime, RiseTime], [0, stepvalue], 'color', 'r')
text(RiseTime, -stepvalue*0.05, sprintf('上升時間%.2f',RiseTime))
line([AdjustTime, AdjustTime], [0, stepvalue*(1 + gTolerance)], 'color', 'r')
text(AdjustTime, stepvalue*0.05, sprintf('調整時間%.2f',AdjustTime))
line([AdjustTime t(end)], stepvalue*[(1 - gTolerance), (1 - gTolerance)], 'color', 'r', 'linestyle', '--')
text(AdjustTime, stepvalue*(1 - gTolerance-0.05), sprintf('容許范圍%.2f', 1 - gTolerance))
line([AdjustTime t(end)], stepvalue*[(1 + gTolerance), (1 + gTolerance)], 'color', 'r', 'linestyle', '--')
text(AdjustTime, stepvalue*(1 + gTolerance+0.05), sprintf('容許范圍%.2f', 1 + gTolerance))
text(t(end)*0.9, stepvalue*1.05, sprintf('穩態誤差%f', SteadyStateError))
end
%% 求階躍響應的典型指標
function [OverShoot, RiseTime, PeakTime, AdjustTime, SteadyStateError] = GetPerformanceOfStepResponse(t, y, stepvalue)
% 超調量Mp:最大超調量規定為在暫態期間輸出超過對應于輸入的終值的最大偏離量
% 上升時間tr:在暫態過程中,輸出第一次達到對應于輸入的終值的時間(從t=0開始計時)
% 峰值時間tp:對應于最大超調量發生的時間(從t=0開始計時)
% 調整時間ts:輸出與其對應于輸入的終值之間的偏差達到容許范圍(一般取5%或2%)所經歷的暫態過程時間(從t=0開始計時)
% 穩態誤差err:給定輸入與穩態輸出的差值
global gTolerance
% 超調量和峰值時間
[OSValue, OSIndex] = max(y);
OverShoot = (OSValue - stepvalue)/stepvalue*100;
PeakTime = t(OSIndex);
% 上升時間
index = find(y >= stepvalue, 1, 'first');
RiseTime = t(index);
% 調整時間和穩態誤差
index1 = find(y <= stepvalue*(1 - gTolerance), 1, 'last'); % 容許范圍由全局變量指定
index2 = find(y >= stepvalue*(1 + gTolerance), 1, 'last');
if isempty(index2) % 如果沒有超調量,此值為空
??? index = index1;
else
??? index = max(index1, index2);
end
index = max(index1, index2);
AdjustTime = t(index);
SteadyStateError = mean(y(index:end)) - stepvalue; % 這里的穩態誤差計算為調整時間后的數據平均值與給定輸入的差,概念上是最后時刻的值與給定輸入的差
end
?
運行結果為:
改變容許范圍偏差為0.02的結果
總結
以上是生活随笔為你收集整理的阶跃响应指标的matlab计算的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 亚马逊为什么那么多人做跟卖?
- 下一篇: 损益表数据‘异常’