My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
matrix.cpp File Reference

Dense matrix class implementation. More...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "logging.h"
#include "object.h"
#include "complex.h"
#include "vector.h"
#include "matrix.h"
Include dependency graph for matrix.cpp:

Go to the source code of this file.

Functions

matrix operator+ (matrix a, matrix b)
 Matrix addition.
 
matrix operator- (matrix a, matrix b)
 Matrix subtraction.
 
matrix operator* (matrix a, nr_complex_t z)
 Matrix scaling complex version.
 
matrix operator* (nr_complex_t z, matrix a)
 Matrix scaling complex version (different order)
 
matrix operator* (matrix a, nr_double_t d)
 Matrix scaling complex version.
 
matrix operator* (nr_double_t d, matrix a)
 Matrix scaling real version (different order)
 
matrix operator/ (matrix a, nr_complex_t z)
 Matrix scaling division by complex version.
 
matrix operator/ (matrix a, nr_double_t d)
 Matrix scaling division by real version.
 
matrix operator* (matrix a, matrix b)
 
matrix operator+ (matrix a, nr_complex_t z)
 Complex scalar addition.
 
matrix operator+ (nr_complex_t z, matrix a)
 Complex scalar addition different order.
 
matrix operator+ (matrix a, nr_double_t d)
 Real scalar addition.
 
matrix operator+ (nr_double_t d, matrix a)
 Real scalar addition different order.
 
matrix operator- (matrix a, nr_complex_t z)
 Complex scalar substraction.
 
matrix operator- (nr_complex_t z, matrix a)
 Complex scalar substraction different order.
 
matrix operator- (matrix a, nr_double_t d)
 Real scalar substraction.
 
matrix operator- (nr_double_t d, matrix a)
 Real scalar substraction different order.
 
matrix transpose (matrix a)
 Matrix transposition.
 
matrix conj (matrix a)
 Conjugate complex matrix.
 
matrix adjoint (matrix a)
 adjoint matrix
 
matrix abs (matrix a)
 Computes magnitude of each matrix element.
 
matrix dB (matrix a)
 Computes magnitude in dB of each matrix element.
 
matrix arg (matrix a)
 Computes the argument of each matrix element.
 
matrix real (matrix a)
 Real part matrix.
 
matrix imag (matrix a)
 Imaginary part matrix.
 
matrix eye (int rs, int cs)
 Create identity matrix with specified number of rows and columns.
 
matrix eye (int s)
 Create a square identity matrix.
 
matrix diagonal (vector diag)
 Create a diagonal matrix from a vector.
 
matrix pow (matrix a, int n)
 
nr_complex_t cofactor (matrix a, int u, int v)
 Computes the complex cofactor of the given determinant.
 
nr_complex_t detLaplace (matrix a)
 Compute determinant of the given matrix using Laplace expansion.
 
nr_complex_t detGauss (matrix a)
 Compute determinant Gaussian algorithm.
 
nr_complex_t det (matrix a)
 Compute determinant of the given matrix.
 
matrix inverseLaplace (matrix a)
 Compute inverse matrix using Laplace expansion.
 
matrix inverseGaussJordan (matrix a)
 Compute inverse matrix using Gauss-Jordan elimination.
 
matrix inverse (matrix a)
 Compute inverse matrix.
 
matrix stos (matrix s, vector zref, vector z0)
 S params to S params.
 
matrix stos (matrix s, nr_complex_t zref, nr_complex_t z0)
 S renormalization with all part identic.
 
matrix stos (matrix s, nr_double_t zref, nr_double_t z0)
 S renormalization with all part identic and real.
 
matrix stos (matrix s, vector zref, nr_complex_t z0)
 S renormalization (variation)
 
matrix stos (matrix s, nr_complex_t zref, vector z0)
 S renormalization (variation)
 
matrix stoz (matrix s, vector z0)
 Scattering parameters to impedance matrix.
 
matrix stoz (matrix s, nr_complex_t z0)
 Scattering parameters to impedance matrix identic case.
 
matrix ztos (matrix z, vector z0)
 Convert impedance matrix scattering parameters.
 
matrix ztos (matrix z, nr_complex_t z0)
 Convert impedance matrix to scattering parameters identic case.
 
matrix ztoy (matrix z)
 impedance matrix to admittance matrix.
 
matrix stoy (matrix s, vector z0)
 Scattering parameters to admittance matrix.
 
matrix stoy (matrix s, nr_complex_t z0)
 Convert scattering pto adminttance parameters identic case.
 
matrix ytos (matrix y, vector z0)
 Admittance matrix to scattering parameters.
 
matrix ytos (matrix y, nr_complex_t z0)
 Convert Admittance matrix to scattering parameters identic case.
 
matrix stoa (matrix s, nr_complex_t z1, nr_complex_t z2)
 Converts chain matrix to scattering parameters.
 
