# How do you average the power spectra across multiple samples to compare 2 conditions?

I have physiological signals from samples under 2 conditions and want to compare the difference in frequency content between the conditions. Specifically,I'd like to compare the average power spectrum of condition A and condition B to evaluate if there are any differences. Both sets of signals are sampled at 1000 Hz. Also, if the signals are of differing length, is it sufficient to just truncate to the shortest length? I'm trying to accomplish this in Python.

Any help would be awesome, thank you.

• 1. the thinking behind averaging to see the difference? 2. Have you heard of coherence?
– Jdip
Oct 11, 2023 at 1:54
• I have physiological signals from 100 samples in condition A and 100 samples in condition B. I'd like to compute average power spectrum for Condition A and Condition B and plot them both. I'm thinking I could use coherence after I've computed the average spectra for both conditions, right? Oct 11, 2023 at 2:04
• So my main question is how do I compute the average across all samples in a given condition? Oct 11, 2023 at 2:05

To compute the average spectrum, simply compute each individual spectrum with the same frequency precision and average them together.

To achieve this, you can zero pad each signal before taking the FFT to make sure they all have the same length. Whichever library you are using, there’s usually an option for that, for example.

• Should I zero-pad each signal or truncate to the shortest length? Zero padding could introduce additional variations, right? Also, I was thinking of applying the signal.welch() function from scipy and then averaging Pxx via arithmetic mean across all signals? See here: docs.scipy.org/doc/scipy/reference/generated/…. Would this work or am I missing something? Oct 12, 2023 at 4:32
• You can do either, but yes, truncating to the shortest length is "safer". Depends on how short and what you want your frequency resolution to be. As far as Welch, you don't need to do this since you're already averaging a bunch of spectra together, which will take care of the noise.
– Jdip
Oct 12, 2023 at 5:24
• Could you clarify what you mean by " As far as Welch, you don't need to do this since you're already averaging a bunch of spectra together, which will take care of the noise"? I need to calculate Pxx of each signal and then average via a simple arithmetic mean, right? What noise are you referring to? Oct 22, 2023 at 2:55
• In short, Welch's method is one of many methods to estimate $P_{xx}$. It trades frequency resolution for estimation noise variance reduction. The noise reduction is attained thanks to the averaging of multiple spectra together (successive windows of the signal under analysis). In your case, you have the luxury of having access to multiple realizations of the same process. You can therefore keep your frequency resolution intact by computing a periodogram (i.e. power spectrum) of each realization, and averaging (arithmetic mean, yes!) the results to reduce the estimation noise variance.
– Jdip
Oct 22, 2023 at 18:00
• Got it. Thanks for the thorough explanation, it was really helpful! One last question - should I be normalizing to the max. peak of Pxx (the PSD) to shift everything relative to 0 db? Oct 22, 2023 at 22:52