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

조회 수: 21 (최근 30일)
FsC 2023년 11월 13일
댓글: Mathieu NOE 2023년 11월 14일
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:
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
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)

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by