matrix atos (matrix a, nr_complex_t z1, nr_complex_t z2)
 Converts chain matrix to scattering parameters.
 
matrix stoh (matrix s, nr_complex_t z1, nr_complex_t z2)
 Converts scattering parameters to hybrid matrix.
 
matrix htos (matrix h, nr_complex_t z1, nr_complex_t z2)
 Converts hybrid matrix to scattering parameters.
 
matrix stog (matrix s, nr_complex_t z1, nr_complex_t z2)
 
matrix gtos (matrix g, nr_complex_t z1, nr_complex_t z2)
 
matrix ytoz (matrix y)
 Convert admittance matrix to impedance matrix.
 
matrix cytocs (matrix cy, matrix s)
 Admittance noise correlation matrix to S-parameter noise correlation matrix.
 
matrix cstocy (matrix cs, matrix y)
 Converts S-parameter noise correlation matrix to admittance noise correlation matrix.
 
matrix cztocs (matrix cz, matrix s)
 Converts impedance noise correlation matrix to S-parameter noise correlation matrix.
 
matrix cstocz (matrix cs, matrix z)
 Converts S-parameter noise correlation matrix to impedance noise correlation matrix.
 
matrix cztocy (matrix cz, matrix y)
 Converts impedance noise correlation matrix to admittance noise correlation matrix.
 
matrix cytocz (matrix cy, matrix z)
 Converts admittance noise correlation matrix to impedance noise correlation matrix.
 
matrix twoport (matrix m, char in, char out)
 Generic conversion matrix.
 

Detailed Description

Dense matrix class implementation.

References:

[1] Power Waves and the Scattering Matrix Kurokawa, K. Microwave Theory and Techniques, IEEE Transactions on, Vol.13, Iss.2, Mar 1965 Pages: 194- 202

[2] A Rigorous Technique for Measuring the Scattering Matrix of a Multiport Device with a 2-Port Network Analyzer John C. TIPPET, Ross A. SPECIALE Microwave Theory and Techniques, IEEE Transactions on, Vol.82, Iss.5, May 1982 Pages: 661- 666

[3] Comments on "A Rigorous Techique for Measuring the Scattering Matrix of a Multiport Device with a Two-Port Network Analyzer" Dropkin, H. Microwave Theory and Techniques, IEEE Transactions on, Vol. 83, Iss.1, Jan 1983 Pages: 79 - 81

[4] Arbitrary Impedance "Accurate Measurements In Almost Any Impedance Environment" in Scropion Application note Anritsu online(2007/07/30) http://www.eu.anritsu.com/files/11410-00284B.pdf

[5] Conversions between S, Z, Y, H, ABCD, and T parameters which are valid for complex source and load impedances Frickey, D.A. Microwave Theory and Techniques, IEEE Transactions on Vol. 42, Iss. 2, Feb 1994 pages: 205 - 211 doi: 10.1109/22.275248

[6] Comments on "Conversions between S, Z, Y, h, ABCD, and T parameters which are valid for complex source and load impedances" [and reply] Marks, R.B.; Williams, D.F.; Frickey, D.A. Microwave Theory and Techniques, IEEE Transactions on, Vol.43, Iss.4, Apr 1995 Pages: 914- 915 doi: 10.1109/22.375247

[7] Wave Techniques for Noise Modeling and Measurement S. W. Wedge and D. B. Rutledge, IEEE Transactions on Microwave Theory and Techniques, vol. 40, no. 11, Nov. 1992. pages 2004-2012, doi: 10.1109/22.168757 Author copy online (2007/07/31) http://authors.library.caltech.edu/6226/01/WEDieeetmtt92.pdf

Definition in file matrix.cpp.

Function Documentation

matrix abs ( matrix  a)

Computes magnitude of each matrix element.

Parameters
[in]amatrix
Todo:

add abs in place

a is const

Definition at line 529 of file matrix.cpp.

Here is the call graph for this function:

matrix adjoint ( matrix  a)

adjoint matrix

The function returns the adjoint complex matrix. This is also called the adjugate or transpose conjugate.

Parameters
[in]aMatrix to transpose
Todo:

add adjoint in place

Do not lazy and avoid conj and transpose copy

a is const

Definition at line 520 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix arg ( matrix  a)

Computes the argument of each matrix element.

Parameters
[in]amatrix
Todo:

add arg in place

a is const

Definition at line 553 of file matrix.cpp.

Here is the call graph for this function:

matrix atos ( matrix  a,
nr_complex_t  z1 = 50.0,
nr_complex_t  z2 = 50.0 
)

Converts chain matrix to scattering parameters.

Converts chain matrix to scattering parameters Formulae are given by [5] and are remembered here:

