thztools.NoiseModel#
- class thztools.NoiseModel(sigma_alpha, sigma_beta, sigma_tau, dt=None)[source]#
Dataclass to describe the time-domain noise model.
For noise parameters \(\sigma_\alpha\), \(\sigma_\beta\), \(\sigma_\tau\) and signal vector \(\boldsymbol{\mu}\), the \(k\)-th element of the time-domain noise variance vector \(\boldsymbol{\sigma}^2\) is given by [1]
\[\sigma_k^2 = \sigma_\alpha^2 + \sigma_\beta^2\mu_k^2 \ + \sigma_\tau^2(\mathbf{D}\boldsymbol{\mu})_k^2,\]where \(\mathbf{D}\) is the time-domain derivative operator.
- Parameters:
- sigma_alphafloat
Additive noise amplitude.
- sigma_betafloat
Multiplicative noise amplitude.
- sigma_taufloat
Timebase noise amplitude.
- dtfloat or None, optional
Sampling time, normally in picoseconds. Default is None, which sets the sampling time to
thztools.options.sampling_time
. If bothdt
andthztools.get_option("sampling_time")
areNone
, thesigma_tau
parameter is given in units of the sampling time.
Attributes
sigma_alpha
(float) Additive noise amplitude.
sigma_beta
(float) Multiplicative noise amplitude.
sigma_tau
(float) Timebase noise amplitude.
dt
(float or None, optional) Sampling time, normally in picoseconds. Default is None, which sets the sampling time to
thztools.options.sampling_time
. If bothdt
andthztools.get_option("sampling_time")
areNone
, thesigma_tau
parameter is given in units of the sampling time.Methods
noise_amp
(x, *[, axis])Compute the time-domain noise amplitude.
noise_sim
(x, *[, axis, seed])Simulate time-domain noise.
noise_var
(x, *[, axis])Compute the time-domain noise variance.
- Warns:
- UserWarning
If
thztools.options.sampling_time
and thedt
parameter are both notNone
and are set to differentfloat
values, the function will set the sampling time todt
and raise aUserWarning
.
See also
noisefit
Estimate noise model parameters.
References
[1]Laleh Mohtashemi, Paul Westlund, Derek G. Sahota, Graham B. Lea, Ian Bushfield, Payam Mousavi, and J. Steven Dodge, “Maximum- likelihood parameter estimation in terahertz time-domain spectroscopy,” Opt. Express 29, 4912-4926 (2021), https://doi.org/10.1364/OE.417724.
Examples
The following example shows the noise variance \(\sigma^2(t)\) for noise parameters \(\sigma_\alpha = 10^{-4}\), \(\sigma_\beta = 10^{-2}\), \(\sigma_\tau = 10^{-3}\) and the simulated signal \(\mu(t)\). The signal amplitude is normalized to its peak magnitude, \(\mu_0\). The noise variance is normalized to \((\sigma_\beta\mu_0)^2\).
>>> import thztools as thz >>> from matplotlib import pyplot as plt >>> n, dt = 256, 0.05 >>> t = thz.timebase(n, dt=dt) >>> mu = thz.wave(n) >>> alpha, beta, tau = 1e-4, 1e-2, 1e-3 >>> noise_model = thz.NoiseModel(sigma_alpha=alpha, sigma_beta=beta, ... sigma_tau=tau, dt=dt) >>> noise_variance = noise_model.noise_var(mu)
>>> _, axs = plt.subplots(2, 1, sharex=True, layout="constrained") >>> axs[0].plot(t, noise_variance / beta**2) >>> axs[0].set_ylabel(r"$\sigma^2/(\sigma_\beta\mu_0)^2$") >>> axs[1].plot(t, mu) >>> axs[1].set_ylabel(r"$\mu/\mu_0$") >>> axs[1].set_xlabel("t (ps)") >>> plt.show()