2019-12-15 04:04:35 +00:00
|
|
|
|
import torch.nn as nn
|
2019-12-16 04:12:00 +00:00
|
|
|
|
from torch.distributions.normal import Normal
|
2019-12-16 00:48:49 +00:00
|
|
|
|
import math
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
class GaussianChannel(nn.Module):
|
2019-12-18 15:26:35 +00:00
|
|
|
|
"""
|
|
|
|
|
Simulated communication channel that assumes a Gaussian noise model for
|
|
|
|
|
taking in account interference.
|
|
|
|
|
"""
|
2019-12-16 04:12:00 +00:00
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
# Initialize channel parameters
|
|
|
|
|
sys_rate = 32e9
|
|
|
|
|
r = 0.05
|
|
|
|
|
dispersion = 16.48e-6
|
|
|
|
|
B_2 = dispersion
|
|
|
|
|
non_linear_index = 1.3e3
|
|
|
|
|
gam = non_linear_index
|
|
|
|
|
loss = 10**20
|
|
|
|
|
alpha = loss
|
|
|
|
|
span_count = 20
|
|
|
|
|
N_s = span_count
|
|
|
|
|
span_length = 10e5 # (km)
|
|
|
|
|
L_s = span_length
|
|
|
|
|
noise_figure = 10 ** 0.5 # (dB)
|
|
|
|
|
h = 6.6261e-34
|
|
|
|
|
v = 299792458
|
|
|
|
|
B_WDM = sys_rate * (1 + r)
|
|
|
|
|
B_N = 0.1
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
P_ASE_1 = h * v * B_N * (loss * span_length * noise_figure - 1)
|
|
|
|
|
P_ASE = P_ASE_1 * span_count
|
|
|
|
|
L_eff = 1 - math.exp(-loss * span_length) / 2 / alpha
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
eps = 0.3 * math.log(
|
|
|
|
|
1 + (6 / L_s) * (
|
|
|
|
|
L_eff / math.asinh(
|
|
|
|
|
(math.pi ** 2)
|
|
|
|
|
/ 3
|
|
|
|
|
* B_2
|
|
|
|
|
* L_eff
|
|
|
|
|
* (B_WDM ** 2)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
b = P_ASE_1 / (
|
|
|
|
|
2
|
|
|
|
|
* (N_s ** eps)
|
|
|
|
|
* B_N
|
|
|
|
|
* (gam ** 2)
|
|
|
|
|
* L_eff * math.asinh(
|
|
|
|
|
(math.pi ** 2) / 3
|
|
|
|
|
* B_2
|
|
|
|
|
* L_eff
|
|
|
|
|
* (B_WDM ** 2)
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
P_ch = sys_rate * (((27 * math.pi * B_2 / 16) * b) ** (1 / 3))
|
|
|
|
|
OSNR = (2 * P_ch / 3 / P_ASE)
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
OSNR_dB = 10 * math.log10(OSNR)
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
p_N_dB = -OSNR_dB
|
|
|
|
|
p_N_watt = 10**(p_N_dB/10)
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
self.noise_std = math.sqrt(p_N_watt * 5000)
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
def get_noise(self, rows):
|
|
|
|
|
"""
|
|
|
|
|
Generate Gaussian random noise according to the channel’s parameters.
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
2019-12-16 04:12:00 +00:00
|
|
|
|
:param rows: Number of noise vectors to generate.
|
|
|
|
|
:return: Matrix of shape `rows` × 2.
|
|
|
|
|
"""
|
|
|
|
|
return Normal(0, self.noise_std).sample((rows, 2))
|
2019-12-15 04:04:35 +00:00
|
|
|
|
|
|
|
|
|
def forward(self, x):
|
2019-12-16 04:12:00 +00:00
|
|
|
|
return x + self.get_noise(len(x))
|