\begin{align*} S_{11}&=\frac{AZ_{02}+B-CZ_{01}^*Z_{02}-DZ_{01}^*}{\Delta} \\ S_{12}&=\frac{2(AD-BC) (\Re\text{e}\;Z_{01}\Re\text{e}\;Z_{02})^{1/2}} {\Delta}\\ S_{21}&=\frac{2(\Re\text{e}\;Z_{01}\Re\text{e}\;Z_{02})^{1/2}}{\Delta}\\ S_{22}&=\frac{-AZ_{02}^*+B-CZ_{01}^*Z_{02}+DZ_{01}}{\Delta} \end{align*}

Where:

\[ \Delta =AZ_{02}+B+CZ_{01}Z_{02}-DZ_{01} \]

Parameters
[in]aChain matrix
[in]z1impedance at input 1
[in]z2impedance at input 2
Returns
Scattering matrix
Bug:
Do not use fabs
Todo:
a, z1, z2 const

Definition at line 1213 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nr_complex_t cofactor ( matrix  a,
int  u,
int  v 
)

Computes the complex cofactor of the given determinant.

The cofactor is the determinant obtained by deleting the row and column of a given element of a matrix or determinant. The cofactor is preceded by a + or - sign depending of the sign of $(-1)^(u+v)$

Bug:
This algortihm is recursive! Stack overfull!
Todo:

((u + v) & 1) is cryptic use (u + v)% 2

#ifdef 0

static?

Definition at line 648 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix conj ( matrix  a)

Conjugate complex matrix.

Parameters
[in]aMatrix to conjugate
Todo:

add conj in place

a is const

Definition at line 503 of file matrix.cpp.

Here is the call graph for this function:

matrix cstocy ( matrix  cs,
matrix  y 
)

Converts S-parameter noise correlation matrix to admittance noise correlation matrix.

According to [7] fig 2:

\[ C_y=(I+Y)C_s(I+Y)^+ \]

Where $C_s$ is the scattering noise correlation matrix, $C_y$ the admittance noise correlation matrix, $I$ the identity matrix and $S$ the scattering matrix of device. $x^+$ is the adjoint of $x$

Warning
cs matrix and y matrix are assumed to be normalized
Parameters
[in]csS parameter noise correlation
[in]yAdmittance matrix of device
Returns
admittance noise correlation matrix
Todo:
cs, y const

Definition at line 1421 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix cstocz ( matrix  cs,
matrix  z 
)

Converts S-parameter noise correlation matrix to impedance noise correlation matrix.

According to [7] fig 2:

\[ C_z=(I+Z)C_s(I+Z)^+ \]

Where $C_s$ is the scattering noise correlation matrix, $C_z$ the impedance noise correlation matrix, $I$ the identity matrix and $S$ the scattering matrix of device. $x^+$ is the adjoint of $x$

Warning
cs matrix and y matrix are assumed to be normalized
Parameters
[in]csS parameter noise correlation
[in]zImpedance matrix of device
Returns
Impedance noise correlation matrix
Todo:
cs, z const

Definition at line 1474 of file matrix.cpp.

Here is the call graph for this function:

matrix cytocs ( matrix  cy,
matrix  s 
)

Admittance noise correlation matrix to S-parameter noise correlation matrix.

Converts admittance noise correlation matrix to S-parameter noise correlation matrix. According to [7] fig 2:

\[ C_s=\frac{1}{4}(I+S)C_y(I+S)^+ \]

Where $C_s$ is the scattering noise correlation matrix, $C_y$ the admittance noise correlation matrix, $I$ the identity matrix and $S$ the scattering matrix of device. $x^+$ is the adjoint of $x$

Warning
cy matrix and s matrix are assumed to be normalized
Parameters
[in]cyAdmittance noise correlation
[in]sS parameter matrix of device
Returns
S-parameter noise correlation matrix
Note
Assert compatiblity of matrix
Todo:
cy s const

Definition at line 1395 of file matrix.cpp.

Here is the call graph for this function:

matrix cytocz ( matrix  cy,
matrix  z 
)

Converts admittance noise correlation matrix to impedance noise correlation matrix.

According to [7] fig 2:

\[ C_z=ZC_yZ^+ \]

Where $C_z$ is the impedance correlation matrix, $I$ the identity matrix and $C_y$ the admittance noise correlation matrix. $x^+$ is the adjoint of $x$

Warning
cy matrix and z matrix are assumed to be normalized
Parameters
[in]cyAdmittance noise correlation
[in]zImpedance matrix of device
Returns
Impedance noise correlation matrix
Todo:
cs, z const

Definition at line 1522 of file matrix.cpp.

Here is the call graph for this function:

matrix cztocs ( matrix  cz,
matrix  s 
)

Converts impedance noise correlation matrix to S-parameter noise correlation matrix.

According to [7] fig 2:

\[ C_s=\frac{1}{4}(I-S)C_z(I-S) \]

