gwadama.synthetic#

class gwadama.synthetic.NonwhiteGaussianNoise(*, duration, psd, sample_rate, rng, freq_cutoff=0)[source]#

Bases: object

Simulate non-white gaussian noise.

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

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’.

sample_rate: 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, psd, sample_rate, rng, freq_cutoff=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 sample 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

sample_rate: int

Sample frequency of the signal.

random_seed: int or 1-d array_like

Seed for numpy.random.RandomState.

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. But in the future I plan to make it so that it can take both a PSD estimation function or an array realization like I did here.

gwadama.synthetic.gaussian_waveform(times: ndarray, *, 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, *, 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, *, 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.