| 1 |
""" |
| 2 |
.. currentmodule:: skrf.media.device |
| 3 |
|
| 4 |
======================================== |
| 5 |
device (:mod:`skrf.media.device`) |
| 6 |
======================================== |
| 7 |
|
| 8 |
Device is a generic n-port microwave device class to create common Network. |
| 9 |
|
| 10 |
Device Class |
| 11 |
--------------- |
| 12 |
.. autosummary:: |
| 13 |
:toctree: generated/ |
| 14 |
|
| 15 |
Device |
| 16 |
|
| 17 |
Example Devices |
| 18 |
--------------- |
| 19 |
.. autosummary:: |
| 20 |
:toctree: generated/ |
| 21 |
|
| 22 |
MatchedSymmetricCoupler |
| 23 |
Hybrid |
| 24 |
QuadratureHybrid |
| 25 |
Hybrid180 |
| 26 |
DualCoupler |
| 27 |
|
| 28 |
""" |
| 29 |
|
| 30 |
|
| 31 |
from abc import ABCMeta, abstractproperty |
| 32 |
|
| 33 |
import numpy as np |
| 34 |
from numpy import exp, sqrt |
| 35 |
|
| 36 |
from .. import mathFunctions as mf |
| 37 |
from ..network import connect |
| 38 |
|
| 39 |
|
| 40 |
class Device: |
| 41 |
""" |
| 42 |
A n-port microwave device |
| 43 |
|
| 44 |
Parameters |
| 45 |
----------- |
| 46 |
media : skrf.media.Media |
| 47 |
""" |
| 48 |
__metaclass__ = ABCMeta |
| 49 |
|
| 50 |
def __init__(self, media): |
| 51 |
self.media = media |
| 52 |
|
| 53 |
@abstractproperty |
| 54 |
def ntwk(self): |
| 55 |
""" |
| 56 |
the network representation of a given device |
| 57 |
""" |
| 58 |
return None |
| 59 |
|
| 60 |
|
| 61 |
class MatchedSymmetricCoupler(Device): |
| 62 |
""" |
| 63 |
A Matched Symmetric Coupler |
| 64 |
|
| 65 |
The resultant ntwk port assignment is as follows: |
| 66 |
* 0 - insertion |
| 67 |
* 1 - transmit |
| 68 |
* 2 - coupled |
| 69 |
* 3 - isolated |
| 70 |
""" |
| 71 |
def __init__(self, media, c=None, t=None, t_phase=0, phase_diff=0, |
| 72 |
nports=4, *args, **kw): |
| 73 |
Device.__init__(self, media=media, **kw) |
| 74 |
|
| 75 |
if c is None and t is None: |
| 76 |
raise ValueError('Must pass either `c` or `t`') |
| 77 |
|
| 78 |
if nports not in [3,4]: |
| 79 |
raise ValueError('nports must be 3 or 4') |
| 80 |
|
| 81 |
self.phase_diff = phase_diff |
| 82 |
self.t_phase = t_phase |
| 83 |
self.i = 0 |
| 84 |
self.nports=nports |
| 85 |
|
| 86 |
|
| 87 |
if c is not None: |
| 88 |
self.c = c |
| 89 |
|
| 90 |
if t is not None: |
| 91 |
self.t = t |
| 92 |
|
| 93 |
|
| 94 |
@classmethod |
| 95 |
def from_dbdeg(cls, media, db, deg=0, *args,**kw): |
| 96 |
r""" |
| 97 |
Create a coupler in terms of couping(dB) and phase offset(deg) |
| 98 |
|
| 99 |
Parameters |
| 100 |
----------- |
| 101 |
media : skrf.media.Media Object |
| 102 |
|
| 103 |
db : number or array-like |
| 104 |
the magnitude of the coupling value (in dB), sign dont matter |
| 105 |
deg : number or array-like |
| 106 |
phase offset between the transmit and coupled arms. defined |
| 107 |
as : coupled arm = transmit arm +phase offset |
| 108 |
\*args,\*\*kw: passed to self.__init__() |
| 109 |
|
| 110 |
""" |
| 111 |
c = mf.db_2_mag(-1*abs(db)) |
| 112 |
return cls(media=media, c=c, phase_diff=deg, **kw) |
| 113 |
|
| 114 |
@property |
| 115 |
def c(self): |
| 116 |
return self._c |
| 117 |
|
| 118 |
@c.setter |
| 119 |
def c(self,c): |
| 120 |
self._c = c |
| 121 |
t_rad = mf.degree_2_radian(self.t_phase) |
| 122 |
c_rad = t_rad + mf.degree_2_radian(self.phase_diff) |
| 123 |
|
| 124 |
self._t = np.sqrt(1- np.abs(c)**2)*exp(1j*t_rad) |
| 125 |
self._c = c*exp(1j*c_rad) |
| 126 |
|
| 127 |
@property |
| 128 |
def t(self): |
| 129 |
return self._t |
| 130 |
|
| 131 |
@t.setter |
| 132 |
def t(self,t): |
| 133 |
t_rad = mf.degree_2_radian(self.t_phase) |
| 134 |
c_rad = t_rad + mf.degree_2_radian(self.phase_diff) |
| 135 |
self._t= t*exp(1j*t_rad) |
| 136 |
self._c = np.sqrt(1- np.abs(t)**2)*exp(1j*c_rad) |
| 137 |
|
| 138 |
|
| 139 |
@property |
| 140 |
def ntwk(self): |
| 141 |
a = self.media.match(nports=4) |
| 142 |
a.s[:,0,1] = a.s[:,1,0] = a.s[:,3,2] = a.s[:,2,3] = self.t |
| 143 |
a.s[:,0,2] = a.s[:,2,0] = a.s[:,3,1] = a.s[:,1,3] = self.c |
| 144 |
a.s[:,0,3] = a.s[:,3,0] = a.s[:,1,2] = a.s[:,2,1] = self.i |
| 145 |
if self.nports ==3: |
| 146 |
match = self.media.match() |
| 147 |
a = connect(a,3,match,0) |
| 148 |
return a |
| 149 |
|
| 150 |
|
| 151 |
class Hybrid(MatchedSymmetricCoupler): |
| 152 |
""" |
| 153 |
A 3dB Coupler of given phase difference |
| 154 |
""" |
| 155 |
def __init__(self, media, t_phase=180,phase_diff=0, *args, **kw): |
| 156 |
c = 1/sqrt(2) |
| 157 |
MatchedSymmetricCoupler.__init__(self,media=media, c=c, |
| 158 |
phase_diff=phase_diff, |
| 159 |
t_phase=t_phase,**kw) |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
class QuadratureHybrid(MatchedSymmetricCoupler): |
| 164 |
""" |
| 165 |
A 3dB Coupler with 90deg phase diff between transmit and coupled arms |
| 166 |
""" |
| 167 |
def __init__(self, media,t_phase=0, *args, **kw): |
| 168 |
c = 1/sqrt(2) |
| 169 |
MatchedSymmetricCoupler.__init__(self,media=media,c=c,t_phase=t_phase, |
| 170 |
phase_diff=-90, **kw) |
| 171 |
|
| 172 |
|
| 173 |
class Hybrid180(Device): |
| 174 |
""" |
| 175 |
180degree hybrid |
| 176 |
|
| 177 |
This device can be used to combine two signals in and out of phase, |
| 178 |
or as a divider, with outputs in or out of phase. |
| 179 |
|
| 180 |
The resultant ntwk port assignment is as follows: |
| 181 |
* 0 - sum (A+B) |
| 182 |
* 1 - input A |
| 183 |
* 2 - input B |
| 184 |
* 3 - delta (A-B) |
| 185 |
|
| 186 |
|
| 187 |
http://www.microwaves101.com/encyclopedias/hybrid-couplers |
| 188 |
""" |
| 189 |
def __init__(self, media, nports=4, *args, **kw): |
| 190 |
Device.__init__(self, media=media, **kw) |
| 191 |
self.nports = nports |
| 192 |
@property |
| 193 |
def ntwk(self): |
| 194 |
a = self.media.match(nports=4) |
| 195 |
for m,n in [(0,1),(1,0),(2,0),(0,2),(3,2),(2,3)]: |
| 196 |
a.s[:,m,n]=-1j |
| 197 |
for m,n in [(3,1),(1,3)]: |
| 198 |
a.s[:,m,n]=1j |
| 199 |
|
| 200 |
a.s = a.s*1/sqrt(2) |
| 201 |
if self.nports ==3: |
| 202 |
match = self.media.match() |
| 203 |
a = connect(a,3,match,0) |
| 204 |
return a |
| 205 |
|
| 206 |
class DualCoupler(Device): |
| 207 |
""" |
| 208 |
Pair of back-to-back directional couplers |
| 209 |
|
| 210 |
Ports are as follows: |
| 211 |
* 0 : insertion of coupler 1 |
| 212 |
* 1 : insertion on coupler 2 |
| 213 |
* 2 : coupled on coupler 1 |
| 214 |
* 3 : coupled on coupler 2 |
| 215 |
""" |
| 216 |
def __init__(self, media, c1=1/sqrt(2), c2=None, c1kw=None,c2kw=None): |
| 217 |
if c2kw is None: |
| 218 |
c2kw = {} |
| 219 |
if c1kw is None: |
| 220 |
c1kw = {} |
| 221 |
Device.__init__(self,media=media) |
| 222 |
if c2 is None: |
| 223 |
c2= c1 |
| 224 |
self.c1 = MatchedSymmetricCoupler(media=media,c=c1,nports=3,**c1kw) |
| 225 |
self.c2 = MatchedSymmetricCoupler(media=media,c=c2,nports=3,**c2kw) |
| 226 |
|
| 227 |
@property |
| 228 |
def ntwk(self): |
| 229 |
c1ntwk = self.c1.ntwk |
| 230 |
c2ntwk = self.c2.ntwk |
| 231 |
ntwk = connect(c1ntwk,1,c2ntwk,1) |
| 232 |
ntwk.renumber([0,1,2,3],[0,2,1,3]) |
| 233 |
return ntwk |