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:
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 NoiseProfile
Returns:
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:

  1. The vector \(\mathbf{f}\) of the spatial frequencies is created.
  2. 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.
  3. 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.
  4. 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

generate_noise()[source]

Function that generates the noise profile.

CorrelatedNoise

class pynumpm.noise.CorrelatedNoise(z=None, offset=0, noise_amplitude=0.0, correlation_length=0.0)[source]

Class to create a correlated noise profile given a correlation length. It inherits from NoiseProfile.

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
  • correlation_length (float) – Parameter describing the correlation length of the noise.

The ith point \(y_i\) of the correlated profile is generated drawing it from the normal distribution with mean \(\rho y_{i-1}\) and variance \(\sigma^2 (1-\rho^2)\), where \(y_{i-1}\) is the previous point of the profile, \(\sigma\) is the amplitude of the noise and \(\rho\) is the correlation factor given by \(\rho = \exp{-\Delta z/L_C}\), being \(\Delta z\) the size of the mesh cell and \(L_C\) the correlation length.

The following block of code initialises and plots the profile of a CorrelatedNoise object:

z = np.linspace(0, 10, 1000)*1e-3
thisnoise = CorrelatedNoise(z=z,
                         noise_amplitude=0.1,
                         offset = 3,
                         profile_spectrum = "1/f")
thisnoise.plot_noise_properties()

Warning

This class hasn’t been tested completely. It might be buggy.

correlation_length

Correlation length of the noise

generate_noise()[source]

Function to generate the noise profile.