%
% This matlab script plots the magnitude and phase of
% a continuous-time transfer 
%
% Plotting response of 3.12 part (d)
%
wz1 = 10.0 ;
wz2 = 100.0 ;
wp1 = 1.0 ;
wp2 = 1000.0 ;
K = 1.0 ;

%
% 0.001 Hz to 1 MHz
freq = logspace(-3, 6);
w = 2 * pi .* freq ;
%
% Specify coefficients of H(s) (decreasing powers of s)
%
num = K * [( 1.0 / (wz1 * wz2))  (1.0 / wz1 + 1.0 / wz2)  1.0];
den = [( 1.0 / (wp1 * wp2))  (1.0 / wp1 + 1.0 / wp2)  1.0];
%
Ha = freqs(num, den, w) ;
mag_squared = Ha .* conj(Ha) ;
phs = (180 / pi) .* angle(Ha) ;
%
% Magnitude response in dB
subplot(211), semilogx(freq, 10*log10(mag_squared))
xlabel('Frequency (Hz)'), ylabel('Magnitude (dB)')
title('Continuous-time Filter')
% Phase response in degrees
subplot(212), semilogx(freq, phs)
xlabel('Frequency (Hz)'), ylabel('Phase (deg)')
%
