[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Loading touchstone s2p file
From: |
rbb |
Subject: |
Re: Loading touchstone s2p file |
Date: |
Mon, 4 Oct 2010 13:05:58 -0700 (PDT) |
Hi,
Most vendors provide s-parameters in touchstone formats as phase and
magnitude pairs, not as complex numbers. So something more like the code
below would work better...
function [sp] = read_touchstone(fname, mode);
% [sp] = read_touchstone(fname);
%
if nargin < 2, mode = 'magph'; end
fid = fopen (fname, 'rt');
sp.freq = [];
if strcmpi(mode,'complex')
sp.s11 = [];
sp.s12 = [];
sp.s21 = [];
sp.s22 = [];
else
sp.s11.mag = [];
sp.s11.ph = [];
sp.s12.mag = [];
sp.s12.ph = [];
sp.s21.mag = [];
sp.s21.ph = [];
sp.s22.mag = [];
sp.s22.ph = [];
end
while ( ~feof(fid) )
str = fgets (fid);
if (str(1) == '!')
continue;
end
[val, len]= sscanf (str, '%f %f %f %f %f %f %f %f %f');
% Ignore lines with less than 9 elements
if (len == 9)
sp.freq = [sp.freq; val(1)];
if strcmpi(mode,'complex')
%sp.s11 = [sp.s11; ( complex(val(2), val(3)) ) ];
%sp.s21 = [sp.s21; ( complex(val(4), val(5)) ) ];
%sp.s12 = [sp.s12; ( complex(val(6), val(7)) ) ];
%sp.s22 = [sp.s22; ( complex(val(8), val(9)) ) ];
sp.s11 = [sp.s11; ( val(2) .* exp(i*val(3)) ) ];
sp.s21 = [sp.s21; ( val(4) .* exp(i*val(5)) ) ];
sp.s12 = [sp.s12; ( val(6) .* exp(i*val(7)) ) ];
sp.s22 = [sp.s22; ( val(8) .* exp(i*val(9)) ) ];
else % mode == 'magph'
sp.s11.mag = [sp.s11.mag; val(2)];
sp.s11.ph = [sp.s11.ph; val(3)];
sp.s21.mag = [sp.s21.mag; val(4) ];
sp.s21.ph = [sp.s21.ph; val(5) ];
sp.s12.mag = [sp.s12.mag; val(6) ];
sp.s12.ph = [sp.s12.ph; val(7) ];
sp.s22.mag = [sp.s22.mag; val(8) ];
sp.s22.ph = [sp.s22.ph; val(9) ];
end
end
end
fclose(fid);
Russ
--
View this message in context:
http://octave.1599824.n4.nabble.com/Loading-touchstone-s2p-file-tp2076132p2954967.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Re: Loading touchstone s2p file,
rbb <=