Code covered by the BSD License  

Highlights from
CRCBode_example.m

image thumbnail

CRCBode_example.m

by

 

Simple example file showing usage of CRCBode function.

CRCBode_example.m
global aAxis mAxis

s = tf('s');

% Define 2nd order plant transfer function
Kdc = 1;
zeta = 0.8;
w_n = 1;
P = Kdc*w_n^2/(s^2+2*zeta*w_n*s+w_n^2);

% Define frequency vector
f = logspace(-1.7,0.2,1000);
w = 2*pi*f;

% Controller parameters causing intersections with forbidden region
Kp = 2.5;
Ki = 1.5;
Kd = 0.5;

% No Intersections
% Kp = 1.5;
% Ki = 1.0;
% Kd = 0.5;

% Define PID controller transfer function
C = Kp + Ki/s + Kd*s;

% Define performance (W1) and uncertainty (W2) weighting transfer functions
W1 = 10*(100/0.05*(s+.05)/(s+100))^-1;
W2 = 0.3*(0.6/100*(s+100)/(s+0.6))^-1;

% Evaluate frequency responses (mag and phase)
P_freq_resp = squeeze(freqresp(P,w));
P_dB = 20*log10(abs(P_freq_resp));
P_deg = 180/pi*unwrap(angle(P_freq_resp)')';

C_freq_resp = squeeze(freqresp(C,w));
C_dB = 20*log10(abs(C_freq_resp));
C_deg = 180/pi*unwrap(angle(C_freq_resp)')';

W1_freq_resp = squeeze(freqresp(W1,w));
W1_dB = 20*log10(abs(W1_freq_resp));

W2_freq_resp = squeeze(freqresp(W2,w));
W2_dB = 20*log10(abs(W2_freq_resp));

% Create CRCBode figure and set axis properties
figure(1); clf;
CRCBode(f,P_dB,P_deg,C_dB,C_deg,...
                    W2_dB,W1_dB,[-20 40],[-270 90],[-20 20],{'w','-',2.5},[0],{'k','-',2.5});         
set(aAxis,'YTick',[-270,-180,-90,0,90],'YTickLabel',{'-270','-180','-90','0','90'})

Contact us