View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
S-parameter toolbox (+ Z, Y, H, G, ABCD, T)

4.7 | 18 ratings Rate this file 48 Downloads (last 30 days) File Size: 25.3 KB File ID: #6080 Version: 1.5

S-parameter toolbox (+ Z, Y, H, G, ABCD, T)


tudor dima (view profile)


20 Oct 2004 (Updated )

Convert between N-port representations of RF circuits. Read / Write industry-standard files.

| Watch this File

File Information

Useful for the RF designer, it manipulates the various complex representations of the circuits as multi-ports, namely conversions from one representation to another as well as reading/writing from/to files in industry-standard format.
The (more oftenly used) transformations are singularity-protected; some legacy stuff could be done better today... and it is slowly getting done :-)!

The file parsing/writing in particular has been greatly improved thanks to the input received from the users on this site.

I hope this toolbox will help you when searching for that elusive insight when working at high frequencies !

Have fun !

p.s. any ideas ? bugs ? email me


This file inspired Coupling Coefficient K For A Resonator Filter.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements none; it's strictly numeric so it should work on any matlab version supporting N-size arrays (newer than 5.1?); still, I preserved all s2*4.m and *2s4.m alternate functions (2-D arrays only) which should work on 3.x versions
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (29)
24 Mar 2017 alaoui ismail

thank u for this file

Comment only
28 Feb 2017 Malan Ruppert

Thanks, really helpful.

29 Jan 2014 Charaf Eddine SOURIA

Very useful

06 Aug 2013 tudor dima

tudor dima (view profile)

I am not sure I understand the question. The S-parameters are stored as 3D matrices, with the last index spanning the frequency. An N-port at F frequencies will have the size [N N F], that is NxNxF, where N=2 for this 2-port case.

Comment only
30 Jul 2013 padoh

padoh (view profile)

what is meant by 2x2xM matrix? how to write it in matlab?

Comment only
18 May 2012 tudor dima

tudor dima (view profile)


It shouldn't... (uses str2num or str2double...)
anyway, could you send me a sample file so I can take a look at it?

Comment only
17 May 2012 Josiah Bartlett

I'm finding an issue with SXPWrite.
It does not support or properly truncate scientific notation- a number like -9.8235e-5 ends up being written to the file like -9.8235. This is a HUGE problem! Otherwise a great set of tools.

Comment only
12 Jan 2012 Tao Yi Lee

I suggest a minor modification in SXPParse.m for robustness.

At line 55.

% --- find out matrix order ---
[~, NoOfPorts] = strtok(DataFileName, '.');
NoOfPorts = strtok(NoOfPorts, 'p');
NoOfPorts = str2double(NoOfPorts(3:end));

Comment only
12 Jan 2012 Tao Yi Lee

26 Oct 2011 David Yu-Ting Wu

Thank you for saving me from having to write an S2P parser! Truly appreciate it!

21 Dec 2010 tudor dima

tudor dima (view profile)

Great to hear that!

Sure, please send the files over and I'll have a look; it was about time I did a revision of the whole box.

Comment only
14 Dec 2010 Matthew

Matthew (view profile)

Thanks Tudor for writing this very handy toolbox, I have been using it for about a year while I am in grad school and it has saved me a lots of time with its robust handling of Touchstone files (much better and faster than the script I wrote myself) and the handling of singularities in network parameter conversion.

One comment, I have made an alternate version of the s2a and a2s functions which take an optional Zo parameter so that you can have non-unit Zo. In this version Bnew=B*Zo and Cnew=C/Zo in s2a, and it simply reverses these factors in a2s. It is easy to do this external to the function for Y and Z parameters since you just multiply or divide by Zo, but a bit messier to do for ABCD parameters. If you like I can send you the files.

13 Aug 2010 Andrew Farris

12 Jul 2010 tudor dima

tudor dima (view profile)

Yes, that's absolutely right.
One note: in case your data is closer to a singularity (for instance during calibrations when data exhibits extremely low or high return losses) then it's a good practice to doublecheck the above using :

a1 = s2a(s1);
a2 = s2a(s2);
s_12_a = a2s(a1*a2);

