[docs]classNoiseRealization(RandomRealization):"""Realization of a noise model"""__power:floatdef__init__(self,noise:NoiseModel,power:float)->None:""" Args: noise (Noise): Noise model to be realized. power (float): Power indicator of the noise model. """# Validate attributesifpower<0:raiseValueError("Noise power of a noise realization must be non-negative.")# Initialize base classRandomRealization.__init__(self,noise)# Initialize attributesself.__power=power@propertydefpower(self)->float:"""Power of the noise realization. Returns: Power in Watt. """returnself.__power
[docs]@abstractmethoddefadd_to(self,signal:Signal)->Signal:""" Args: signal (Signal): The signal to which the noise should be added. Returns: Signal model with added noise. """...# pragma: no cover
NRT=TypeVar("NRT",bound=NoiseRealization)"""Type of noise realization"""
[docs]classNoiseModel(RandomNode,Generic[NRT]):"""Noise modeling base class."""def__init__(self,seed:int|None=None)->None:""" Args: seed (int, optional): Random seed for initializating the pseud-random number generator. """RandomNode.__init__(self,seed=seed)
[docs]@abstractmethoddefrealize(self,power:float)->NRT:"""Realize the noise model. Args: power (float, optional): Power of the added noise in Watt. Returns: Noise model realization. """...# pragma: no cover
[docs]defadd_noise(self,signal:Signal,power:float)->Signal:"""Add noise to a signal model. Args: signal (Signal): The signal to which the noise should be added. power (float): Power of the added noise in Watt. Returns: Signal model with added noise. """realization=self.realize(power)returnrealization.add_to(signal)
[docs]classAWGNRealization(NoiseRealization):"""Realization of additive white Gaussian noise"""
[docs]defadd_to(self,signal:Signal)->Signal:# Create random number generatorrng=self.generator()noise_samples=(0.5*self.power)**0.5*(rng.standard_normal(signal.shape)+1j*rng.standard_normal(signal.shape))noisy_signal=signal.copy()forblockinnoisy_signal:block+=noise_samplesnoisy_signal.noise_power=self.powerreturnnoisy_signal
[docs]classAWGN(Serializable,NoiseModel[AWGNRealization]):"""Additive White Gaussian Noise."""yaml_tag="AWGN"property_blacklist={"random_mother"}def__init__(self,seed:int|None=None)->None:""" Args: seed (int, optional): Random seed for initializating the pseud-random number generator. """NoiseModel.__init__(self,seed=seed)