spectral_connectivity.transforms.Welch#
- class Welch(time_series: ndarray[tuple[int, ...], dtype[floating]], sampling_frequency: float, segment_duration: float | None = None, segment_overlap: float = 0.5, n_time_samples_per_segment: int | None = None, detrend_type: str | None = 'constant', start_time: float = 0, n_fft_samples: int | None = None, fft_workers: int | None = None)[source]#
Bases:
objectWelch spectral transform using overlapping Hann-windowed segments.
Segment coefficients are represented on the taper/observation axis, so the default
trials_tapersexpectation averages both trials and Welch segments and returns a single spectrum centered on the analyzed record.- Parameters:
time_series (ndarray, shape (n_time_samples, n_trials, n_signals)) – Input signals. Use
prepare_time_series()for 1-D/2-D input.sampling_frequency (float) – Samples per second; required because it labels the frequency axis and scales power.
segment_duration (float, optional) – Segment length in seconds; sets the frequency resolution (
1 / segment_durationHz). Strongly recommended – the fallback of 256 samples does not scale with the sampling rate. Give this orn_time_samples_per_segment.segment_overlap (float, default=0.5) – Fractional overlap between successive segments, in
[0, 1).n_time_samples_per_segment (int, optional) – Segment length in samples (alternative to
segment_duration).detrend_type ({"constant", "linear"} or None, default="constant") – Detrending applied to each segment before the FFT.
start_time (float, default=0) – Time of the first sample, in seconds (scalar only).
n_fft_samples (int, optional) – FFT length. Defaults to
scipy.fft.next_fast_lenof the segment length, which may zero-pad (e.g. a 257-sample segment gives 264 bins); pass the segment length explicitly for an unpadded frequency grid.fft_workers (int, optional) – Worker threads for SciPy’s CPU FFT (
-1uses all cores).
- Attributes:
frequenciesFrequency of each FFT bin in Hz, in standard FFT order.
n_segmentsNumber of (overlapping) segments averaged by the estimate.
n_signalsNumber of signals in the time series.
n_trialsNumber of trials in the time series.
observations_are_independentWhether the segments may be counted as independent observations.
timeMean of the segment center times, in seconds.
Methods
fft()Compute the Hann-windowed Fourier coefficients of every segment.
Methods
Compute the Hann-windowed Fourier coefficients of every segment.
Attributes
Frequency of each FFT bin in Hz, in standard FFT order.
is_one_sidedNumber of (overlapping) segments averaged by the estimate.
Number of signals in the time series.
Number of trials in the time series.
Whether the segments may be counted as independent observations.
Mean of the segment center times, in seconds.
- fft() ndarray[tuple[int, ...], dtype[complexfloating]][source]#
Compute the Hann-windowed Fourier coefficients of every segment.
- Returns:
fourier_coefficients – Shape
(1, n_trials, n_segments, n_fft_samples, n_signals). Segments occupy the taper axis, soConnectivity’s trial/taper expectation averages over segments (and trials) into a single time bin.- Return type:
array
- property frequencies: ndarray[tuple[int, ...], dtype[floating]]#
Frequency of each FFT bin in Hz, in standard FFT order.
- Returns:
frequencies
- Return type:
array, shape (n_fft_samples,)
- property observations_are_independent: bool#
Whether the segments may be counted as independent observations.
Welch’s estimate averages the periodograms of overlapping Hann-windowed segments. For a Hann window the correlation between the periodograms of segments overlapping by 50% is small, so up to that overlap the average has close to the degrees of freedom of independent segments (Welch 1967; Percival & Walden 1993, sec. 6.17). Beyond 50% the additional segments are strongly correlated with their neighbors and add little independent information, so
n_observations(trials x segments) overstates the effective sample size.Connectivityreads this flag before the jackknife, the debiased measures (pairwise phase consistency, debiased squared PLI/WPLI) and the zero-coherence significance test, whose finite-sample corrections assume independent observations.- Returns:
Truewhensegment_overlap <= 0.5.- Return type: