Main Content

Writing S2P Touchstone® Files

This example shows how to write out the data in circuit objects you create in the MATLAB® workspace into an industry-standard data file: Touchstone®. You can use these files in third-party tools.

This simple example shows how to create and analyze an RLCG transmission line object. It then shows how to write the analyzed result into a Touchstone file and compare the file data to the original result.

Create an RF Circuit Object to Represent an RLCG Transmission Line

Create an txlineRLCGLine object to represent an RLCG transmission line using the transmission line's parameters. This example uses Name-Value pairs to implement the parameters in the RLCG transmission line shown in figure 1 [1].

Figure 1: RLCG transmission line.

ckt1 = txlineRLCGLine('R',100,'L',80e-9,'C',200e-12,'G',1.6);

Clone the Circuit Object

Use the clone function to make a copy of the first txline object.

ckt2 = clone(ckt1)
ckt2 = 
  txlineRLCGLine: RLCGLine element

           Name: 'RLCGLine'
      Frequency: 1.0000e+09
              R: 100
              L: 8.0000e-08
              C: 2.0000e-10
              G: 1.6000
       IntpType: 'Linear'
     LineLength: 0.0100
    Termination: 'NotApplicable'
       StubMode: 'NotAStub'
       NumPorts: 2
      Terminals: {'p1+'  'p2+'  'p1-'  'p2-'}

Cascade Two Circuit Objects

Use the circuit object to cascade the two transmission lines together.

ckt = circuit([ckt1,ckt2]);

Analyze the Cascade and Plot S-Parameter Data

Use the sparameters object to analyze the cascade in the frequency domain. Then, use the smithplot method to plot the object's S11 on a Smith chart®.

freq = linspace(0,10e9);
ckt_sparameters = sparameters(ckt,freq);
figure
smithplot(ckt_sparameters,[1,1],'LegendLabels','S11 Original')

Write out the Data to an S2P File

Use the rfwrite function to write the data to a file.

workingdir = tempname;
mkdir(workingdir);
filename = fullfile(workingdir,'myrlcg.s2p');
if exist(filename,'file')
    delete(filename)
end
rfwrite(ckt_sparameters,filename);

Compare the Data

Read the data from the file myrlcg.s2p into a new sparameters object and plot S11 on a Smith chart. Visually compare this Smith chart to the previous one to see that the data matches.

compare_ckt = sparameters(filename);
figure
smithplot(compare_ckt,[1,1],'LegendLabels','S11 from S2P')

[1] M. Steer, "Transmission Lines," in Microwave and RF Design: Transmission Lines. vol. 2, 3rd ed. Raleigh, North Carolina, US: North Carolina State University, 2019, ch. 2, sec. 2, pp.58.