sage.dsp.whiten
Filename : whiten.py Description : Short description of the file
Created on 2026-01-19 16:26:37
__author__ = Narenraju Nagarajan __copyright__ = Copyright 2026, Sage __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]
GitHub Repository: NULL
Documentation: NULL
Classes
Whiten frequency-domain strain using fixed, detector-specific fiducial PSDs. |
Module Contents
- class FiducialWhitening(**kwargs)[source]
Bases:
torch.nn.ModuleWhiten frequency-domain strain using fixed, detector-specific fiducial PSDs.
The whitening kernel is derived once from pre-computed fiducial ASDs and stored as a registered buffer so it moves to the correct device automatically and is included in
torch.compilegraphs.Pipeline (per sample)
Multiply FD strain by the whitening kernel:
X_white = X_fd * whiteningwherewhitening[d, f] = 2 Δf / (√0.5 · ASD[d, f]).Convert back to time domain via inverse real FFT.
Strip the corrupted edge samples introduced by the Welch PSD estimation window (
padding_nsampleson each side).
The
@torch.no_grad()decorator onforward()means this module severs the autograd graph. Adversarial perturbations or any gradient-based optimisation must therefore operate on the output of this module, not on its FD input.- param **kwargs:
Forwarded to
nn.Module.__init__.
- whitening
Per-detector, per-frequency whitening kernel (registered buffer).
- Type:
torch.Tensor, shape
(D, F)
- Input / Output
- --------------
- Initialize internal Module state, shared by both nn.Module and ScriptModule.
- remove_corrupted(x)[source]
Strip edge samples corrupted by the Welch PSD estimation window.
- Parameters:
x (torch.Tensor, shape
(B, D, T)) – Whitened time-domain strain (full length, including corrupted ends).- Returns:
Valid central samples only.
- Return type:
torch.Tensor, shape
(B, D, T - 2 * corrupted_len)
- forward(input)[source]
Whiten frequency-domain strain.
Accepts either a raw tensor (legacy path) or a
GWBatch(state-tracked path). The behaviour depends on the grid type:FD_UNIFORM — whiten → IFFT → strip corrupted edges → return
GWBatchwithTD_UNIFORMstate (real float32, shape(B, D, T_valid)).FD_COARSE — whiten at the coarse frequency indices using
batch.coarse_indices→ returnGWBatchwithFD_COARSEwhitened state (complex, shape(B, D, N_coarse)). No IFFT is applied — the non-uniform grid cannot be IFFTed.Raw tensor (no GWBatch) — treated as FD_UNIFORM and the raw whitened TD tensor is returned for backward compatibility.
- Parameters:
input (torch.Tensor or GWBatch) – FD strain
(B, D, F)complex, or a GWBatch wrapping it.- Returns:
GWBatch when input is a GWBatch; raw float32 tensor otherwise.
- Return type: