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
RiseT = 1.3248e-04
SettT = OUTS.SettlingTime
SettT = 0.0037
OVERSH = (OUTS.Peak)-Desire
OVERSH = 14.3081
plot(Time,Volt)

4 Comments

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
mohammed hussein about 15 hours ago
Edited: mohammed hussein 11 minutes ago
Dear Sam Chak, thank you very much for your response. My output is derived from a data-driven black box. I have improved my equestion based on your feedback.
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
RiseT = 1.3248e-04
SettT = OUTS.SettlingTime
SettT = 0.0037
OVERSH = (OUTS.Peak)-Desire
OVERSH = 14.3081
% 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])
Thank you for your suggestion

Sign in to comment.

Answers (0)

Asked:

about 16 hours ago

Edited:

11 minutes ago

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!