% Frequency response calculation of the RC circuit using Laplace
% transformation
%
% -----------------------------------------------------------------------------------
%
% (C) 2017, Krzysztof Sozanski, Digital Signal Processing in Power Electronics Control 
% Circuits, second edition, Springer-Verlag, London, 2017. 
% 
% -----------------------------------------------------------------------------------
%
% RC Laplace
clear all; close all; 
l_width = 2; f_size = 16;
C=1; R=1; 
b=1; % numerator
a=[R*C 1]; % denumerator
w = logspace(-2,1,200); % generate logarithmically spaced vectors
h = freqs(b,a,w);
mag = abs(h); phase = angle(h); phasedeg = phase*180/pi;
figure('Name','RC Frequency response','NumberTitle','off');
  subplot(2,1,1), loglog(w,mag,'r','linewidth',l_width),
	set(gca,'FontSize',f_size), grid on
	title('(a)'), ylabel('Magnitude');
  subplot(2,1,2), semilogx(w,phasedeg,'b','linewidth',l_width), 
	set(gca,'FontSize',f_size),grid on, title('(a)'),
	xlabel 'Frequency (rad/s)', ylabel('Phase [deg]');
  print('Mag_and_phase_RC_freqs.pdf','-dpdf');