File Exchange

image thumbnail

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

version 1.5 (25.3 KB) by

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

4.66667
18 Ratings

27 Downloads

Updated

View License

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

Comments and Ratings (29)

alaoui ismail

thank u for this file

Malan Ruppert

Thanks, really helpful.

Very useful

tudor dima

tudor dima (view profile)

@padoh
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.

padoh

padoh (view profile)

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

tudor dima

tudor dima (view profile)

@Josiah,

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

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.

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));

Tao Yi Lee

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

tudor dima

tudor dima (view profile)

@Matthew
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.

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.

Andrew Farris

tudor dima

tudor dima (view profile)

@Chris
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(:)))

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

Thanks

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

sree kasturi

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

S Malevsky

j hatchatourian

leonard cristovski

great, thanks; suggestions : smith chart ? circles ?

rajeeh akbar

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

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.

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.

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.

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 !

george ardeleanu

nifty ! I like the file import/export operations

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 !

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

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

Updates

1.5

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

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

1.2

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

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

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

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

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

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

MATLAB Release
MATLAB 7.6 (R2008a)

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

» Watch video