mwavepy is an object-oriented approach to microwave engineering, implemented in the Python programming language. It provides a set of objects and features which can be used to build powerful solutions to specific problems. mwavepy’s abilities are; touchstone file manipulation, calibration, VNA data acquisition, circuit design and much more.
This is the main module file for mwavepy. it simply imports classes and methods. It does this in two ways; import all into the current namespace, and import modules themselves for coherent structured referencing
Holds pre-initialized class’s to provide convenience. Also provides some functions, which cant be categorized as anything better than general conviniencies.
- Pre-initialized classes include:
- Frequency Objects for standard frequency bands Media objects for standard waveguide bands,
find nearest value in array. taken from http://stackoverflow.com/questions/2566412/find-nearest-value-in-numpy-array
find nearest value in array. taken from http://stackoverflow.com/questions/2566412/find-nearest-value-in-numpy-array
turn off the legend for a given axes. if no axes is given then it will use current axes.
plots a complex array or list in real vs imaginary.
Provides the Frequency class, and related functions
Bases: object
represents a frequency band.
start: starting frequency (in Hz) stop: stoping frequency (in Hz) npoints: number of points, an int unit: unit which to scale a formated axis, when accesssed. see
formattedAxis
frequently many calcluations are made in a given band , so this class is used in other classes so user doesnt have to continually supply frequency info.
returns a frequency vector in Hz
returns a frequency vector in units of self.unit
alternative constructor from a frequency vector, takes:
f: frequency array (default in Hz)
multiplier for formating axis
The unit to format the frequency axis in. see formatedAxis
angular frequency in radians
convienience function converts a frequency vector to a Frequency object
!depricated, use classmethod from_f instead.
Provides commonly used math functions.
returns the magnitude in dB of a complex number.
where z is a complex number
returns the angle complex number in radians.
returns the magnitude of a complex number.
takes a complex number and returns quadrature, which is (length, arc-length from real axis)
returns the angle complex number in radians.
break up a complex array into all possible scalar components
takes: complex ndarray return:
c_real: real part c_imag: imaginary part c_angle: angle in degrees c_mag: magnitude c_arc: arclength from real axis, angle*magnitude
converts db to normal magnitude
where z is a complex number
converts a value in nepers to dB
the dirac function.
can take numpy arrays or numbers returns 1 or 0
converts magnitude to db
- db is given by
- 20*log10(|z|)
where z is a complex number
neumans number
2-dirac_delta(x)
converts a value in dB to neper’s
calculates the null space of matrix A.
i found this on stack overflow.
convert a one sided complex spectrum into a real time-signal. takes
f: frequency array, y: complex PSD arary windowType: windowing function, defaults to rect
timeVector is in inverse units of the input variable f, if spectrum is not baseband then, timeSignal is modulated by
exp(t*2*pi*f[0])
so keep in mind units, also due to this f must be increasing left to right
Provides the Network class and related functions.
Bases: object
Represents a n-port microwave network.
z0: characteristic impedance f: frequency vector in Hz. see also frequency, which is a
Frequency object (see help on this class for more info)
various other network properties are accesable as well as plotting routines are also defined for convenience,
most properties are derived from the specifications given for touchstone files.
adds a complex zero-mean gaussian white-noise signal of given standard deviations for magnitude and phase
adds a flatband complex zero-mean gaussian white-noise signal of given standard deviations for magnitude and phase
the frequency vector for the network, in Hz.
swaps the ports of a two port
returns a Frequency object, see frequency.py
calculates an interpolated network. defualt interpolation type is linear. see notes about other interpolation types
a network representing inverse s-parameters, for de-embeding
multiplys a complex bivariate gaussian white-noise signal of given standard deviations for magnitude and phase. magnitude mean is 1, phase mean is 0
perturb s-parameters by small amount. this is usefule to work-around numerical bugs. takes:
amount: amount to add to s parameters
the number of ports the network has.
passivity metric for a multi-port network. It returns
a matrix who’s diagonals are equal to the total power received at all ports, normalized to the power at a single excitement port.
mathmatically, this is a test for unitary-ness of the s-parameter matrix.
where H is conjugate transpose of S, and * is dot product
note: see more at, http://en.wikipedia.org/wiki/Scattering_parameters#Lossless_networks
generic plotting function for plotting a Network’s attribute in polar form
takes:
plots all s parameters in log magnitude
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the scattering parameter of indecies m, n on complex plane
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the magnitude of the scattering parameter of indecies m, n in log magnitude
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the phase of a scattering parameter of indecies m, n in degrees
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the phase of a scattering parameter of indecies m, n in unwrapped degrees
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the phase of a scattering parameter of indecies m, n in unwrapped degrees
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the magnitude of a scattering parameter of indecies m, n not in magnitude
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the scattering parameter of indecies m, n in polar form
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the phase of a scattering parameter of indecies m, n in radians
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the phase of a scattering parameter of indecies m, n in unwrapped radians
m - first index, int n - second indext, int ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not *args,**kwargs - passed to the matplotlib.plot command
plots the scattering parameter of indecies m, n on smith chart
m - first index, int n - second indext, int r - radius of smith chart ax - matplotlib.axes object to plot on, used in case you
want to update an existing plot.
show_legend: boolean, to turn legend show legend of not chart_type: string determining countour type. options are:
‘z’: impedance contours (default) ‘y’: admittance contours
*args,**kwargs - passed to the matplotlib.plot command
generic plotting function for plotting a Network’s attribute vs frequency.
takes:
loads values from a touchstone file.
The scattering parameter matrix.
s-matrix has shape fxnxn, where;
f is frequency axis and, n’s are port indicies
returns the phase of the s-parameters, in radians
returns the unwrapped phase of the s-paramerts, in degrees
returns the magnitude of the s-parameters.
returns the phase of the s-parameters, in radians.
returns the unwrapped phase of the s-parameters, in radians.
returns the t-parameters, which are also known as wave cascading matrix.
write a touchstone file representing this network. the only format supported at the moment is :
HZ S RI
the characteristic impedance of the network.
z0 can be may be a number, or numpy.ndarray of shape n or fxn.
calculates the average network from a list of Networks. this is complex average of the s-parameters for a list of Networks
DEPRECATED. see connect_s() instead.
cascade two s-matricies together.
a’s port 2 == b’s port 1
if you want a different port configuration use the flip() fuction takes:
a: a 2x2 or kx2x2 s-matrix b: a 2x2, kx2x2, 1x1, or kx1x1 s-matrix
connect two n-port networks together. specifically, connect port ‘k’ on ntwkA to port ‘l’ on ntwkB. The resultant network has (ntwkA.nports+ntwkB.nports -2) ports. The port index’s (‘k’,’l’) start from 0. Port impedances are taken into account.
S-parameter connection algorithm.
the effect of mis-matched port impedances is handled by inserting
a 2-port ‘mismatch’ network between the two connected ports.
connect two n-port networks together. specifically, connect port ‘k’ on network ‘S’ to port ‘l’ on network ‘T’. The resultant network has (S.rank + T.rank-2)-ports
and calls the innerconnect() function. see that function for more details about the implementation
converts a csv file saved from a Rhode swarz and possibly other
de-embed a 2x2 s-matrix from another 2x2 s-matrix
c = b**-1 * a
invert the ports of a networks s-matrix, ‘flipping’ it over
Applies a function to some attribute of aa list of networks, and returns the result in the form of a Network. This means information that may not be s-parameters is stored in the s-matrix of the returned Network.
Applies a function to some attribute of aa list of networks, and returns the result in the form of a Network. This means information that may not be s-parameters is stored in the s-matrix of the returned Network.
returns a two-port network for a impedance mis-match
connect two ports of a single n-port network, resulting in a (n-2)-port network. port indecies start from 0.
S-parameter connection algorithm.
connect two ports of a single n-port network, resulting in a (n-2)-port network.
inverse s-parameters, used for de-embeding
loads all touchtone files in a given dir
dir - the path to the dir, passed as a string (defalut is cwd) contains - string which filename must contain to be loaded, not
used if None.(default None)
calculates the two-port network given a symetric, reciprocal and lossless one-port network.
plots mean value with +- uncertainty bounds in an Network attribute, for a list of Networks.
if your list_of_networks is for a calibrated short, then the
std dev of deg_unwrap might blow up, because even though each network is unwrapped, they may fall on either side fo the pi relative to one another.
see plot_uncertainty_bounds for help
see plot_uncertainty_bounds for help
converts a scattering parameters to ‘wave cascading parameters’
input matrix shape should be should be 2x2, or kx2x2
BUG: if s -matrix has ones for reflection, thsi will produce inf’s you cant cascade a matrix like this anyway, but we should handle it better
converts a ‘wave cascading parameters’ to scattering parameters
input matrix shape should be should be 2x2, or kx2x2
example: to use a working band to create a two-port reflective standard from two one-port standards
my_media= ... two_port_reflect(my_media.short(), my_media.match())
writes a dictionary of networks to a given directory
provides plotting functions, which dont belong to any class.
plots the smith chart of a given radius takes:
smithR - radius of smith chart chart_type: string representing contour type: acceptable values are
‘z’: lines of constant impedance ‘y’: lines of constant admittanceax - matplotlib.axes instance
transmission line theory related functions
reflection coefficient at electrical length theta takes:
Gamma0: reflection coefficient at theta=0 theta: electrical length, (may be complex)
calculates the input impedance at electrical length theta, given a reflection coefficient and characterisitc impedance of the medium takes:
z0 - characteristic impedance. Gamma: reflection coefficient theta: electrical length of the line, (may be complex)
calculates the input impedance given a reflection coefficient and characterisitc impedance of the medium takes:
Gamma: reflection coefficient z0 - characteristic impedance.
calculates the electrical length of a section of transmission line.
l: length of line. in meters f: frequency at which to calculate. [array-like or float]. deg: return in degrees or not. [boolean].
converts complex distributed impedance and admittance to propagation constant and characteristic impedance.
calculates the electrical length of a section of transmission line.
l: length of line. in meters f: frequency at which to calculate. [array-like or float]. deg: return in degrees or not. [boolean].
convert electrical length to a physical distance.
note: the gamma function must take a single variable, that is frequency and return complex propagation constant such that the propagating part is positive imag part.
calculates the reflection coefficient for a given input impedance takes:
zl: input (load) impedance [number of array]. z0 - characteristic impedance[number of array].
input impedance of load impedance zl at electrical length theta, given characteristic impedance z0.
converts complex propagation constant and characteristic impedance to distributed impedance and admittance.
calculates the input impedance given a reflection coefficient and characterisitc impedance of the medium takes:
Gamma: reflection coefficient z0 - characteristic impedance.
calculates the input impedance at electrical length theta, given a reflection coefficient and characterisitc impedance of the medium takes:
z0 - characteristic impedance. Gamma: reflection coefficient theta: electrical length of the line, (may be complex)
reflection coefficient at electrical length theta takes:
Gamma0: reflection coefficient at theta=0 theta: electrical length, (may be complex)
the skin depth for a material. see www.microwaves101.com for more info.
surface resistivity. see www.microwaves101.com for more info.
calculates the electrical length of a section of transmission line.
l: length of line. in meters f: frequency at which to calculate. [array-like or float]. deg: return in degrees or not. [boolean].
calculates the reflection coefficient for a given input impedance takes:
zl: input (load) impedance [number of array]. z0 - characteristic impedance[number of array].
input impedance of load impedance zl at electrical length theta, given characteristic impedance z0.
contains touchstone class ( written by Werner Hoch )
class to read touchstone s-parameter files The reference for writing this class is the draft of the Touchstone(R) File Format Specification Rev 2.0 http://www.eda-stds.org/ibis/adhoc/interconnect/touchstone_spec2_draft.pdf
returns the file format string used for the given format. This is usefull to get some informations.
TODO: NIY
TODO: NIY
returns the sparameters as a tuple of arrays, where the first element is the frequency vector (in Hz) and the s-parameters are a 3d numpy array. The values of the sparameters are complex number. usage:
f,a = self.sgetparameter_arrays() s11 = a[:,0,0]
get the data of the sparameter with the given format. supported formats are:
orig: unmodified s-parameter data ri: data in real/imaginary ma: data in magnitude and angle (degree) db: data in log magnitute and angle (degree)
Returns a list of numpy.arrays
generate a list of column names for the s-parameter data The names are different for each format. posible format parameters:
ri, ma, db, orig (where orig refers to one of the three others)
returns a list of strings.
Load the touchstone file into the interal data structures