MATLAB: How to cascade a four port device with a two port device using rfckt objects in RF Toolbox

cascadenetworksRFRF Toolboxrkckttoolbox

I want to connect a 4 port device (e.g. coupler) with a two port device (e.g. amplifier) in cascade using RF Toolbox rfckt objects.  But, there is currently no rfckt object for a 4 port device.  How can I achieve this workflow?

Best Answer

Unlike RF Blockset which has a 'Coupler' block for Simulink, there is no four port device rfckt object.  In RF Toolbox, rfckt circuit objects are designed for chain of objects, i.e. we are limited to two port networks.  As a workaround,  if you could represent the Coupler as a 2 port network touchstone file, it will be possible to read the file and create a 'rfckt.passive' element with it. And then we can continue do the RF analysis on that network.
Please refer to the sample scripts below demonstrating this using two approaches - 
1. Use the 'nport' object which reads both S-parameters and noise data from a Touchstone file. Then cascade them using an 'rfbudget' object.  This sample script is the recommended and approach and it uses some functions which were released in MATLAB R2017a.  
%%Using NEW nport objects (Recommended)/Approach 1
%%Read in a 3 Port coupler

S3 = sparameters('default.s3p');
Coupler to to 2-port nport
S2 = snp2smp(S3);
rfwrite(S2, 'coupler2port.s2p')
% Creating a nport object
Coupler2port = nport('coupler2port.s2p');
% Note that coupler does not have noise of its own.
ckt1 = nport('default.s2p'); % Other 2 port sparameter device

% Noise Data can be viewed by doing ckt1.NoiseData
%%CASCADE

ckt_cascade = rfbudget([Coupler2port ckt1],[2e9:1e9:10e9],-30,10);
show(ckt_cascade);
To export the network into Simulink, i.e. RF Blockset please uncomment and execute the command below
% exportRFBlockset(ckt_cascade)
2. Use the 'rfckt.amplifier' object which contains both S-parameter and noise data. Then cascade them using 'rfckt.cascade'.  This approach is not recommended, as it might be not available in future releases. 
%%Using OLD rfckt objects /Approach 2
%%Read in a 3 Port coupler
ckt = read(rfckt.passive,'default.s3p'); % This only works for passive data
s3p = ckt.NetworkData.Data;
Z0 = ckt.NetworkData.Z0;
Coupler to to 2-port rfckt.amplifier
s2p = snp2smp(s3p,Z0);
% Creating a rfckt object
rfwrite(s2p,ckt.NetworkData.Freq,'coupler2port_ckt.s2p')
Coupler2port = read(rfckt.amplifier,'coupler2port_ckt.s2p');
ckt1 = read(rfckt.amplifier,'default.s2p'); % Other 2 port sparameter device
%%CASCADE
ckt_cascade = rfckt.cascade('Ckts', {Coupler2port, ckt1});
analyze(ckt_cascade, 2.9e9)