Dear Community
I have created a loop to get phase synchronization for frequency range from 4-8 hz, but for some reason the script calculates only the value for 8Hz.
What am I doing wrong?
% phase-based connectivity
load 'EC_I.mat'
% names of the channels you want to compute connectivity between
channel1 = 'Fz';
channel2 = 'F8';
% create complex Morlet wavelet
frequencies = [4:8];
time = -1:1/EEG.srate:1;
half_wavN = (length(time)-1)/2;
all_wavelet = zeros(10, 1001);
for i_frequencies = frequencies
center_freq = i_frequencies ;
wavelet = exp(2*1i*pi*center_freq.*time) .* exp(-time.^2./(2*(4/(2*pi*center_freq))^2))
all_wavelet(i_frequencies,:) = wavelet ;
end
all_phase_synchronization = zeros(1, 1000);
for i_frequencies = frequencies
center_freq = i_frequencies ;
phase_synchronization = abs(mean(exp(1i*(phase_data(2,:)-phase_data(1,:)))));
all_phase_synchronization(i_frequencies,:) = phase_synchronization ;
end
disp([ 'Synchronization between ' channel1 ' and ' channel2 ' is ' num2str(phase_synchronization) '!' ])
All tips would be very helpful!! Thanks in advance,
Carmen

댓글 수: 3

for i_frequencies = frequencies
center_freq = i_frequencies ;
phase_synchronization = abs(mean(exp(1i*(phase_data(2,:)-phase_data(1,:)))));
all_phase_synchronization(i_frequencies,:) = phase_synchronization ;
end
frequences is 4:8 and you are setting i_frequencies to those. So i_frequencies is content, not index. You will end up writing to all_phase_synchronization(4:8,:) rather than to all_phase_synchronization(1:5, :)
Thank you so much for responding, so now I have changed the following:
frequencies = [4:8];
time = -1:1/EEG.srate:1;
half_wavN = (length(time)-1)/2;
all_wavelet = zeros(10, 1001);
for i_frequencies= frequencies
center_freq = i_frequencies ;
wavelet = exp(2*1i*pi*center_freq.*time) .* exp(-time.^2./(2*(4/(2*pi*center_freq))^2))
all_wavelet(1:5,:)= wavelet;
%all_wavelet(i_frequencies,:) = wavelet ;
end
all_phase_synchronization = zeros(1, 1000);
for i_frequencies = frequencies
center_freq = i_frequencies ;
phase_synchronization = abs(mean(exp(1i*(phase_data(2,:)-phase_data(1,:)))));
all_phase_synchronization(1:5, :) = phase_synchronization ;
end
disp([ 'Synchronization between ' channel1 ' and ' channel2 ' is ' num2str(phase_synchronization) '!' ])
And get this error :
Unable to perform assignment because the size of the left side is 5-by-0 and the
size of the right side is 1-by-1001.
Sorry, I am very new to matlab coding!!
Carmen Sergiou
Carmen Sergiou 2021년 6월 30일
I am now copying every electrode pair combination in excel, but is there also an option to have it in matlab in table? If I want to do analysis or correlations with it?
And I have to figure out how to differ between my two conditions also, if that is not possible I will make 2 seperate files, if there is documentation for that also very welcome!
Thanks again, really a life saver!!
Best,
Carmen

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

 채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 30일

0 개 추천

frequencies = [4:8];
nfreq = length(frequencies);
time = -1:1/EEG.srate:1;
half_wavN = (length(time)-1)/2;
all_wavelet = zeros(10, 1001);
for idx = 1 : nfreq
center_freq = frequencies(idx);
wavelet = exp(2*1i*pi*center_freq.*time) .* exp(-time.^2./(2*(4/(2*pi*center_freq))^2));
all_wavelet(idx,:)= wavelet;
end
all_phase_synchronization = zeros(nfreq, size(all_wavelet,2));
for idx = 1 : nfreq
center_freq = frequencies(idx);
phase_synchronization = abs(mean(exp(1i*(phase_data(2,:)-phase_data(1,:)))));
all_phase_synchronization(idx, :) = phase_synchronization ;
end
but you do not use all_wavelet() after you create it. and your phase_synchronization calculation always calculates over the same data and does not use the center_freq information. You also seem to expect it to be a vector rather than having one for each frequency. I suspect that you should not be using a loop there, just
all_phase_synchronization = abs(mean(exp(1i*(phase_data(2,:)-phase_data(1,:)))));
as a single statement with no loop and no initialization to zero needed.

댓글 수: 3

Carmen Sergiou
Carmen Sergiou 2021년 6월 30일
Thank you, I have implemented the changes and everything works correctly now.
I see a different phase-synchronization value then before, so I assume it is now measured over 4-8 Hz instead of over 8 Hz. When I look at the all_phase_synchronization table in my workspace, I do see all the same values but I assume that is the averaged over the frequency bands.
I decided to do use the loop, because if I just used the single row the phase value stayed the same as in my 8Hz.
Thank you so much!! I believe I can continue now (see screenshots for the workspace tables)
Walter Roberson
Walter Roberson 2021년 6월 30일
all_phase_synchronization is exactly the same for all rows because your code does not use the center_freq or idx information at all. Every iteration of the loop only works with phase_data(2,:)-phase_data(1,:) so it is exactly the same calculation every time.
Carmen Sergiou
Carmen Sergiou 2021년 6월 30일
Ok, well I am still stuck then.
Probably need to do some steps before that.
Thank you for your time!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Wavelet Toolbox에 대해 자세히 알아보기

질문:

2021년 6월 30일

댓글:

2021년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by