Skip to content

fixing issue with overlapping/non-overlapping segments (introduced by !146)

A bug was found in the new implementation of the PSD/CSD calculations, which was fortuitously not present when using default parameters. The issue was that when not using the same overlap value for both the Welch PSD estimation and the overall segment (CSD) estimation, the number of segments in the PSD and CSD spectrograms would differ. This MR fixes the issue by adding a new parameter, overlap_factor_welch, separate from overlap_factor, which differentiates the overlaps used for a Welch estimate of a spectrum vs. the overlap to use in the analysis segments themselves. I also took the opportunity to add a window_fftgram_dict_welch parameter dictionary, so that we can control what window is used when calculating Welch averages.

The bug was found by @jessica.lawrence ; could you please check out this MR and verify your code works now?

This should link up with work done previously on the bias factors by @philip.charlton ! However, as the code now stands, things can break when overlap_factor_welch is explicitly 0.0. I have set up a few safety nets that turn it to 1.0 when the user requests a 0.0 overlap (no overlap) for Welch estimation, which in turn sets the bias factor to 1.0; similarly, this happens also when the PSD is estimated via coarse-graining instead of Welch averaging. To then control the values of the window factors in this case, I suggest setting the window_fftgram_dict_welch to boxcar, which then implies all window factors are 1.0.

NEW PARAMETERS

  • overlap_factor_welch
  • window_fftgram_dict_welch

REMOVED PARAMETERS

  • zeropad_csd

zeropadding is now done automatically whenever/wherever coarse-graining is employed.

UPDATE 5/1/23

I have done some extensive testing to check that various allowed combinations don't break the pipeline:

works? c-grain PSD c-grain CSD overlap_factor overlap_factor_welch
Y F T 0.5 0.5
Y F F 0.5 0.5
Y T * T 0.5 0.5
Y T * F 0.5 0.5
Y F T 0.0 0.5
Y F F 0.0 0.5
Y T * T 0.0 0.5
Y T * F 0.0 0.5
Y F T 0.0 0.0**
Y F T 0.5 0.0**

* these cases require setting window_fftgram_welch=boxcar to ensure window factors don't do anything weird to the final estimate...

** these cases should really only be used with window_fftgram_welch=boxcar or a really narrow tukey...

NOTE: whenever an overlap of 0.0 is used for PSD estimation (last 4 cases or whenever c-grain PSD is True), the bias factor is automatically set to 1.0 to avoid a division by 0. The sanity+validity of this needs to be checked.

Edited by Arianna Renzini

Merge request reports