PID controller in matlab code
古いコメントを表示
I'm having trouble using a PID controller in a MATLAB script. I don't have the transfer function typically used with PID in MATLAB, but I do have the output error signal. I would like to connect this error signal to the PID code to improve the error correction.
For example, if I have this data (from the black system). I want to reduce the (maximum overshoot , rise time , settling time , ...) by using a PID controller .
clear all
clc
load("Vo_vn.mat")
load("x.mat")
Volt = Vo_vn;
Time = x;
OUTS = stepinfo(Volt,Time);
Desire = 23.5;
Error = Vo_vn-Desire;
RiseT = OUTS.RiseTime
SettT = OUTS.SettlingTime
OVERSH = (OUTS.Peak)-Desire
plot(Time,Volt)
4 件のコメント
Sam Chak
2026 年 5 月 22 日 6:40
If you don't have the system transfer function in the traditional sense, where does the output error signal come from in the MATLAB script? The output signal must be generated from some system, either a transparent mathematical model or a data-driven black box. The PID controller, pid() function, itself does not require a transfer function to operate, unless you are referring to tuning the PID controller, which I understand you implied is intended to “improve the error correction.”
mohammed hussein
2026 年 5 月 22 日 7:31
編集済み: mohammed hussein
2026 年 5 月 22 日 22:01
You first need to estimate a transfer function that fits the step response data. This is a topic in system identification, and you can use the tfest() function to address this type of problem. Otherwise, you can also intelligently guess the coefficients if you are familiar with the underlying system.
clear all
clc
load("Vo_vn.mat")
load("x.mat")
Volt = Vo_vn;
Time = x;
OUTS = stepinfo(Volt,Time);
Desire = 23.5;
Error = Vo_vn-Desire;
RiseT = OUTS.RiseTime
SettT = OUTS.SettlingTime
OVERSH = (OUTS.Peak)-Desire
% Estimated model
s = tf('s');
w = 8e3; % natural frequency (guess)
K = w^2; % stiffness coeff
zet = 0.16; % damping ratio (guess)
D = 2*zet*w; % damping coeff
Gp = K/(s^2 + D*s + K); % 2nd-order transfer function
figure
step(Gp, Time(end)) % step response of model
hold on
plot(Time, Volt/Desire, 'r-') % normalized data
legend('estimated model', 'black box data')
hold off
ylim([0 1.6])
mohammed hussein
2026 年 5 月 22 日 14:50
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Linear Model Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



