Code covered by the BSD License  

Highlights from
Using S-Parameters in MATLAB & Simulink

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

flowgraph_1.m
% Solutions to flowgraph problems using the Symbolic Toolbox
% Flowgraphs are a staple of s-parameter based network analysis. 
% Although there are "simple" rules (Sam Mason, MIT) for their analysis, 
% even simple rules can be forgotten as time passes.  The symbolic toolbox 
% is a great tool for analyzing flowgraphs, and no "rules" need be remembered. It 
% is simply a matter of writing the equations for the flowgraph in an
% orderly manner, and using the "solve" function of the symbolic toolbox to
% do the tedious and error prone algebra. 
%
% See http://en.wikipedia.org/wiki/Mason's_rule 
%
% The notation used in this example is as follows: 
%     summing node: O
%     signal flow : > < V ^    (right, left, down, up)
%     signal node : *
%     branches without a coefficient:  default "gain" = 1
%
% 
%   As a first example, consider a simple feedback topology .... 
%
%                x1
%      u*--K->---O---G->----*----*y
%                |          |
%                ---<-(-H)--- 
%
% Goal: solve for output y in terms of input u and parameters K,G,H
% Dick Benson, The Mathworks
% Copywrite 2002-2010 The MathWorks, Inc. 

%%  start by defining symbols ..
clc
clear
syms u y K G H x1 
% then write the two equations
eq1 =  x1*G - y;         % y  = G*x1
eq2 = -H*y + K*u - x1;   % x1 = K*u - H*y

solution_1 = solve(eq1,eq2,x1,y);  % use the solve function on the equations
disp('answer to problem 1: ')
y = solution_1.y      % solution for y in terms of input x 
                      %  y = K*u/(H*G+1)*G

%% That was a simple example that could have easily be worked by hand. 
% For a more challenging case, consider the error factors (Exy) involved with  S parameter measurements (Sxy)
%       a1 = incident, b1 = reflected, b2 = transmitted  (power)
%
%                -------------------------  Exf->------------------------------
%                |                                                             |
%                |                    x1                        x3             |
%      a1*---->--*--->-----O--->------*-----S21->-----O---->----*-----Etf->----O------*b2
%                |         |          |               |         |
%                V Edf     ^ Esf      V S11           ^ S22     V Elf
%                |         |          |               |         |
%      b1*--<----O--<-Erf--*--<-------O-----<-S12-----*----<----O     
%                          x4                         x2
%
%    Goal:  solve for outputs b1 and b2 in terms of input a1
%

syms a1 b1 b2 Edf Erf Esf S11 S21 S22 S12 Elf Etf Exf x1 x2 x3 x4

eq1 = Esf*x4 + a1     - x1;     %  x1 = Esf*x4 + a1        
eq2 = Elf*x3          - x2;     %  x2 = Elf*x3
eq3 = S21*x1 + S22*x2 - x3;     %  x3 = S11*x1 + S22*x2
eq4 = S11*x1 + S12*x2 - x4;     %  x4 = S11*x1 + S12*x2 
eq5 = Erf*x4 + Edf*a1 - b1;     %  b1 = Erf*x4 + Edf*a1
eq6 = Etf*x3 + Exf*a1 - b2;     %  b2 = Etf*x3 + Exf*a1

solution = solve(eq1,eq2,eq3,eq4,eq5,eq6,x1,x2,x3,x4,b1,b2);
disp('answer to problem 2: ')
b1=solution.b1 
b2=solution.b2   

% In case you do not have the symbolic Toolbox, the solution is : 
% b1 = a1*(Erf*S21*S12*Elf-Erf*S22*Elf*S11+Erf*S11-Edf*S21*Esf*S12*Elf+Edf*S22*Elf*S11*Esf-Edf*S22*Elf-Edf*S11*Esf+Edf)/(-S21*Esf*S12*Elf+S22*Elf*S11*Esf-S22*Elf-S11*Esf+1)
% b2 = a1*(Etf*S21-Exf*S21*Esf*S12*Elf+Exf*S22*Elf*S11*Esf-Exf*S22*Elf-Exf*S11*Esf+Exf)/(-S21*Esf*S12*Elf+S22*Elf*S11*Esf-S22*Elf-S11*Esf+1)
% The chances of getting this answer correct is slim to none for most of us mortals ! 



Contact us at files@mathworks.com