Where $C_s$ is the scattering noise correlation matrix, $C_z$ the impedance noise correlation matrix, $I$ the identity matrix and $S$ the scattering matrix of device. $x^+$ is the adjoint of $x$

Warning
Cz matrix and s matrix are assumed to be normalized
Parameters
[in]czImpedance noise correlation
[in]sS parameter matrix of device
Returns
S-parameter noise correlation matrix
Note
Assert compatiblity of matrix
Todo:
cz, s const

Definition at line 1448 of file matrix.cpp.

Here is the call graph for this function:

matrix cztocy ( matrix  cz,
matrix  y 
)

Converts impedance noise correlation matrix to admittance noise correlation matrix.

According to [7] fig 2:

\[ C_y=YC_zY^+ \]

Where $C_z$ is the impedance correlation matrix, $I$ the identity matrix and $C_y$ the admittance noise correlation matrix. $x^+$ is the adjoint of $x$

Warning
cz matrix and y matrix are assumed to be normalized
Parameters
[in]czimpedance noise correlation
[in]yAdmittance matrix of device
Returns
admittance noise correlation matrix
Todo:
cs, y const

Definition at line 1498 of file matrix.cpp.

Here is the call graph for this function:

matrix dB ( matrix  a)

Computes magnitude in dB of each matrix element.

Parameters
[in]amatrix

Definition at line 540 of file matrix.cpp.

Here is the call graph for this function:

nr_complex_t det ( matrix  a)

Compute determinant of the given matrix.

Parameters
[in]amatrix
Returns
Complex determinant
Todo:
a const?

Definition at line 753 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nr_complex_t detGauss ( matrix  a)

Compute determinant Gaussian algorithm.

Compute determinant of the given matrix using the Gaussian algorithm. This means to triangulate the matrix and multiply all the diagonal elements.

Parameters
[in]amatrix
Note
assert square matrix
Todo:

static ?

a const?

Definition at line 708 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nr_complex_t detLaplace ( matrix  a)

Compute determinant of the given matrix using Laplace expansion.

The Laplace expansion of the determinant of an n by n square matrix a expresses the determinant of a as a sum of n determinants of (n-1) by (n-1) sub-matrices of a. There are 2n such expressions, one for each row and column of a.

See Wikipedia http://en.wikipedia.org/wiki/Laplace_expansion

Parameters
[in]amatrix
Bug:
This algortihm is recursive! Stack overfull!
Note
assert square matrix
Todo:

#ifdef 0

static ?

Definition at line 677 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix diagonal ( vector  diag)

Create a diagonal matrix from a vector.

Parameters
[in]diagvector to write on the diagonal
Todo:
diag is const

Definition at line 615 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix eye ( int  rs,
int  cs 
)

Create identity matrix with specified number of rows and columns.

Parameters
[in]rsrow number
[in]cscolumn number
Todo:

Avoid res.get*

Use memset

rs, cs are const

Definition at line 594 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix eye ( int  s)

Create a square identity matrix.

Parameters
[in]srow or column number of square matrix
Todo:

Do not by lazy and implement it

s is const

Definition at line 607 of file matrix.cpp.

Here is the call graph for this function:

matrix gtos ( matrix  g,
nr_complex_t  z1 = 50.0,
nr_complex_t  z2 = 50.0 
)

Definition at line 1346 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix htos ( matrix  h,
nr_complex_t  z1 = 50.0,
nr_complex_t  z2 = 50.0 
)

Converts hybrid matrix to scattering parameters.

Formulae are given by [5] and are remembered here:

\begin{align*} S_{11}&=\frac{(h_{11}-Z_{01}^*)(1+h_{22}Z_{02})-h_{12}h_{21}Z_{02}} {\Delta}\\ S_{12}&=\frac{-2h_{12}(\Re\text{e}\;Z_{01}\Re\text{e}\;Z_{02})^\frac{1}{2}} {\Delta}\\ S_{21}&=\frac{-2h_{21}(\Re\text{e}\;Z_{01}\Re\text{e}\;Z_{02})^\frac{1}{2}} {\Delta}\\ S_{22}&=\frac{(h_{11}+Z_{01})(1-h_{22}Z_{02}^*)-h_{12}h_{21}Z_{02}^*} {\Delta} \end{align*}

Where $\Delta$ is:

\[ \Delta=(Z_{01}+h_{11})(1+h_{22}Z_{02})-h_{12}h_{21}Z_{02} \]

Parameters
[in]hhybrid matrix
[in]z1impedance at input 1
[in]z2impedance at input 2
Returns
scattering matrix
Note
Assert 2 by 2 matrix
Todo:
Why not h,z1,z2 const

Definition at line 1298 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix imag ( matrix  a)

Imaginary part matrix.

Parameters
[in]amatrix
Todo:

add imag in place

a is const

Definition at line 579 of file matrix.cpp.

