How do I create a matrix that is only the frequencies within the COI of a wavelet transform coherence?

조회 수: 7 (최근 30일)
FsC 2023년 11월 12일
댓글: Mathieu NOE 2023년 11월 21일
I am measuring the wavelet transform coherence of two signals (x and y). I then am trying to take the average coherence within various frequency ranges. However, I only want to measure the coherence values within the cone of influence COI. How do I do this?
Currently I have the two signals and then conduct the wtc. The signals are attached as files
% define parameterts and signals
ts = 0.1; % time step
fs = 10; % frequency in Hz
t = (0:length(x) - 1)/10; % time vector
[wtc, f, coi] = wcoherence(x, y,fs);
Next, I assume I would create the matrix that is the coherence values within the cone of influence.
coiDatamatrix = ?? % a matrix of only the wtc values within the coi
Finaly, I would take the average coherence within the frequency range 0.125-0.3 Hz
freqRange = [0.125 0.3];
% % Find indices corresponding to the frequency range
freqIndices = find(f >= freqRange(1) & f <= freqRange(2));
% Extract coherence values in the frequency range within the COI
coherenceInRange = coiDatamatrix(freqIndices)
% Calculate average coherence (ignoring NaNs)
averageCoherence = mean(coherenceInRange);
댓글 수: 5이전 댓글 3개 표시이전 댓글 3개 숨기기
FsC 2023년 11월 17일
Yes, of course. I've attached the coherence matric (wtc), coi array, and frequency array (f). The original signal is 2 minutes long and sampled at 10 Hz. Attached is also an image of the graphical output for this data.
Mathieu NOE 2023년 11월 20일
ok I think I got it to work now , see in the answer section below

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

채택된 답변

Mathieu NOE 2023년 11월 20일
so now the final code
the idea is to create a mask so that wtc values that lies below the coi curve are zeroed
% specific code (to remove)
n = numel(coi);
t = (0:n - 1)*ts; % time vector
% define parameterts and signals
fs = 10; % frequency in Hz
ts = 1/fs; % time step
% t = (0:length(x) - 1)*ts; % time vector
% [wtc, wcs, f, coi] = wcoherence(x, y,fs);
% create a mask (coi) so data below coi curve are zeroed
[m,n] = size(wtc);
ind = round(m*coi/max(f));
for ci =1:n
end
% plot wtc within coi bounds
imagesc(t,f,abs(wtc));
set(gca,'YDir','normal');
title('X1');
xlabel('Time (samples)')
ylabel('Frequency (Hz)')
colormap('jet')
colorbar('vert')
hold on
plot(t,coi,'--w','linewidth',3);
% Finaly, I would take the average coherence within the frequency range 0.125-0.3 Hz
freqRange = [0.125 0.3];
% % Find indices corresponding to the frequency range
freqIndices = find(f >= freqRange(1) & f <= freqRange(2));
% Extract coherence values in the frequency range within the COI
coherenceInRange = abs(wtc(freqIndices,:));
% Calculate average coherence (ignoring NaNs)
averageCoherence = mean(coherenceInRange,'all','omitnan');
on your side you simply have to remove these lines
% specific code (to remove)
n = numel(coi);
t = (0:n - 1)*ts; % time vector
and uncomment this one
% t = (0:length(x) - 1)*ts; % time vector
% [wtc, wcs, f, coi] = wcoherence(x, y,fs);
hope it helps !
댓글 수: 2없음 표시없음 숨기기
FsC 2023년 11월 20일
This is perfect! Thank you so much for your help and knowledge!
Mathieu NOE 2023년 11월 21일
My pleasure !
one last thing : you can remove that line
all the best

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

카테고리

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