%For this script we assume w0=1.

minw=0.1;  maxw=10;                         %min and max freqs
w=logspace(log10(minw),log10(maxw),1000);   %omega values       
z=[1 1/sqrt(2) 0.5 0.3 0.2 0.1];            %zeta values
c='mbcgyr';                                 %colors for plots

for i=1:length(z)
    p=-atan2(2*z(i)*w,(1-w.^2))*180/pi;  %angle (deg)
    semilogx(w,p,c(i),'Linewidth',2);
    leg{i}=sprintf('\\zeta=%3.2g',z(i));
    hold on
end
xlabel('Frequency (\omega/\omega_0)');
ylabel('Phase (^o)');
legend(leg)
axis([minw maxw -180 0]);

for i=1:length(z)
% Uncomment appropriate lines to see an approximation.
    
%     % Cheever1
    wl=log10(2/z(i))/2; 
    wh=1/wl;
    title('Phase vs. frequency (Cheever 1 Approx)');

    % Cheever2
    wl=0.2^z(i);
    wh=5^z(i);
    title('Phase vs. frequency (Cheever 2 Approx)');
% 
%     % Brogan
%     wl=1/(1+5*z(i));
%     wh=1+5*z(i);
%     title('Phase vs. frequency (Brogan Approx)');

%     Cheever4
    wl=0.1^z(i);
    wh=10^z(i);
    title('Phase vs. frequency (Cheever 4 Approx)');
    
    
    plot([wl wh],[0 -180],[c(i) ':'])
    plot(wl,0,[c(i) 'o'],'MarkerFaceColor',c(i));
    plot(wh,-180,[c(i) 'o'],'MarkerFaceColor',c(i));
end
hold off

%% compare
clf
z=0.5;
minw=0.01*sqrt(10);  maxw=100/sqrt(10);                         %min and max freqs
w=logspace(log10(minw),log10(maxw),1000);   %omega values  
    p=-atan2(2*z*w,(1-w.^2))*180/pi;  %angle (deg)
    semilogx(w,p,'g','Linewidth',2);    hold on
    title('Phase vs. frequency, \zeta=0.5');
wl=0.2^z;
    wh=5^z;
    plot([minw wl wh maxw],[0 0 -180 -180],'r:')
    wl2=0.1^z;
    wh2=10^z;
    plot([minw wl2 wh2 maxw],[0 0 -180 -180],'b:')
    plot(wl,0,'ro','MarkerFaceColor','r');
    plot(wh,-180,'ro','MarkerFaceColor','r');


    plot(wl2,0,'ro','MarkerFaceColor','b');
    plot(wh2,-180,'ro','MarkerFaceColor','b');
    legend({'Exact','Approx 2','Approx 4'});
    axis([minw maxw -180 0]);
    set(gca,'YTick',-180:45:0)
    grid