help-octave
[Top][All Lists]
Advanced

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

Re: Loading touchstone s2p file


From: Sergei Steshenko
Subject: Re: Loading touchstone s2p file
Date: Mon, 4 Oct 2010 16:40:53 -0700 (PDT)


--- On Mon, 10/4/10, rbb <address@hidden> wrote:

> From: rbb <address@hidden>
> Subject: Re: Loading touchstone s2p file
> To: address@hidden
> Date: Monday, October 4, 2010, 1:05 PM
> 
> 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.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 

For better efficiency move

      if strcmpi(mode,'complex')
      else % mode == 'magph

to be outside the loop, i.e. have a 'while' loop per mode.

Regards,
  Sergei.


      



reply via email to

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