Here is the call graph for this function:

matrix inverse ( matrix  a)

Compute inverse matrix.

Parameters
[in]amatrix to invert
Todo:
a is const

Definition at line 838 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix inverseGaussJordan ( matrix  a)

Compute inverse matrix using Gauss-Jordan elimination.

Compute inverse matrix of the given matrix by Gauss-Jordan elimination.

Todo:

a const?

static?

Note
assert non singulat matix
Parameters
[in]amatrix to invert

Definition at line 789 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix inverseLaplace ( matrix  a)

Compute inverse matrix using Laplace expansion.

Compute inverse matrix of the given matrix using Laplace expansion.

Parameters
[in]amatrix to invert
Todo:

Static?

#ifdef 0

Bug:
recursive! Stack overflow
Todo:
a const?

Definition at line 770 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix operator* ( matrix  a,
nr_complex_t  z 
)

Matrix scaling complex version.

Parameters
[in]amatrix to scale
[in]zscaling complex
Returns
Scaled matrix
Todo:
Why not a and z const

Definition at line 296 of file matrix.cpp.

Here is the call graph for this function:

matrix operator* ( nr_complex_t  z,
matrix  a 
)

Matrix scaling complex version (different order)

Parameters
[in]amatrix to scale
[in]zscaling complex
Returns
Scaled matrix
Todo:

Why not a and z const

Why not inline

Definition at line 311 of file matrix.cpp.

matrix operator* ( matrix  a,
nr_double_t  d 
)

Matrix scaling complex version.

Parameters
[in]amatrix to scale
[in]dscaling real
Returns
Scaled matrix
Todo:
Why not d and a const

Definition at line 321 of file matrix.cpp.

Here is the call graph for this function:

matrix operator* ( nr_double_t  d,
matrix  a 
)

Matrix scaling real version (different order)

Parameters
[in]amatrix to scale
[in]dscaling real
Returns
Scaled matrix
Todo:

Why not inline?

Why not d and a const

Definition at line 336 of file matrix.cpp.

matrix operator* ( matrix  a,
matrix  b 
)

Matrix multiplication.

Dumb and not optimized matrix multiplication

Parameters
a]first matrix
b]second matrix
Note
assert compatibility
Todo:
a and b are const

Definition at line 376 of file matrix.cpp.

Here is the call graph for this function:

matrix operator+ ( matrix  a,
matrix  b 
)

Matrix addition.

Parameters
a]first matrix
b]second matrix
Note
assert same size
Todo:
a and b are const

Definition at line 226 of file matrix.cpp.

Here is the call graph for this function:

matrix operator+ ( matrix  a,
nr_complex_t  z 
)

Complex scalar addition.

Parameters
[in]amatrix
[in]zcomplex to add
Todo:

Move near other +

a and z are const

Definition at line 397 of file matrix.cpp.

Here is the call graph for this function:

matrix operator+ ( nr_complex_t  z,
matrix  a 
)

Complex scalar addition different order.

Parameters
[in]amatrix
[in]zcomplex to add
Todo:

Move near other +

a and z are const

Why not inline

Definition at line 412 of file matrix.cpp.

matrix operator+ ( matrix  a,
nr_double_t  d 
)

Real scalar addition.

Parameters
[in]amatrix
[in]dreal to add
Todo:

Move near other +

a and d are const

Definition at line 422 of file matrix.cpp.

Here is the call graph for this function:

matrix operator+ ( nr_double_t  d,
matrix  a 
)

Real scalar addition different order.

Parameters
[in]amatrix
[in]dreal to add
Todo:

Move near other +

a and d are const

Why not inline

Definition at line 437 of file matrix.cpp.

matrix operator- ( matrix  a,
matrix  b 
)

Matrix subtraction.

Parameters
a]first matrix
b]second matrix
Note
assert same size
Todo:
a and b are const

Definition at line 257 of file matrix.cpp.

Here is the call graph for this function:

matrix operator- ( matrix  a,
nr_complex_t  z 
)

Complex scalar substraction.

Parameters
[in]amatrix
[in]zcomplex to add
Todo:

Move near other +

a and z are const

Why not inline

Definition at line 448 of file matrix.cpp.

matrix operator- ( nr_complex_t  z,
matrix  a 
)

Complex scalar substraction different order.

Parameters
[in]amatrix
[in]zcomplex to add
Todo:

Move near other +

a and z are const

Why not inline

Definition at line 459 of file matrix.cpp.

matrix operator- ( matrix  a,
nr_double_t  d 
)

Real scalar substraction.

Parameters
[in]amatrix
[in]zreal to add
Todo:

Move near other +

a and z are const

Why not inline

Definition at line 470 of file matrix.cpp.

matrix operator- ( nr_double_t  d,
matrix  a 
)

Real scalar substraction different order.

