help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading touchstone s2p file


From: David Bateman
Subject: Re: Loading touchstone s2p file
Date: Thu, 29 Apr 2010 22:53:13 +0200
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

address@hidden wrote:
Hello,

how can i load a touchstone format file *.s2p into my workspace with Octave?

Thanks in advance.

Nacho.


Touchstone files have three elements you need to treat..

1) Comments starting with "!" that need to be thrown away
2) Q single option line that define what the contents of the file are starting with "#"
3) Data lines that is basically a table of white space separated columns

If you know what is in your file (Frequency in what units, measured property Y, S matrix, data in dB/angle, etc and the impedance), then just throwing away the comment and option lines and reading the 9 columns of your matrix should be relatively easy. Assuming your data is in real/imaginary parts something like

fid = fopen ("myfile.s2p", "rt");
freq = [];
s11 = [];
s12 = [];
s21 = [];
s22 = [];
while (! feof (fid))
  str = fgets (fid);
  [val , len]= sscanf ("%f %f %f %f %f %f %f %f %f");
  ## Ignore lines with less than 9 elements
  if (len == 9)
    freq = [freq; val(1)];
    s11 = [s11; complex (val(2), val(3))];
    s12 = [s12; complex (val(4), val(5))];
    s21 = [s21; complex (val(6), val(7))];
    s22 = [s22; complex (val(8), val(9))];
  endif
endwhile
fclose(fid)

will do it though inefficiently. These files are typically not very big so the above if probably good enough. Its easy to modify the above for the case of having your data in dB/angle and magnitude/angle as well.

D.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]