How do I calculate the coherence within a specific frequency range?

10 次查看(过去 30 天)
Hello,
I am calculating the wavelet transform coherence betweem two signals. I am trying to extract the average coherence between 0.01-1Hz. I have tried using the f output of the wcoherence() function however, I'm confused by this output becasure it is a matrix of complex numbers that are both positive and negative. In the plot, I can clearly see that there are values within this frequency fange however, the current approach I'm using returns NaN or the values increase linearly with the increasing frequency band which does not seem correct.
How do I extract the average coherence within this frequency range?
Here is the code I am currently using:
load('x') % load signal 1
load('y') % load signal 2
fs = 10; % 10 Hz sampling rate
[wtc, f, coi] = wcoherence(x, y,fs); % calculate the coherence between the signals
fbandStep = 0.05; % frequency step for defining the frequency bands to calculate average coherence
for k = 0.01:0.05:1-fbandStep
% define upper and lower frequency bounds
lowerFrequencyBound = k;
upperFrequencyBound = k+fbandStep;
% Find indices corresponding to the frequency range
freqIndices = find(f_trial >= lower & f_trial <= upper);
% Extract coherence values for the specific frequency range
avgCoherence(k) = mean(wtc_trial(freqIndices));
clear freqIndices
end
  1 个评论
Mathieu NOE
Mathieu NOE 2023-11-14
hello
seems to me there is a bug in your code
[wtc, f, coi] = wcoherence(x, y,fs); % calculate the coherence between the signals
should be
[wtc, wcs, f, coi] = wcoherence(x, y,fs);
according to the doc , this is the right way :
[wcoh,wcs,f] = wcoherence(x,y,fs)
[wcoh,wcs,f,coi] = wcoherence(x,y,fs)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Frequency Transformations 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by