RF Toolbox 2.6
Writing A Touchstone® File
You can write out the data in RFCKT 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 demo shows how to create and analyze an RLCG transmission line object. It then shows how to write the analyzed result into a Touchstone file, read it back in, and compare the file data to the original result.
Contents
Create an RFCKT Object to Represent an RLCG Transmission Line
Create an RFCKT.RLCGLINE object to represent an RLCG transmission line. Create variables to represent the transmission line parameters and use the SET method to update the RFCKT.RLCGLINE object to use these values.
Ckt1 = rfckt.rlcgline; R = 0.002; % ohm/m G = 0.002; % S/m mu_0 = pi*4e-7; % H/m L = mu_0; % H/m c = 299792458; % m/s epsilon_0 = 1/(mu_0*c^2); % F/m C = epsilon_0; % F/m LineLength = 10; % m Z_vacuum = sqrt(mu_0/epsilon_0) % ohms set(Ckt1, 'R', R, 'G', G, 'L', L, 'C', C, 'LineLength', LineLength);
Z_vacuum = 376.7303
Create a Second RFCKT Object by Copying the First One
Make a copy of the first RFCKT object. Then change the capacitance of the new object to introduce mismatch that will appear as a finite reflection coefficient on the Smith chart.
Ckt2 = copy(Ckt1)
set(Ckt2, 'C', Ckt1.C/2);
Ckt2 =
Name: 'RLCG Transmission Line'
nPort: 2
AnalyzedResult: []
LineLength: 10
StubMode: 'NotAStub'
Termination: 'NotApplicable'
Freq: 1.0000e+009
R: 0.0020
L: 1.2566e-006
C: 8.8542e-012
G: 0.0020
IntpType: 'Linear'
Cascade Two RFCKT Objects to Form a New RFCKT Object
Create an RFCKT.CASCADE object that cascades the two transmission lines together.
Ckt3 = rfckt.cascade('Ckts', {Ckt1, Ckt2});
Analyze the Cascaded RFCKT Object and Plot its S11
Use the ANALYZE method of the RFCKT.CASCADE object to analyze the cascade in the frequency domain. Then, use the SMITH method to plot the object's S11 on a Smith chart.
Freq = logspace(0,8,20); analyze(Ckt3, Freq); fig1 = figure; hline = smith(Ckt3, 'S11'); legend(hline, 'S_{11} Original');
Write out the Data to an S2P File
Use the WRITE method of RFCKT.CASCADE object to write the data to an .s2p file.
workingdir = tempname; mkdir(workingdir) FileName = fullfile(workingdir, 'myrlcg.s2p'); if exist(FileName, 'file') delete(FileName); end write(Ckt3, FileName);
Inspect the S2P File
Use the TYPE function to display the contents of the S2P file in the MATLAB command window to see the Touchstone file format.
type(FileName)
# KHz S RI R 50 ! S-Parameters data ! Freq reS11 imS11 reS21 imS21 reS12 imS12 reS22 imS22 0.0010000000 -0.4995668830 0.0000017038 0.4996335434 -0.0000014511 0.4996335434 -0.00 00014511 -0.4995668830 0.0000017038 0.0026366509 -0.4995668830 0.0000044923 0.4996335434 -0.0000038260 0.4996335434 -0.00 00038260 -0.4995668830 0.0000044924 0.0069519280 -0.4995668828 0.0000118447 0.4996335433 -0.0000100879 0.4996335433 -0.00 00100879 -0.4995668828 0.0000118448 0.0183298071 -0.4995668819 0.0000312305 0.4996335423 -0.0000265984 0.4996335423 -0.00 00265984 -0.4995668819 0.0000312305 0.0483293024 -0.4995668751 0.0000823438 0.4996335358 -0.0000701306 0.4996335358 -0.00 00701306 -0.4995668751 0.0000823440 0.1274274986 -0.4995668283 0.0002171119 0.4996334903 -0.0001849098 0.4996334903 -0.00 01849098 -0.4995668284 0.0002171123 0.3359818286 -0.4995665025 0.0005724481 0.4996331739 -0.0004875424 0.4996331739 -0.00 04875424 -0.4995665037 0.0005724491 0.8858667904 -0.4995642378 0.0015093416 0.4996309743 -0.0012854749 0.4996309743 -0.00 12854749 -0.4995642464 0.0015093441 2.3357214691 -0.4995484944 0.0039795297 0.4996156831 -0.0033892719 0.4996156831 -0.00 33892719 -0.4995485542 0.0039795365 6.1584821107 -0.4994390650 0.0104912138 0.4995093980 -0.0089349194 0.4995093980 -0.00 89349194 -0.4994394809 0.0104912370 16.2377673919 -0.4986791954 0.0276357322 0.4987713849 -0.0235324982 0.4987713849 -0.02 35324982 -0.4986820834 0.0276358889 42.8133239872 -0.4934385957 0.0723941929 0.4936826159 -0.0615785238 0.4936826159 -0.06 15785238 -0.4934585122 0.0723963417 112.8837891685 -0.4589240427 0.1826943622 0.4602182935 -0.1542335913 0.4602182935 -0.15 42335913 -0.4590551443 0.1827301093 297.6351441631 -0.2852418642 0.3736130053 0.2936325835 -0.2995173863 0.2936325835 -0.29 95173863 -0.2858977090 0.3741008493 784.7599703515 0.0679211792 0.4271026849 -0.0153624476 -0.2453561328 -0.0153624476 -0.24 53561328 0.0667708824 0.4302594244 2069.1380811148 0.3288626312 0.3558833285 -0.0821509890 -0.0254485420 -0.0821509890 -0.02 54485420 0.3305419624 0.3643818249 5455.5947811685 0.5389529747 0.2731026895 0.0008593120 0.0166149682 0.0008593120 0.01 66149682 0.5469296660 0.2870131451 14384.4988828766 0.6765852740 0.1732861806 -0.0006910367 -0.0016923988 -0.0006910367 -0.00 16923988 0.6957628522 0.1957444816 37926.9019073225 0.7427051546 0.0878652805 -0.0001926848 0.0000721400 -0.0001926848 0.00 00721400 0.7822742513 0.1131602650 100000.0000000000 0.7616882453 0.0365074342 0.0000508918 0.0000317939 0.0000508918 0.00 00317939 0.8180769911 0.0528302064
Compare the Data
Read the data from the file 'myrlcg.s2p' into a new RFCKT object and plot S11 on a Smith chart. Visually compare this Smith chart to the previous one to see that the data is the same.
Ckt4 = read(rfckt.passive, FileName); fig2 = figure; hline = smith(Ckt4, 'S11'); legend(hline, 'S_{11} from S2P');
close(fig1); close(fig2);
Store