Hi Eric,

My approach to this would be, using current PDL (2.080), in multiple stages:

  *   Read the data into a matrix ($m) with columns (freq,m11,a11,etc) as you 
seem to have already done (although you haven’t shown any code or 
real-but-minimal sample data which limits how much help people can provide)
  *   Slice out the complex data, e.g. $c = $m->slice(‘1:-1’) so it’s columns 
(m11,a11,etc)
  *   Reshape that with splitdim: $reshaped = $c->splitdim(0, 2) so columns 
(mag,angle)
  *   Convert the polar format to rectangular: $angrad = $reshaped->slice(1) * 
$PDL::Transform::DEG2RAD; $rect = $reshaped->slice(0) * 
$angrad->cos->append($angrad->sin) so columns (real,imag) (your formula seems 
to not multiply the real by the magnitude which looks to me wrong)
  *   Convert that to cdouble: $cd = czip($rect->mv(0,-1)->dog) giving row 
vector of cdouble
  *   Reshape that with splitdim: $m22 = $cd->splitdim(0,4)->splitdim(0,2) 
giving (2,2,n) where n is number of original rows (this might need transposing 
given your data is column-major – if you leave it column-major like Fortran, 
make sure your docs are VERY CLEAR about that since PDL’s idiom is 0th dim is 
columns)

Best regards,
Ed

From: Eric Wheeler<mailto:p...@lists.ewheeler.net>
Sent: 01 July 2022 08:36
To: pdl-general@lists.sourceforge.net<mailto:pdl-general@lists.sourceforge.net>
Subject: [Pdl-general] How do you create a set of cdouble matrices from (real, 
imag) values?

Hello all,

I'm trying to read RF touchstone (.s2p) files that are in a format like so:

Freq(MHz)  MagS11  AngS11  MagS21  AngS21   MagS12  AngS12   MagS22  AngS22
100         0.588   50.208  0.770   -35.964  0.770   -35.964  0.588   50.208
...
200         0.589   51.209  1.771   -34.965  1.771   -34.965  1.589   51.209

There are thousands of these lines in a file, one line for each measured
frequency.  Each line represents a complex scattering (S-parameter) matrix
and the mag/angle format needs to be converted to a `cdouble` to work on
the matrix mathematically.

A single-line 2x2 complex matrix might look as follows, where S_ji is a
complex value:

 [ S11  S12 ]
 [ S21  S22 ]

Since we are provided values in magnitude-angle format (in this example)
they must be converted to cdoubles so we can work on them.  There are
several formats: RI, DB, and MA.  For the MA (mag-angle) format this is
the transform where $a is mag and $b is angle:

        $complex = cos($b*pi()/180) + $a*sin($b*pi()/180) * i

I can generate a vector of 2x4 matrices holding mag-angle pairs by reading
the file line by line like this:

[
  [
   [ S11mag S11ang S12mag S12ang ]
   [ S21mag S21ang S22mag S22ang ]
  ]
  ... for each line
]

I'm new to using PDL and at this point I'm not sure how to convert them to
a computable form. Since the mag/angle values need to be manipulated in
parallel before creating a cdouble out of them I'm not sure how to go
about this.

Here are my questions:

1. How can I efficiently apply the
     real = cos($b*pi()/180)
     imag = $a*sin($b*pi()/180)
   transform to each mag/angle pair where $a is mag and $b is angle?

2. How can I then (or simultaneously) convert the 2x4 real-imag matrix
   from #1 into a 2x2 cdouble matrix to look something like this?

        [
          [
           [ S11  S12 ]
           [ S21  S22 ]
          ]
          ... for each line where Sji are cdoubles
        ]

3. Now that I've described the issue, is there a better way to do this?


Once they are in a matrix format then PDL can convert them efficiently to
other matrix types (T, A, Z, Y) to create parallel or series circuits with
matrix arithmetic at each frequency.  We can then optimize the RF filter
circuits using component models published by manufacturers from actual
measurements.

The resulting open-source tool will be comprised of Perl modules from this
work and published on CPAN.

Thanks for your help!

--
Eric Wheeler
KJ7LNW


_______________________________________________
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general

_______________________________________________
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to