Skip to content

Commit

Permalink
Merge pull request #3 from jhillairet/circuit_update_networks
Browse files Browse the repository at this point in the history
Circuit update networks
  • Loading branch information
jhillairet authored Jan 3, 2025
2 parents 0bc3cc5 + 560a3bc commit 44fbca2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies = [
"matplotlib>=3.9.2",
"networkx>=3.4.2",
"numpy>=2.1.3",
"scikit-rf>=1.4.1",
"scikit-rf>=1.3.0",
"tqdm>=4.67.0",
]

Expand Down
59 changes: 42 additions & 17 deletions west_ic_antenna/antenna.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def capa(
Bridge side characteristic impedance in [Ohm].
The default is bridge z0.
z0_antenna : float, optional
Antenna side charactetistic impedance in [Ohm].
Antenna side characteristic impedance in [Ohm].
The default is the antenna z0
name : str, optional
capacitor Network name. Default is 'capa'.
Expand Down Expand Up @@ -290,36 +290,56 @@ def capa(

return capa

def _antenna_circuit(self, Cs: NumberLike) -> "rf.Circuit":
def _capacitors(self, Cs: NumberLike) -> List["rf.Network"]:
"""
Antenna scikit-rf Circuit.
Create the four capacitor Networks
Parameters
----------
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]
Cs : list or array or None
antenna 4 capacitances [C1, C2, C3, C4] in [pF].
Default is None (use internal Cs).
Returns
-------
circuit: :class:`skrf.circuit.Circuit`
Antenna Circuit
C1_ntw, C2_ntw, C3_ntw, C4_ntw : rf.Network
capacitor networks
"""
C1, C2, C3, C4 = Cs
# left side
capa_C1 = self.capa(
C1_ntw = self.capa(
C1, z0_bridge=self.bridge_left.z0[0][1], z0_antenna=self.antenna.z0[0][0], name="C1"
)
capa_C2 = self.capa(
C2_ntw = self.capa(
C2, z0_bridge=self.bridge_left.z0[0][2], z0_antenna=self.antenna.z0[0][2], name="C2"
)
# right side
capa_C3 = self.capa(
C3_ntw = self.capa(
C3, z0_bridge=self.bridge_right.z0[0][1], z0_antenna=self.antenna.z0[0][1], name="C3"
)
capa_C4 = self.capa(
C4_ntw = self.capa(
C4, z0_bridge=self.bridge_right.z0[0][2], z0_antenna=self.antenna.z0[0][3], name="C4"
)
return C1_ntw, C2_ntw, C3_ntw, C4_ntw

def _antenna_circuit(self, Cs: NumberLike) -> "rf.Circuit":
"""
Antenna scikit-rf Circuit.
Parameters
----------
Cs : list or array
antenna 4 capacitances [C1, C2, C3, C4] in [pF]
Returns
-------
circuit: :class:`skrf.circuit.Circuit`
Antenna Circuit
"""
# capacitor Networks
capa_C1, capa_C2, capa_C3, capa_C4 = self._capacitors(Cs)

# WARNING !
# antenna port numbering convention does not follow capa and voltage :
Expand Down Expand Up @@ -389,7 +409,12 @@ def circuit(self, Cs: Union[List, None] = None) -> "Circuit":
"""
Cs = Cs or self.Cs
self._circuit = self._antenna_circuit(Cs)
if not hasattr(self, '_circuit'):
# Create full circuit
self._circuit = self._antenna_circuit(Cs)
else:
# Update only the capacitors Networks to speed up
self._circuit = self._circuit.update_networks(self._capacitors(Cs))
return self._circuit

def _optim_fun_one_side(
Expand Down Expand Up @@ -472,10 +497,10 @@ def _optim_fun_both_sides(
"""
Optimisation function to match both antenna sides.
Optimization is made for active Z parameters, that is taking into
Optimisation is made for active Z parameters, that is taking into
account the antenna excitation.
The residual used for the optimization is calculated as:
The residual used for the optimisation is calculated as:
.. math::
Expand Down Expand Up @@ -527,7 +552,7 @@ def match_one_side(
decimals: Union[int, None] = None,
) -> NumberLike:
"""
Search best capacitance to match the specified side of the antenna.
Search the best capacitance to match the specified side of the antenna.
Capacitance of the non-matched side are set to 120 [pF].
Expand Down Expand Up @@ -689,9 +714,9 @@ def match_both_sides(
power : list or array
Input power at external ports in Watts [W]. Default is [1, 1] W.
phase : list or array
Input phase at external ports in radian [rad]. Defalt is dipole [0, pi] rad.
Input phase at external ports in radian [rad]. Default is dipole [0, pi] rad.
method : str, optional
Scipy Optimization mathod. 'SLSQP' (default) or 'COBYLA'
Scipy Optimization method. 'SLSQP' (default) or 'COBYLA'
C0 : list or None, optional
Initial guess of the matching point. If None, the initial guess
is obtained from matching both sides separately. Default is None.
Expand Down

0 comments on commit 44fbca2

Please sign in to comment.