%  Exemplo 16.16 (Medidas Experimentais)
clear all
close all
clc

H = tf([128],[1 4.16 64])
% w = logspace(0, 2);

bode(H,{1,10^2})
grid on

% ou
w = logspace(0, 2);
xi = 0.26;
wn = 8;
for i = 1:length(w)
    MdB(i) = mag2db(2*wn^2/sqrt((wn^2-w(i)^2)^2+(2*xi*wn*w(i))^2)); 
end
figure
semilogx(w,MdB,'r','LineWidth',2);
axis([10^(0) 10^2 -40 20])
grid on
title('Diagrama assintótico de módulo')
xlabel('\omega')
ylabel('M_{dB}(\omega)')


for i = 1:length(w)
    if w(i)<=wn
        Phi(i) = -atan(2*xi*wn*w(i)/(wn^2-w(i)^2))*180/pi;
    elseif w(i)>wn
        Phi(i) = (-pi-atan(-2*xi*wn*w(i)/(w(i)^2-wn^2)))*180/pi;
    end
end
figure
semilogx(w,Phi,'r','LineWidth',2);
axis([10^(0) 10^2 -180 0])
grid on
title('Diagrama assintótico de fase')
xlabel('\omega')
ylabel('\Phi(\omega)')
