Note
This page was generated from a Jupyter Notebook. Download the notebook (.ipynb)
[1]:
# Skipped in CI: Colab/bootstrap dependency install cell.
Signal Extraction: Weak Signal Recovery from Colored Noise๏
This case study promotes the legacy weak-signal notebook into the public gallery. The core physics question is how to recover a narrowband signal whose amplitude is far below the raw time-domain noise.
The workflow is: simulate a weak injected tone, identify it spectrally, isolate it with a band-pass filter, and fit a compact sinusoidal model.
Related API: Time Series API, Signal API
Related theory: Validated Algorithms, Numerical Stability
[2]:
import matplotlib.pyplot as plt
import numpy as np
from gwexpy import TimeSeries
duration = 32
sample_rate = 4096
signal_freq = 123.4
signal_amp = 0.5
noise_std = 5.0
t = np.linspace(0, duration, int(duration * sample_rate), endpoint=False)
# The injected tone is far below the broadband noise floor, which is why it disappears in the raw waveform.
noise = np.random.normal(0, noise_std, size=len(t))
clean_signal = signal_amp * np.sin(2 * np.pi * signal_freq * t)
ts = TimeSeries(noise + clean_signal, t0=0, sample_rate=sample_rate, name="Noisy Data", unit="V")
1. Find the candidate frequency band๏
ASD averaging reduces estimator variance so the narrowband tone can emerge as a statistically visible line even when the time-domain waveform looks noise dominated.
[3]:
plot = ts.plot()
plot.gca().set_xlim(0, 0.1)
plot.gca().set_title("Raw Time Series (Zoomed)")
plt.show()
asd = ts.asd(fftlength=4, method="welch")
plot = asd.plot()
plot.gca().set_xlim(10, 1000)
plot.gca().set_yscale("log")
plot.gca().set_title("ASD")
plt.show()
2. Filter and fit the recovered signal๏
The band-pass is chosen to keep the injected line while rejecting unrelated broadband power. Making the band too narrow or too wide would respectively distort the tone or let too much noise back in.
Related API: Time Series API, Fitting API
Related theory: Validated Algorithms
[4]:
# Keep the band around the detected line so the fit sees the signal-dominated portion of the data.
filtered_ts = ts.bandpass(110, 130).crop(1, 1.1)
plot = filtered_ts.plot()
plot.gca().set_title("Band-passed TimeSeries")
plt.show()
def sine_model(t, amp, freq, phase, amp2, freq2, phase2):
return amp * np.sin(2 * np.pi * freq * t + phase) * (1 + amp2 * np.sin(2 * np.pi * freq2 * t + phase2))
p0 = {"amp": 0.5, "freq": 123, "phase": 0, "amp2": 0.05, "freq2": 10, "phase2": 0}
limits = {"freq": (110, 130), "amp": (0.1, 5), "amp2": (0, 0.2), "freq2": (0, 50)}
result = filtered_ts.fit(sine_model, p0=p0, limits=limits, sigma=0.01)
print(result)
result.plot()
plt.show()
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Migrad โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ FCN = 3.241e+05 (ฯยฒ/ndof = 802.2)โ Nfcn = 420 โ
โ EDM = 3.68e-07 (Goal: 0.0002) โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Valid Minimum โ Below EDM threshold (goal x 10) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ SOME parameters at limit โ Below call limit โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Hesse ok โ Covariance accurate โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโฌโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโ
โ โ Name โ Value โ Hesse Err โ Minos Err- โ Minos Err+ โ Limit- โ Limit+ โ Fixed โ
โโโโโผโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโค
โ 0 โ amp โ 224.7e-3 โ 0.7e-3 โ โ โ 0.1 โ 5 โ โ
โ 1 โ freq โ 120.966 โ 0.017 โ โ โ 110 โ 130 โ โ
โ 2 โ phase โ 10.83 โ 0.11 โ โ โ โ โ โ
โ 3 โ amp2 โ200.000e-3 โ 0.004e-3 โ โ โ 0 โ 0.2 โ โ
โ 4 โ freq2 โ 9.35 โ 0.04 โ โ โ 0 โ 50 โ โ
โ 5 โ phase2 โ 5.19 โ 0.24 โ โ โ โ โ โ
โโโโโดโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโ
โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ amp freq phase amp2 freq2 phase2 โ
โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ amp โ 5.04e-07 -0.2e-6 1.4e-6 -161.87e-18 -5.1e-6 33.8e-6 โ
โ freq โ -0.2e-6 0.000292 -1.86e-3 -41.40e-18 -0.02e-3 0.14e-3 โ
โ phase โ 1.4e-6 -1.86e-3 0.0119 274.33e-18 0.0001 -0.001 โ
โ amp2 โ -161.87e-18 -41.40e-18 274.33e-18 2.93e-19 1.74137e-15 -11.43654e-15 โ
โ freq2 โ -5.1e-6 -0.02e-3 0.0001 1.74137e-15 0.00132 -0.0086 โ
โ phase2 โ 33.8e-6 0.14e-3 -0.001 -11.43654e-15 -0.0086 0.0566 โ
โโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