% FILE: legoDcpBode1_0.m (00courses\..\labview-XX-Bode)
% AUTH: P.Oh
% DATE: 12/12/18 10:00
% REFS: 
% DESC: Display Boe for fitted DCP model
% VERS: 1.0: works; displays Bode in rad/sec

% Recall 11/26/18 notes, after using Matlab System ID toolbox, our TF

%               31.24               Theta(s) [deg]
%     G = --------------------- = ------------------
%           2                       Motor(s) [%]
%          s  + 0.8084s + 44.4

% So, define as

gNum = [31.24]; 
gDen = [1 0.8084 44.4];

G = tf(gNum, gDen)
roots(gDen)

% Alternatively, can use the state space form and convert

Fol = [0 1; -44.4 -0.8084];	% (2x2) open-loop F matrix (fitted DCP)
Gol = [0; 31.24];		% (2x1) open-loop G matrix (fitted DCP)
Hol = [1 0];			% (1x2) open-loop H matrix (fitted DCP)
Jol = 0; 

[gNumStateSpace, gDenStateSpace] = ss2tf(Fol, Gol, Hol, Jol);
GStateSpace = tf(gNumStateSpace, gDenStateSpace)

% Use Bode function

% bode(g), grid

% Specify min and max frequency range
wRange = {0.1, 100}; % note the french braces; want to plot between these frequencies
figure(1)
bode(G, wRange), grid

 