PID controller in matlab code
Show older comments
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 Comments
Sam Chak
18 minutes ago
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
about 15 hours ago
Edited: mohammed hussein
11 minutes ago
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
2 minutes ago
Answers (0)
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
