[docs]classDbConversionType(Enum):"""Supported db conversion types."""POWER=0AMPLITUDE=1
[docs]@jit(nopython=True)defdb2lin(db_val:float,conversion_type:Optional[DbConversionType]=DbConversionType.POWER):# pragma: no cover""" Converts from dB to linear Args: db_val (float): value in dB conversion_type (DbConversionType, optional): if POWER then it converts from dB to a power ratio if AMPLITUDE, then it converts from dB to an amplitude ratio default = POWER Returns: (float): the equivalent value in linear scale """ifconversion_type==DbConversionType.POWER:output=10**(db_val/10)elifconversion_type==DbConversionType.AMPLITUDE:output=10**(db_val/20)else:raiseValueError("dB conversion type not supported")returnoutput
[docs]@jit(nopython=True)deflin2db(val:float,conversion_type:Optional[DbConversionType]=DbConversionType.POWER):# pragma: no cover""" Converts from linear to dB Args: val (float): value in linear scale conversion_type (DbConversionType, optional): if POWER then it converts from a power ratio to dB if AMPLITUDE, then it converts from an amplitude ratio to dB default = POWER Returns: (float) the equivalent value in linear scale """ifconversion_type==DbConversionType.POWER:output=10*np.log10(val)elifconversion_type==DbConversionType.AMPLITUDE:output=20*np.log10(val)else:raiseValueError("dB conversion type not supported")returnoutput
[docs]defmarcum_q(a:float,b:np.ndarray,m:Optional[float]=1):"""Calculates the Marcum-Q function Q_m(a, b) This method uses the relationship between Marcum-Q function and the chi-squared distribution. Args: a (float): b (np.array): m (float): Returns: (np.ndarray): the approximated Marcum-Q function for the desired parameters """q=stats.ncx2.sf(b**2,2*m,a**2)returnq
[docs]@jit(nopython=True)defrms_value(x:np.ndarray)->float:# pragma: no cover"""Returns the root-mean-square value of a given input vector"""returnnp.linalg.norm(x,2)/np.sqrt(x.size)
[docs]defamplitude_path_loss(carrier_frequency:float,distance:float)->float:"""Compute the free space propagation loss of a wave in vacuum. Args: carrier_frequency (float): The wave's carrier frequency in Hz. distance (float): The traveled distance in m. Raises: ValueError: If the absolute value of `carrier_frequency` is zero. """absolute_carrier=abs(carrier_frequency)ifabsolute_carrier==0.0:raiseValueError("Carrier frequency may not be zero for free space propagation path loss modeling")# Note that the wavelength factor referes to the effective antenna aperture, so technically it's not part of the propagation losswavelength=speed_of_light/absolute_carrieramplitude_scale=wavelength/(4*np.pi*distance)returnamplitude_scale