2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 1. the thinking behind averaging to see the difference? 2. Have you heard of coherence? $\endgroup$
    – Jdip
    Oct 11, 2023 at 1:54
  • $\begingroup$ 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? $\endgroup$
    – MAtennis9
    Oct 11, 2023 at 2:04
  • $\begingroup$ So my main question is how do I compute the average across all samples in a given condition? $\endgroup$
    – MAtennis9
    Oct 11, 2023 at 2:05

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
14
  • $\begingroup$ 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? $\endgroup$
    – MAtennis9
    Oct 12, 2023 at 4:32
  • $\begingroup$ 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. $\endgroup$
    – Jdip
    Oct 12, 2023 at 5:24
  • $\begingroup$ 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? $\endgroup$
    – MAtennis9
    Oct 22, 2023 at 2:55
  • $\begingroup$ 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. $\endgroup$
    – Jdip
    Oct 22, 2023 at 18:00
  • $\begingroup$ 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? $\endgroup$
    – MAtennis9
    Oct 22, 2023 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.