Skip to content

Commit bd0ec5a

Browse files
committed
Incorporate beam splitting into CMRR
1 parent 18f68c6 commit bd0ec5a

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

simphony/simulation.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
nprect = np.vectorize(rect)
3232

3333

34+
def from_db(x: float, factor: int = 10) -> float:
35+
"""Converts a dB value to a linear value."""
36+
return 10 ** (x / factor)
37+
38+
39+
def to_db(x: float, factor: int = 10) -> float:
40+
"""Converts a linear value to a dB value."""
41+
return factor * np.log10(x)
42+
43+
3444
class Simulation:
3545
"""This class instantiates a simulation context.
3646
@@ -406,7 +416,7 @@ def __init__(
406416
self._coupled_powers = np.array([])
407417
self._freqs = np.array([freq if freq else wl2freq(wl)])
408418
self._powers = np.array([power])
409-
self.coupling_ratio = 10 ** (-np.abs(coupling_loss) / 10)
419+
self.coupling_ratio = from_db(-np.abs(coupling_loss))
410420
self.freqs = np.array([])
411421
self.index = 0
412422
self.phase = phase
@@ -437,11 +447,7 @@ def get_rin(self, bandwidth: float) -> float:
437447
bandwidth :
438448
The bandwidth of the detector in Hz.
439449
"""
440-
return (
441-
0
442-
if self.rin == -np.inf
443-
else 10 * np.log10((10 ** (self.rin / 10)) * bandwidth)
444-
)
450+
return 0 if self.rin == -np.inf else to_db(from_db(self.rin) * bandwidth)
445451

446452
def get_rin_dist(self, i: int, j: int) -> List[float]:
447453
"""Returns the normal distribution used for the i,j key. If this is the
@@ -557,7 +563,7 @@ def _detect(self, power: List[np.ndarray]) -> List[np.ndarray]:
557563

558564
# calculate the standard deviation of the RIN noise
559565
std = (
560-
10 ** ((10 * np.log10(power[i][j][0]) + rin) / 20)
566+
from_db(to_db(power[i][j][0]) + rin, 20)
561567
if power[i][j][0]
562568
else 0
563569
)
@@ -715,21 +721,28 @@ def _detect(self, powers: List[np.ndarray]) -> List[np.ndarray]:
715721
rf_rin = source.get_rin(self._get_rf_bandwidth()[0])
716722
dist = source.get_rin_dist(i, j)
717723

724+
# if the two powers are different, we need to adjust
725+
# the CMRR to account for the difference
726+
cmrr = self.rf_cmrr
727+
sum = p1[i][j][0] + p2[i][j][0]
728+
diff = np.abs(p1[i][j][0] - p2[i][j][0])
729+
if diff:
730+
cmrr2 = -to_db(sum / diff)
731+
cmrr = to_db(
732+
np.sqrt(from_db(cmrr) ** 2 + from_db(cmrr2) ** 2)
733+
)
734+
718735
# only calculate the noise if there is power
719736
if p1[i][j][0] > 0:
720-
p1db = 10 * np.log10(p1[i][j][0])
721-
monitor_noise1 += (10 ** ((p1db + monitor_rin) / 20)) * dist
722-
rf_noise1 += (
723-
10 ** ((p1db + rf_rin + self.rf_cmrr) / 20)
724-
) * dist
737+
p1db = to_db(p1[i][j][0])
738+
monitor_noise1 += from_db(p1db + monitor_rin, 20) * dist
739+
rf_noise1 += from_db(p1db + rf_rin + cmrr, 20) * dist
725740

726741
# only calculate the noise if there is power
727742
if p2[i][j][0] > 0:
728-
p2db = 10 * np.log10(p2[i][j][0])
729-
monitor_noise2 += (10 ** ((p2db + monitor_rin) / 20)) * dist
730-
rf_noise2 += (
731-
10 ** ((p2db + rf_rin + self.rf_cmrr) / 20)
732-
) * dist
743+
p2db = to_db(p2[i][j][0])
744+
monitor_noise2 += from_db(p2db + monitor_rin, 20) * dist
745+
rf_noise2 += from_db(p2db + rf_rin + cmrr, 20) * dist
733746

734747
# store the RIN noise for later use
735748
self.monitor_rin_dists1[i][j] = monitor_noise1

0 commit comments

Comments
 (0)