% The RC circuit square wave response
%
% -----------------------------------------------------------------------------------
%
% (C) 2017, Krzysztof Sozanski, Digital Signal Processing in Power Electronics Control 
% Circuits, second edition, Springer-Verlag, London, 2017. 
% 
% -----------------------------------------------------------------------------------
%

clear all; close all; 
l_width = 2; f_size = 16;
C=1; R=1; N=8000; dt=0.001;
b=1; % numerator
a=[R*C 1]; % denumerator
H=tf(b,a)  % RC transfer function
t=(0:N-1)*dt;
x=[ones(1,N/4) zeros(1,N/4) ones(1,N/4) zeros(1,N/4)];
y=lsim(H,x,t);
figure('Name','RC impuse response','NumberTitle','off');
plot(t,x,'b',t,y,'r','linewidth',l_width),
set(gca,'FontSize',f_size), grid on
ylabel('Amplitude'), xlabel 'Time [s]'; legend('Square wave','RC response');
print('RC_imp_resp.pdf','-dpdf');
