Noise module¶
This module contains the functions to generate noise profiles for the waveguides.
-
pynumpm.noise.calculate_profile_properties(z: numpy.ndarray = None, profile: numpy.ndarray = None)[source]¶ Function to calculate the noise properties (autocorrelation and power density spectrum) a user-defined profile.
Parameters: - z (numpy.ndarray) – z mesh of the system
- profile (numpy.ndarray) – Profile of the varying variable of the waveguide.
Returns: z_autocorr, autocorrelation, f, power_spectrum: Returns the autocorrelation profile (z axis included) and the power spectrum (frequency and power)
NoiseProfile¶
-
class
pynumpm.noise.NoiseProfile(z: numpy.ndarray = None, noise_amplitude: float = 0.0, offset: float = 0.0)[source]¶ Base class to define a generic noise profile.
Initialize the noise object passing a numpy array containing the mesh along z, the noise amplitude and an offset. It generates a random profile, where each point is drawn from a normal distribution with mean offset and standard deviation noise_amplitude.
Parameters: - z (numpy.ndarray) – linearly spaced space mesh [meter].
- noise_amplitude (float) – Amplitude of the noise profile.
- offset (float) – Offset of the noise profile
The following block of code initialises and plots the profile of a NoiseProfile:
z = np.linspace(0, 10, 1000)*1e-3 thisnoise = NoiseProfile(z=z, noise_amplitude=0.1, offset = 3) thisnoise.plot_noise_properties()
Note
This class has its own __add__ method, allowing one to sum the effects of two noise profiles, if their dimensions match.
-
length¶ Length of the structure
-
z¶ Z-mesh used to discretise the profile
-
dz¶ Discretisation unit cell.
-
profile¶ Profile of the structure.
-
noise_amplitude¶ Noise amplitude of the noise profile.
-
offset¶ Offset of the noise profile.
-
concatenate(other)[source]¶ Method to concatenate two noise tracks.
Warning
This method has not been tested completely.
Parameters: other ( pynumpm.NoiseProfile) – Another instance of a NoiseProfileReturns:
-
load_noise_profile(noise_profile: numpy.ndarray)[source]¶ Method used to load a user-generated noise profile.
Parameters: noise_profile (numpy.ndarray) – Array containing the noise profile
-
plot_noise_properties(fig=None, **plotkwargs)[source]¶ Function to plot the noise properties.
Parameters: - fig – Figure handle, if the plot needs to be in a specific figure
- plotkwargs – Dictionary of properties to be passed to the plotting functions. This can be used e.g. to define the colours and the size of the lines
Returns: fig, [ax1, ax2, ax3]. The handles to the figure object and the three axes of the figure.
NoiseFromSpectrum¶
-
class
pynumpm.noise.NoiseFromSpectrum(z: numpy.ndarray = None, offset: float = 0, noise_amplitude: float = 0.0, profile_spectrum: str = None)[source]¶ Class to create a noise profile given a specific noise power spectrum. It inherits from NoiseProfile. It can create Additive White Gaussian Noise (awgn), 1/f noise and 1/f2 noise.
Initialize the noise object passing a numpy array containing the mesh along z, the noise amplitude, an offset and a string describing the power spectrum of the noise.
Parameters: - z (numpy.ndarray) – linearly spaced space mesh [meter].
- noise_amplitude (float) – Amplitude of the noise profile.
- offset (float) – Offset of the noise profile
- profile_spectrum (str) – Noise profile of the simulated structure. Can be one of “awgn”, “1/f”, “1/f2”.
The noise profile is generated on the basis of the profile spectrum with the following algorithm:
- The vector \(\mathbf{f}\) of the spatial frequencies is created.
- The respective coefficients \(\mathbf{c}\) are generated according to \(\mathbf{c} = \mathbf{f}^{-\gamma}\), where \(\gamma\) is equal to 0, 1, 2 for AWGN, 1/f and 1/f2 noise.
- A random phase is then sampled for each coefficient \(c_k\) in \(\mathbf{c}\). The phase of \(c_{-k}\) is opposite to the phase of \(c_k\) to ensure a real-valued noise.
- The IFFT of \(\mathbf{c}\) is calculated to retrieve the spectral distribution of the noise. If necessary, an offset is added at the end.
The following block of code initialises and plots the profile of a NoiseFromSpectrum object:
z = np.linspace(0, 10, 1000)*1e-3 thisnoise = NoiseFromSpectrum(z=z, noise_amplitude=0.1, offset = 3, profile_spectrum = "1/f") thisnoise.plot_noise_properties()
-
profile_spectrum¶ Type of noise spectrum of the structure