Simplify channel model to account for normalized power

This commit is contained in:
Mattéo Delabre 2019-12-15 19:48:49 -05:00
parent 59d7adf6bd
commit 34cb3b863b
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 7 additions and 6 deletions

View File

@ -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