% https://www.barghnews.com
% --- Bode Diagram ---
%% Enter the numnator and denuminator of the transfer function
num=[9 1.8 9];
den=[1 1.2 9 0];
%% Specify the frequency range and enter the command [mag,phase,w]=bode(num,den,w)
w=logspace(-2,3,100);
[mag,phase,w]=bode(num,den,w);
% convert mag to decibels
madB=20*log10(mag);
%% plot the Magnitude curve
%Spacify the range of the magnitude.
%For the system considered, the magnitude range should include -50 dB and +50 dB.
%Enter dBmax Line and dBmin line.
%To plot the magdB curve enter the following dbmax, dBmin and semilogx 
dBmax=50*ones(1,100);
dBmin=-50-ones(1,100);
semilogx(w,madB,'o',w,madB,'-',w,dBmax,'-',w,dBmin,'-')
% enter grid, titel, xlabel and ylabel
grid
title('Bode Diagram of G(s)=9(s^2+0.2s+1)/[s(s^2+1.2s+9)]')
xlabel('Frequency (rad/sec)')
ylabel('Gain dB')
%% plot the phase angle curve
%Specify the range of the phase angle.
%For the system considered, the phase-angle range should include -150 degrees and +150 degrees.
%Enter pmax  and pmin  into the program and draw pmax line and pmin line.
%To plot  the phase curve  enter the following pmax, pmin and  semilogx
pmax=150*ones(1,100);
pmin=-150*ones(1,100);
figure(2)
semilogx(w,phase,'o',w,phase,'-',w,pmax,'-',w,pmin,'-')
% enter grid, titel, xlabel and ylabel

grid
title('Bode Diagram of G(s)=9(s^2+0.2s+1)/[s(s^2+1.2s+9)]')
xlabel('Frequency (rad/sec)')