Parameters
[in]amatrix
[in]zreal to add
Todo:

Move near other +

a and z are const

Why not inline

Definition at line 481 of file matrix.cpp.

matrix operator/ ( matrix  a,
nr_complex_t  z 
)

Matrix scaling division by complex version.

Parameters
[in]amatrix to scale
[in]zscaling complex
Returns
Scaled matrix
Todo:
Why not a and z const

Definition at line 346 of file matrix.cpp.

Here is the call graph for this function:

matrix operator/ ( matrix  a,
nr_double_t  d 
)

Matrix scaling division by real version.

Parameters
[in]amatrix to scale
[in]dscaling real
Returns
Scaled matrix
Todo:
Why not a and d const

Definition at line 360 of file matrix.cpp.

Here is the call graph for this function:

matrix pow ( matrix  a,
int  n 
)

Definition at line 623 of file matrix.cpp.

Here is the call graph for this function:

matrix real ( matrix  a)

Real part matrix.

Parameters
[in]amatrix
Todo:

add real in place

a is const

Definition at line 566 of file matrix.cpp.

Here is the call graph for this function:

matrix stoa ( matrix  s,
nr_complex_t  z1 = 50.0,
nr_complex_t  z2 = 50.0 
)

Converts chain matrix to scattering parameters.

Converts scattering parameters to chain matrix. Formulae are given by [5] tab 1. and are remembered here:

\begin{align*} A&=\frac{(Z_{01}^*+S_{11}Z_{01})(1-S_{22}) +S_{12}S_{21}Z_{01}}{\Delta} \\ B&=\frac{(Z_{01}^*+S_{11}Z_{01})(Z_{02}^*+S_{22}Z_{02}) -S_{12}S_{21}Z_{01}Z_{02}}{\Delta} \\ C&=\frac{(1-S_{11})(1-S_{22}) -S_{12}S_{21}}{\Delta} \\ D&=\frac{(1-S_{11})(Z_{02}^*+S_{22}Z_{02}) +S_{12}S_{21}Z_{02}}{\Delta} \end{align*}

Where:

\[ \Delta = 2 S_{21}\sqrt{\Re\text{e}\;Z_{01}\Re\text{e}\;Z_{02}} \]

Bug:
Do not need fabs
Parameters
[in]sScattering matrix
[in]z1impedance at input 1
[in]z2impedance at input 2
Returns
Chain matrix
Note
Assert 2 by 2 matrix
Todo:
Why not s,z1,z2 const

Definition at line 1172 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix stog ( matrix  s,
nr_complex_t  z1 = 50.0,
nr_complex_t  z2 = 50.0 
)

Definition at line 1322 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix stoh ( matrix  s,
nr_complex_t  z1 = 50.0,
nr_complex_t  z2 = 50.0 
)

Converts scattering parameters to hybrid matrix.

Converts chain matrix to scattering parameters Formulae are given by [5] and are remembered here:

\begin{align*} h_{11}&=\frac{(Z_{01}^*+S_{11}Z_{01}) (Z_{02}^*+S_{22}Z_{02}) -S_{12}S_{21}Z_{01}Z_{02}}{\Delta}\\ h_{12}&=\frac{2S_{12} (\Re\text{e}\;Z_{01} \Re\text{e}\;Z_{02})^\frac{1}{2}} {\Delta} \\ h_{21}&=\frac{-2S_{21} (\Re\text{e}\;Z_{01} \Re\text{e}\;Z_{02})^\frac{1}{2}} {\Delta} \\ h_{22}&=\frac{(1-S_{11})(1-S_{22})-S_{12}S_{21}}{\Delta} \end{align*}

Where $\Delta$ is:

\[ \Delta=(1-S_{11})(Z_{02}^*+S_{22}Z_{02})+S_{12}S_{21}Z_{02} \]

Bug:
{Programmed formulae are valid only for Z real}
Parameters
[in]sScattering matrix
[in]z1impedance at input 1
[in]z2impedance at input 2
Returns
hybrid matrix
Note
Assert 2 by 2 matrix
Todo:
Why not s,z1,z2 const

Definition at line 1260 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix stos ( matrix  s,
vector  zref,
vector  z0 
)

S params to S params.

Convert scattering parameters with the reference impedance 'zref' to scattering parameters with the reference impedance 'z0'.

Detail are given in [1], under equation (32)

New scatering matrix $S'$ is:

\[ S'=A^{-1}(S-\Gamma^+)(I-\Gamma S)^{-1}A^+ \]

Where x^+ is the adjoint (or complex tranposate) of x, I the identity matrix and $A$ is diagonal the matrix such as: $ \Gamma_i= r_i $ and $A$ the diagonal matrix such as:

\[ A_i = \frac{(1-r_i^*)\sqrt{|1-r_ir_i^*|}}{|1-r_i|} \]

Where $x*$ is the complex conjugate of $x$ and $r_i$ is wave reflexion coefficient of $Z_i'$ with respect to $Z_i^*$ (where $Z_i'$ is the new impedance and $Z_i$ is the old impedance), ie:

