Graphics Reference
In-Depth Information
y_3 = y_2;y_2 = y_1;y_1 = yout(k);
wkp_1 = wkp(k);
wkd_1 = wkd(k);
wki_1 = wki(k);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% Second run executes based on Matlab's built-in PID %%%%%%%%%
load model
%convert idss model to ss
H = ss(n4s1);
%take “measured” channel
H = H(1);
ts = H.Ts;
%train pid
C = pidtune(H, 'pi');
plantWithPid = feedback(series(C, H), 1);
% rin->(+)->[C]—> [H]——>yout
% ^ |
% |———————-|
%constant rin
%pid_rin = refValue * ones(1, length(time));
pid_rin = rin;
pid_yout = lsim(plantWithPid, pid_rin, time);
pid_error = pid_rin' - pid_yout;
%to find pid's output send rin-yout to pid
%rin-yout' -> [pid] -> u
pid_u = lsim(C, pid_rin-pid_yout', time);
%test original system with pid signal
%pid_yout2 = lsim(n4s1, pid_u, time);
%Output graphs
figure 1);
hold on;
plot(time,rin,'b',time,yout,'r');
plot(time,pid_rin,'k',time,pid_yout,'k');
xlabel('Frame');ylabel('rin,yout');
legend('rin','yout', 'pid yout');
%Error graphs
figure 2);
plot(time,error,'r', time, pid_error, 'b');
xlabel('Frame');ylabel('error');
legend('error', 'pid error');
%SNPID control input
%figure 3);
%plot(time,u,'r');
%xlabel('Frame');ylabel('Control Input');
%legend('u', 'pid u');
Search WWH ::




Custom Search