% Matlab code to evaluate the RC lowpass filter response of the first 2-port problem
% HWb, Feb 16, 2017, Section 2 Fig 1, left.

NFT=1024; NF=1+NFT/2;%number of non-negative frequencies
Fmax=1e4; Fs=2*Fmax; Fmin=Fs/NFT;
 f=0:Fmin:Fmax; %sweep frequency from 0 to Fmax [Hz] in steps of Fmin [Hz]

R1=9.8e3; R2=9.8e3; %in [Ohms]
C=47e-9; %[Farads]
T=zeros(NF,2,2); %Init output array

for k=1:NF;
s=2*pi*f(k)*1j; %Define complex frequency

%Define three matrices for the three elements in the network
T1=[1 R1;0 1];
T2=[1 0; s*C 1];
T3=[1 R2;0 1];
T(k,:,:)=T1*T2*T3; %avoid all the messy algebra

end %end for freq loop

%Save T matrix elements
kf=2:(NF-1); %freq limits; avoid ends
A=T(kf,1,1); B=T(kf,1,2);
C=T(kf,2,1); D=T(kf,2,2);

%compute Z matrix Z1, Z2, Z12
Z1=D./C; Z12=1./C;
Z2=A./C; Z21=Z12; % Assumes reciprocity

