diff --git a/constellation/GaussianChannel.py b/constellation/GaussianChannel.py index 09638d7..4efc083 100644 --- a/constellation/GaussianChannel.py +++ b/constellation/GaussianChannel.py @@ -1,5 +1,6 @@ import torch.nn as nn import torch +import math import numpy as np @@ -44,24 +45,24 @@ def Const_Points_Pow(IQ): return p_enc_avg_dB -def Pow_Noise(CH_OSNR, CPP): +def Pow_Noise(CH_OSNR): """ Calculate the power of channel noise. """ - P_N_dB = CPP - CH_OSNR + P_N_dB = -CH_OSNR p_N_watt = 10**(P_N_dB/10) Var_Noise = p_N_watt return Var_Noise -def Channel_Noise_Model(NV, S): +def Channel_Noise_Model(variance, shape): """ Compute the Gaussian noise to be added to each vector to simulate passing through a channel. """ return torch.distributions.normal.Normal( - 0, torch.sqrt(NV*10000) - ).sample(S) + 0, math.sqrt(variance * 5000) + ).sample(shape) class GaussianChannel(nn.Module): @@ -69,6 +70,6 @@ class GaussianChannel(nn.Module): super().__init__() def forward(self, x): - Noise_Variance = Pow_Noise(channel_OSNR(), Const_Points_Pow(x)) + Noise_Variance = Pow_Noise(channel_OSNR()) Noise_Volts = Channel_Noise_Model(Noise_Variance, [len(x), 2]) return x + Noise_Volts