Code covered by the BSD License

### Highlights fromUsing S-Parameters in MATLAB & Simulink

from Using S-Parameters in MATLAB & Simulink by Dick Benson
Example of rf amplifier design using S parameters in both MATLAB and Simulink.

match_net.m
```%  Getting close to the finish !  Now need to develop ABCD (chain) to s param transformation
%  since the matching networks were (sucessfully) described using ABCD two port description.
%  Assume same Zo on both ports
% Copywrite 2002-2010 The MathWorks, Inc.

clear
clc
syms a b c d z11 z12 z21 z22 s11 s12 s21 s22 Zo s

%% first, abcd -> z
z11 = a/(c);  z12 = (a*d-b*c)/(c); z21=1/(c); z22 = d/(c);  % dimensionally ok and "confirmed"
% note that C=0 (no shunt) is a bummer ....
% Then, z -> s parameters ...
D      = ((z11/Zo+1)*(z22/Zo+1)-z12*z21/(Zo^2));
sp(1,1) = simple(((z11/Zo-1)*(z22/Zo+1)-z12*z21/(Zo^2))/D);
sp(2,2) = simple(((z11/Zo+1)*(z22/Zo-1)-z12*z21/(Zo^2))/D);
sp(1,2) = simple(2*z12/(D*Zo));
sp(2,1) = simple(2*z21/(D*Zo));

%% using the above, convert LC matching net to s param
% First, create ABCD as before in s_plus_match_2.m
syms  x y Z Y s   L1 L2 C1 C2 Co Rl w
Z(1,1) = 1; Z(1,2) = x; Z(2,1) = 0; Z(2,2)=1;    % series impedance
Y(1,1) = 1; Y(1,2) = 0; Y(2,1) = y; Y(2,2)=1;    % shunt admittance

% build a network using abcd chain parameters, same topology *happens* to be used on transistor input and output
Z(1,2) = L2*s;            % series L2
Y(2,1) = C2*s;            % shunt C2
N      = Z*Y;             % combine (series 1st)
Z(1,2) = L1*s + 1/(C1*s); % series lC
N_abcd  = N*Z;            % series L2, shunt C2, followed by series L1 C1

disp('Here is the general S parameter description of the INPUT matching network: ')
N_s     = subs(sp,{a b c d Zo},{N_abcd(1,1), N_abcd(1,2), N_abcd(2,1),N_abcd(2,2),50})

Y(2,1)  = Co*s;          % for output match, need to add a shunt cap
Nout_abcd  = simple(Y*N_abcd);

disp('Here is the general S parameter description of the OUTPUT matching network: ')
Nout_s  = subs(sp,{a b c d Zo},{Nout_abcd(1,1), Nout_abcd(1,2), Nout_abcd(2,1),Nout_abcd(2,2), 50});

%% determine polynonials

load amp_data;            % Now pick up LC NUMERICAL values for matching network
a=1e6;                    % Simulink Model was scaled by 1 MHz for computational reasons.
for i=1:2
for k=1:2
[numi,deni] = numden(N_s(i,k));
numi = collect(numi,s);
deni = collect(deni,s);
% input matching network
L1=(L1i+Loi)*a; L2=L2i*a; C1=C1i*a; C2=C2i*a; % scale components
ni(i,k).p= sym2poly(subs(numi));
di(i,k).p= sym2poly(subs(deni));

[numo,deno]=numden(Nout_s(i,k));
numo = collect(numo,s);
deno = collect(deno,s);
% output matching network
L1=(L1o)*a; L2=L2o*a; C1=C1o*a; C2=C2o*a; % scale components
Co = Coo*a;
no(i,k).p= sym2poly(subs(numo));
do(i,k).p= sym2poly(subs(deno));
end
end;
% We now (ostensibly) have s-parameter matching networks in the s-domain
% with numerical coefficients for the powers of s.
% Confused yet ? Sorry, too many s's !
save match_net ni di no do
% The final confirmation will be to use these matching networks in a
% Simulink model, along with the Transistor model that was checked in
% sp_ex1.m

```