sage.dsp.welch

Filename : welch.py Description : Short description of the file

Created on 2026-01-20 12:42:08

__author__ = Narenraju Nagarajan __copyright__ = Copyright 2026, ProjectName __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __affiliation__ = N/A __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]

GitHub Repository: NULL

Documentation: NULL

Classes

ScipyWelch

Welch PSD estimator wrapping scipy.signal.welch().

TorchWelch

Welch PSD estimator using PyTorch (CPU-friendly).

Module Contents

class ScipyWelch(sample_rate, nperseg_in_seconds=4.0, average='median', detrend='constant', window='hann', scaling='density')[source]

Welch PSD estimator wrapping scipy.signal.welch().

Provides a consistent interface for estimating the one-sided power spectral density of a 1D time series using Welch’s overlapping-segment method. Suitable for offline PSD computation during the data-preparation stage (not used inside the training loop).

Parameters:
  • sample_rate (float) – Sampling rate in Hz.

  • nperseg_in_seconds (float) – Welch segment length in seconds (default 4.0 s).

  • average (str) – Segment averaging method — "mean" or "median" (default).

  • detrend (str or None) – Detrending applied to each segment (default "constant").

  • window (str) – Window function name (default "hann").

  • scaling (str) – "density" (V²/Hz, default) or "spectrum" (V²).

:param : :type : param sample_rate: Sampling rate in Hz :param : :type : param nperseg_in_seconds: Segment length in seconds :param : :type : param average: ‘mean’ or ‘median’ :param : :type : param detrend: Detrending method :param : :type : param window: Window function :param : :type : param scaling: ‘density’ or ‘spectrum’

sample_rate[source]
nperseg_in_seconds = 4.0[source]
average = 'median'[source]
detrend = 'constant'[source]
window = 'hann'[source]
scaling = 'density'[source]
nperseg[source]
class TorchWelch(delta_t=1.0 / 2048, seg_len=4096, seg_stride=2048, window='hann', avg_method='median', require_exact_data_fit=False, minimum_segments=None)[source]

Welch PSD estimator using PyTorch (CPU-friendly).

Designed for a single time series per call. Returns PSD in frequency domain. Refer: https://pycbc.org/pycbc/latest/html/_modules/pycbc/psd/estimate.html

Parameters:
  • delta_t (float)

  • seg_len (int)

  • seg_stride (int)

  • window (str)

  • avg_method (str)

  • require_exact_data_fit (bool)

  • minimum_segments (int)

delta_t[source]

Sampling interval (seconds)

seg_len[source]

Segment length (samples)

seg_stride[source]

Stride between segments (samples)

window

Window type (‘hann’) or torch tensor

avg_method[source]

‘mean’, ‘median’, ‘median-mean’

require_exact_data_fit[source]

if True, enforce exact segment fit

minimum_segments[source]

minimum number of segments required

delta_t = 0.00048828125[source]
seg_len = 4096[source]
seg_stride = 2048[source]
avg_method = 'median'[source]
require_exact_data_fit = False[source]
minimum_segments = None[source]
delta_f = 0.5[source]
freqs[source]