\[ r_i = \frac{Z_i'-Z_i}{Z_i'-Z_i^*} \]

Parameters
[in]soriginal S matrix
[in]zreforiginal reference impedance
[in]z0new reference impedance
Bug:
This formula is valid only for real z!
Todo:

Correct documentation about standing waves [1-4]

Implement Speciale implementation [2-3] if applicable

Returns
Renormalized scattering matrix
Todo:
s, zref and z0 const

Definition at line 881 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix stos ( matrix  s,
nr_complex_t  zref,
nr_complex_t  z0 = 50.0 
)

S renormalization with all part identic.

Parameters
[in]soriginal S matrix
[in]zreforiginal reference impedance
[in]z0new reference impedance
Todo:
Why not inline
Returns
Renormalized scattering matrix
Todo:
s, zref and z0 const

Definition at line 901 of file matrix.cpp.

Here is the call graph for this function:

matrix stos ( matrix  s,
nr_double_t  zref,
nr_double_t  z0 = 50.0 
)

S renormalization with all part identic and real.

Parameters
[in]soriginal S matrix
[in]zreforiginal reference impedance
[in]z0new reference impedance
Todo:
Why not inline
Returns
Renormalized scattering matrix
Todo:
s, zref and z0 const

Definition at line 914 of file matrix.cpp.

Here is the call graph for this function:

matrix stos ( matrix  s,
vector  zref,
nr_complex_t  z0 = 50.0 
)

S renormalization (variation)

Parameters
[in]soriginal S matrix
[in]zreforiginal reference impedance
[in]z0new reference impedance
Todo:
Why not inline
Returns
Renormalized scattering matrix
Todo:
s, zref and z0 const

Definition at line 926 of file matrix.cpp.

Here is the call graph for this function:

matrix stos ( matrix  s,
nr_complex_t  zref,
vector  z0 
)

S renormalization (variation)

Parameters
[in]soriginal S matrix
[in]zreforiginal reference impedance
[in]z0new reference impedance
Todo:

Why not inline

s, zref and z0 const

Returns
Renormalized scattering matrix

Definition at line 938 of file matrix.cpp.

Here is the call graph for this function:

matrix stoy ( matrix  s,
vector  z0 
)

Scattering parameters to admittance matrix.

Convert scattering parameters to admittance matrix. According to [1] eq (19):

\[ Z=F^{-1} (I- S)^{-1} (SG + G^+) F \]

Where $S$ is the scattering matrix, $x^+$ is the adjoint of x, I the identity matrix. The matrix F and G are diagonal matrix defined by:

\begin{align*} F_i&=\frac{1}{2\sqrt{\Re\text{e}\; Z_i}} \\ G_i&=Z_i \end{align*}

Using the well know formula $(AB)^{-1}=B^{1}A^{1}$, we derivate:

\[ Y=F^{-1} (SG+G^+)^{-1} (I-S) F \]

Parameters
[in]sScattering matrix
[in]z0Normalisation impedance
Note
We could safely drop the $1/2$ in $F$ because we compute $FXF^{-1}$ and therefore $1/2$ will simplify.
Bug:
not correct if zref is complex
Todo:
s and z0 const
Returns
Admittance matrix

Definition at line 1073 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix stoy ( matrix  s,
nr_complex_t  z0 = 50.0 
)

Convert scattering pto adminttance parameters identic case.

Parameters
[in]SScattering matrix
[in]z0Normalisation impedance
Returns
Admittance matrix
Todo:

Why not inline

s and z0 const

Definition at line 1092 of file matrix.cpp.

Here is the call graph for this function:

matrix stoz ( matrix  s,
vector  z0 
)

Scattering parameters to impedance matrix.

Convert scattering parameters to impedance matrix. According to [1] eq (19):

\[ Z=F^{-1} (I- S)^{-1} (SG + G^+) F \]

Where $S$ is the scattering matrix, $x^+$ is the adjoint of x, I the identity matrix. The matrix F and G are diagonal matrix defined by:

\begin{align*} F_i&=\frac{1}{2\sqrt{\Re\text{e}\; Z_i}} \\ G_i&=Z_i \end{align*}

Parameters
[in]sScattering matrix
[in]z0Normalisation impedance
Note
We could safely drop the $1/2$ in $F$ because we compute $FXF^{-1}$ and therefore $1/2$ will simplify.
Bug:
not correct if zref is complex
Todo:
s, z0 const
Returns
Impedance matrix

Definition at line 964 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix stoz ( matrix  s,
nr_complex_t  z0 = 50.0 
)

Scattering parameters to impedance matrix identic case.

