gwadama.synthetic#

class gwadama.synthetic.NonwhiteGaussianNoise(*, duration: float, psd: Callable | ndarray[Any, dtype[_ScalarType_co]], fs: int, rng: Generator, freq_cutoff: int = 0)[source]#

Bases: object

Simulate non-white gaussian noise.

¡¡¡OLD VERSION FROM MASTER’S THESIS!!! (Tweaked)

TODO: Implement SNR and injection methods into BaseInjected instead, and use the PSD array-callable conversions from there (newer). Leave here the methods needed only for generating the synthetic noise. This will also make easier to integrate other noise scenarios, such as real noise.

I changed several things: - Now the PSD argument can be either a function or an array.

Attributes:
noise: NDArray
duration: float

Duration of the noise in seconds.

psd: function

Interpolant of PSD(f). If the instance is initialized with a realization of the PSD (an array) its original value can be accessed through the attribute ‘_psd’.

fs: int
f_nyquist: int

Nyquist frequency.

rng: numpy.random.Generator

Methods

inject(x, *, snr[, snr_lim, pos, normed])

Add the simulated noise to the signal 'x'.

rescale(x, *, snr)

Rescale the signal 'x' to the given snr w.r.t.

snr(x)

Compute the Signal to Noise Ratio.

__init__(*, duration: float, psd: Callable | ndarray[Any, dtype[_ScalarType_co]], fs: int, rng: Generator, freq_cutoff: int = 0)[source]#

Initialises the noise instance.

Parameters:
duration: float

Duration of noise to be generated, in seconds. It may change after genetarting the noise, depending on its sampling frequency.

psd: function | NDArray

Power Spectral Density of the non-white part of the noise. If NDArray, will be used to create a quadratic spline interpolant, assuming shape (2, psd_length):

psd[0] = frequency samples psd[1] = psd samples

fs: int

Sampling frequency of the signal.

freq_lowcut: int, optional

Low cut-off frequency to apply when computing noise in frequency space.

rng: numpy.random.Generator
inject(x, *, snr, snr_lim=None, pos=0, normed=False)[source]#

Add the simulated noise to the signal ‘x’.

Parameters:
xarray

Signal array. Its length must be lower or equal to the length of the noise array.

snrint or float, optional

Signal to Noise Ratio. Defaults to 1.

snr_limtuple, optional

Limits in ‘x’ where to calculate the SNR.

posint, optional

Index position in the noise array where to inject the signal. 0 by default.

normedboolean, optional

Normalize ‘x’ to its maximum amplitude after adding the noise. False by default.

Returns:
noisyarray

Signal array with noise at the desired SNR.

scalefloat

Coefficient used to rescale the signal.

rescale(x, *, snr)[source]#

Rescale the signal ‘x’ to the given snr w.r.t. the PSD.

Parameters:
xarray

Signal array.

snrint or float, optional

Signal to Noise Ratio. Defaults to 1.

Returns:
x_newfloat

Rescaled signal.

snr(x)[source]#

Compute the Signal to Noise Ratio.

Due to the legacy code state, I need to compute a sample of the PSD first, because in some old applications the self._psd may have values outside the valid frequency band. TODO: Currently the PSD is being interpolated twice (here and in fat.snr). Try to simplify it by passing here directly self._psd, but be sure to avoid the possible issue mentioned before.

gwadama.synthetic.gaussian_waveform(times: ndarray[Any, dtype[_ScalarType_co]], *, t0: float, hrss: float, duration: float, amp_threshold: float) ndarray[source]#

Generate a Gaussian-like waveform.

Parameters:
times: NDArray

Time samples.

t0: float

Time of the peak.

hrss: float

Root sum squared amplitude of the wave. REF: (2015) Powell J, Trifirò D, Cuoco E, Heng I S and Cavaglià M,

Class. Quantum Grav. 32 215012.

duration: float

In seconds.

amp_threshold: float

Fraction w.r.t. the maximum absolute amplitude of the wave where to consider the amplitude of the wave zero. Here is used to compute the effective duration of the wave.

gwadama.synthetic.ring_down_waveform(times: ndarray[Any, dtype[_ScalarType_co]], *, t0: float, f0: float, Q: float, hrss: float) ndarray[source]#

Generate a Sine-Gaussian-like waveform.

This waveform has its peak at the beginning. In order to synchronise it with other waveforms which have their peak at the center, it is recommended to use the ‘t0’ parameter.

Parameters:
times: NDArray

Time samples.

t0: float

Time of the peak.

f0: float

Central frequency.

Q: float

Quality factor of the wave.

hrss: float

Root sum squared amplitude of the wave. REF: (2015) Powell J, Trifirò D, Cuoco E, Heng I S and Cavaglià M,

Class. Quantum Grav. 32 215012.

gwadama.synthetic.sine_gaussian_waveform(times: ndarray[Any, dtype[_ScalarType_co]], *, t0: float, f0: float, Q: float, hrss: float) ndarray[source]#

Generate a Sine-Gaussian-like waveform.

Parameters:
times: NDArray

Time samples.

t0: float

Time of the peak.

f0: float

Central frequency.

Q: float

Quality factor of the wave.

hrss: float

Root sum squared amplitude of the wave. REF: (2015) Powell J, Trifirò D, Cuoco E, Heng I S and Cavaglià M,

Class. Quantum Grav. 32 215012.