2
$\begingroup$

Is there a general formula I could use to calculate the ideal window for the window argument in the function scipy.signal.coherence, maybe taking into account sampling rate and number of time points?

For example, if I acquired data at a sampling rate of $1.5\texttt{Hz}$ and I have $100$ time points, what window size would you recommend?

$\endgroup$

1 Answer 1

1
$\begingroup$
  • It depends what frequency resolution you are happy with, i.e. how many discrete frequencies you think are relevant to you. These frequencies will span $0$ to $f_s/2$, and you will get a coherence value for each.
  • The frequency resolution is computed as $f_s/N$, $N$ being the size of the analysis window.

With that in mind, a here is an example:

$N = 10$ will give you $N/2 = 5$ values for your coherence function (the negative frequency part is discarded), at the following discrete frequencies spaced $f_s/N = 0.15\texttt{Hz}$ apart: $$0\texttt{Hz}, 0.15\texttt{Hz}, 0.30\texttt{Hz}, 0.45\texttt{Hz}, 0.60\texttt{Hz}$$

Note, you can also play around with the noverlap argument. Typical values would be $N/2$ or $N/4$

$\endgroup$
2
  • $\begingroup$ Thanks a lot for the explanation, it was very helpful! What would you consider a reasonable frequency resolution to be? I'm mostly interested in very low frequencies (below 0.25 Hz). I believe matlab uses a default L=N/4.5, but I'm not sure what the rationale is for that choice. $\endgroup$
    – HappyPy
    Jan 25, 2023 at 22:34
  • $\begingroup$ I don't know your application, so you need to define what a reasonable frequency resolution is based on your requirements. You can also compute the coherence on the full $100$ points. By the way, I'm assuming you know what coherence is, you do know it's computed between two signals right? Your question mentions "data", hence my question. $\endgroup$
    – Jdip
    Jan 25, 2023 at 23:15

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.