and then compare the results; (it was not your case, here the maximum delta is 2.2215e-016 -- using max(abs(s_12_a(:)-s(:)))

Comment only
25 Jun 2010 Chris

Chris (view profile)

Would this be the right way to calculate the cascaded input/output VSWR?:

% first in cascade
s1 = [148+1.4*1i 193-756*1i; 198-762*1i 119+44*1i]*1e-3;
% second in cascade
s2 = [33+68*1i 724-167*1i; 731-166*1i -22+77*1i]*1e-3;

t1 = s2t(s1);
t2 = s2t(s2);

t = t1*t2;
s = t2s(t);

(1+abs(s(1,1)))/(1-abs(s(1,1))) % input VSWR
(1+abs(s(2,2)))/(1-abs(s(2,2))) % output VSWR


Comment only
12 Aug 2009 tudor dima

tudor dima (view profile)

posted the new version that allows more separators and also improves the file parsing speed

@sree kasturi :
thanks for the observation; however, in the absence of noise data the previous version of the function only executed the following two lines, then jumped to end; anyway, I have meanwhile posted the new version and included your suggestion

Comment only
28 Jul 2009 sree kasturi

to read s2p files without noise data, change line 135 in SXPParse.m to 'while flagNoiseStarted && flagGotOptions'.

24 Sep 2008 S Malevsky

15 Dec 2007 j hatchatourian

29 Nov 2007 leonard cristovski

great, thanks; suggestions : smith chart ? circles ?

12 Oct 2007 rajeeh akbar

very good; if it had plots it would completely replace my viewer

20 May 2007 Jeff P

I wanted to use this to read Agilent PNA .s2p files. However, the sxpparse.m function makes a call to phrase2word.m, which is not included in the toolbox. I found this function on the Exchange. Now, sxpparse hangs up trying to parse the first line of numerical data. The code does not appear to handle cell arrays well. Anyway, it was easier to write my own function than to debug this one.

Comment only
17 May 2007 jonathan cape

very good ! ...and very fast :-)

I like especially the singularity-protection, is saves me a lot of hassle from defining quasi-perfect shorts or opens.

BTW, I did not find any files that the parser won't work with. Mind you, we use only HP/Agilent, which is among the orginators of the standard.

02 May 2007 bahareh siasi

the program is exellent but SXPparse function has a problem,once reading the snp file for more than 4 ports(when the sparameter of a frequency is written in more than one single line )the program brakes.

09 Oct 2006 yin chow

Excellent ! we are a few RF designers sharing a single licence of mwoffice and since using this toolbox everything goes smoother - I can get 50-75% of the work done before I fire up the simulator to refine my design. Thanks !

03 Jul 2006 george ardeleanu

nifty ! I like the file import/export operations

03 Jun 2005 wayne sho

it's pretty cool; I like the fact that it's simple and doesn't need 1G of RAM; btw, yes, I tried it in 4.2, it works !

30 Mar 2005 charles beam

yes, cascaded simulations will work just fine if you know how to write the individual s-matrices; I hope this will be included in a later release

27 Oct 2004 al davidson

excellent so far (I have only used the conversion to and from s-parameters); I like especially converting to ABCD or T parameters, this way you can do cascaded simulations

22 Feb 2005

added 3rd dimension (multiple frequencies) for z2a, y2a

03 Jun 2005

added limited octave compatibility : s2a, a2s, y2s, SXPRead

09 Mar 2006

modified SXPParse.m in order to handle Z,G,Y,ABCD data, and also comment lines anywhere inside data file

22 Jun 2007

re-included Phrase2Word.m (previously left out by error); unless you had unzipped over an older version the file parsing would not work;

25 Oct 2008 1.1

SXPParse revision : v.1.4, 2008.10.25
fix for the case nPort>4 (when lines get split)
allow comments on lines
allow various separators (tabs!)
better parsing, subfunctions introduced
limited protection for non-compliant files

05 Aug 2009 1.2

more separators allowed, file read speed improvement, better code flow

30 Sep 2011 1.4

- added 3rd dimension (frequency)
  to h2y, y2h, g2y, y2g, h2g,
- faster h2* and *2h conversions
- h2g (and its wrap, g2h) as
  protected inverses

29 May 2012 1.5

properly write long numbers in scientific notation
accept multi-line comments
accept more frequency units (before MHz only)
close the parsed file

Contact us