Parameters
[in]sScattering matrix
[in]z0Normalisation impedance
Returns
Impedance matrix
Todo:

Why not inline?

s and z0 const?

Definition at line 983 of file matrix.cpp.

Here is the call graph for this function:

matrix transpose ( matrix  a)

Matrix transposition.

Parameters
[in]aMatrix to transpose
Todo:

add transpose in place

a is const

Definition at line 490 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix twoport ( matrix  m,
char  in,
char  out 
)

Generic conversion matrix.

This function converts 2x2 matrices from any of the matrix forms Y, Z, H, G and A to any other. Also converts S<->(A, T, H, Y and Z) matrices. Convertion assumed:

Y->Y, Y->Z, Y->H, Y->G, Y->A, Y->S, Z->Y, Z->Z, Z->H, Z->G, Z->A, Z->S, H->Y, H->Z, H->H, H->G, H->A, H->S, G->Y, G->Z, G->H, G->G, G->A, G->S, A->Y, A->Z, A->H, A->G, A->A, A->S, S->Y, S->Z, S->H, S->G, S->A, S->S, S->T,T->T,T->S

Note
assert 2x2 matrix
Parameters
[in]mbase matrix
[in]inmatrix
[in]outmatrix
Returns
matrix given by format out
Todo:
m, in, out const

Definition at line 1585 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix ytos ( matrix  y,
vector  z0 
)

Admittance matrix to scattering parameters.

Convert admittance matrix to scattering parameters. Using the same methodology as [1] eq (16-19), but writing (16) as $i=Yv$, ie

\[ S=F(I-G^+Y)(I-GY)^{-1}F^{-1} \]

Where $S$ is the scattering matrix, $x^+$ is the adjoint of x, I the identity matrix. The matrix F and G are diagonal matrix defined by:

\begin{align*} F_i&=\frac{1}{2\sqrt{\Re\text{e}\; Z_i}} \\ G_i&=Z_i \end{align*}

Using the well know formula $(AB)^{-1}=B^{1}A^{1}$, we derivate:

\[ Y=F^{-1} (SG+G^+)^{-1} (I-S) F \]

Parameters
[in]yadmittance matrix
[in]z0Normalisation impedance
Note
We could safely drop the $1/2$ in $F$ because we compute $FXF^{-1}$ and therefore $1/2$ will simplify.
Bug:
not correct if zref is complex
Todo:
why not y and z0 const
Returns
Scattering matrix

Definition at line 1124 of file matrix.cpp.

Here is the call graph for this function:

matrix ytos ( matrix  y,
nr_complex_t  z0 = 50.0 
)

Convert Admittance matrix to scattering parameters identic case.

Parameters
[in]yAdmittance matrix
[in]z0Normalisation impedance
Returns
Scattering matrix
Todo:

Why not inline

y and z0 const

Definition at line 1142 of file matrix.cpp.

Here is the call graph for this function:

matrix ytoz ( matrix  y)

Convert admittance matrix to impedance matrix.

Convert $Y$ matrix to $Z$ matrix using well known relation $Z=Y^{-1}$

Parameters
[in]yadmittance matrix
Returns
Impedance matrix
Note
Check if y matrix is a square matrix
Todo:

Why not inline

y const

move near ztoy()

Definition at line 1371 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix ztos ( matrix  z,
vector  z0 
)

Convert impedance matrix scattering parameters.

Convert scattering parameters to impedance matrix. According to [1] eq (18):

\[ S=F(Z-G^+)(Z+G)^{-1} F^{-1} \]

Where $Z$ is the scattering matrix, $x^+$ is the adjoint of x, I the identity matrix. The matrix F and G are diagonal matrix defined by:

\begin{align*} F_i&=\frac{1}{2\sqrt{\Re\text{e}\; Z_i}} \\ G_i&=Z_i \end{align*}

Parameters
[in]ZImpedance matrix
[in]z0Normalisation impedance
Returns
Scattering matrix
Note
We could safely drop the $1/2$ in $F$ because we compute $FXF^{-1}$ and therefore $1/2$ will simplify.
Bug:
not correct if zref is complex
Todo:
z and z0 const?

Definition at line 1009 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

matrix ztos ( matrix  z,
nr_complex_t  z0 = 50.0 
)

Convert impedance matrix to scattering parameters identic case.

Parameters
[in]ZImpedance matrix
[in]z0Normalisation impedance
Returns
Scattering matrix
Todo:

Why not inline

z and z0 const

Definition at line 1028 of file matrix.cpp.

Here is the call graph for this function:

matrix ztoy ( matrix  z)

impedance matrix to admittance matrix.

Convert impedance matrix to admittance matrix. By definition $Y=Z^{-1}$

Parameters
[in]zimpedance matrix
Returns
Admittance matrix
Todo:

Why not inline

z const

Definition at line 1041 of file matrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function: