Re: [scipy/scipy] ENH: signal.csd: add `maxhold`, `minhold` options for `average` (PR #21487)

Folks,
Some enhancement to the csd or cross spectral density function were required to get the matlab like “maxhold” and “minhold” capability. Would like to get some feedback on the above mentioned pull request.

AFAIK, the Welch’s Method was designed to estimate PSDs of stationary processes. Having a max/min-hold functionality seems conceptually a bit odd to me. Wouldn’t make it more sense to apply those to cross-spectrograms (which are provided by ShortTimeFFT.spectrogram)?

There are some caveats, like the choice of window and overlap, which makes interpreting the results quantitatively non-trivial. Therefore it would be great, if you could provide a reference which discusses the methodological aspects of utilizing max/min-hold statistics on cross-spectrograms (or on Welch’s method). Matlab is not a good role-model in that regard, IMO.

Perhaps, it would be sufficient, to document in csd(), how to obtain a cross-spectral density by utilizing ShortTimeFFT.spectrogram, which is illustrated in this helper. This would enable users to easily implement their own custom statistics.

From a theoretical perspective, I agree that the Welch’s Method was designed to estimate PSDs of stationary processes. Nevertheless, I have observed the “peak hold” or “max hold” algorithm being available in most spectrum analyzers in practice.

Here some of the examples:

  1. Forum post discussing this topic at National Instruments - https://forums.ni.com/t5/LabVIEW/FFT-Power-Spectrum-and-PSD-Max-hold/td-p/4098242
  2. Dewesoft DAQ systems - https://manual.dewesoft.com/x/setupmodule/modules/freqdomain/fftapplication
  3. Article discussing the peak-hold functionality at the Silicon Labs portal - https://community.silabs.com/s/article/Peak-vs-Average-PSD-measurements?language=en_US
  4. Technical article related to amateur radio - https://destevez.net/2021/06/rain-backscatter-on-10-ghz/

I believe there is enough motivation from a practical perspective that Matlab found it reasonable to provide the max hold function with their pwelch. I have myself used it on a number of occasions for the following reasons - It is easy to use and the output is quite intuitive to understand for a general user.

Apart from this I have come across the following request looking for an equivalent implementation in scipy, although posted on the wrong forum-I guess - https://discourse.matplotlib.org/t/psd-maxhold-feature/22029.

For these reasons, I believe the addition of this functionality would be a welcome addition.