PLV all in one matrix

3 views (last 30 days)
Carmen Sergiou
Carmen Sergiou on 21 Jul 2021
Answered: Nipun on 30 May 2024
Dear Community,
I have created a script that calculates the phase-correlation (PLV) values for every participant for every frequency.
I have added a feature so it will give me all the PLV's per participant per frequency in a matrix. Then I am copying it in excel and then will calculate the mean eventually.
Now I am doing everything manually, but i was wondering, can I make something in the script so that every frequency will be put in my matrix, and it will keep on going untill 30Hz so I can copy the whole matrix in one time?
% names of the channels you want to compute connectivity between
channel1 = 'F7';
channel2 = 'FC1';
frequencies = [9];
% frequencies = [6];
nfreq = length(frequencies);
srate = ALLEEG.srate
time = -1:1/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
%%and then this is how I put it in the matrix:
filenames_TDCS_I ={'EEGLAB_Subject_102_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_104_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_110_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_112_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_116_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_118_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_120_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_122_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_124_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_128_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_132_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_138_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_140_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_148_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_150_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_152_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_154_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_156_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_158_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set','EEGLAB_Subject_164_I_REST_EC_chanrej_ep_rej_ICA pruned with ICA_ICA_clean_avref_int_int_final.set'}
phase_synchronization_all = zeros(1,length(filenames_TDCS_I))
for filenr=1:length(filenames_TDCS_I)
file_name_current = char(filenames_TDCS_I(filenr))
EEGdataset = pop_loadset('filename',file_name_current,'filepath',filepath2);
I hope this makes sense! I(See attachments also)
Best,
Carmen

Answers (1)

Nipun
Nipun on 30 May 2024
Hi Carmen,
I understand that you want to automate the process of calculating phase-correlation (PLV) values for every participant for every frequency and store them in a matrix. Here's how you can modify your script to achieve this:
% Names of the channels you want to compute connectivity between
channel1 = 'F7';
channel2 = 'FC1';
% Frequencies to iterate over
frequencies = 1:30;
nfreq = length(frequencies);
% Preallocate phase synchronization matrix
phase_synchronization_all = zeros(nfreq, length(filenames_TDCS_I));
% Iterate over frequencies
for freq_idx = 1:nfreq
center_freq = frequencies(freq_idx);
% Generate wavelet for current frequency
wavelet = exp(2*1i*pi*center_freq.*time) .* exp(-time.^2./(2*(4/(2*pi*center_freq))^2));
% Iterate over participants
for filenr = 1:length(filenames_TDCS_I)
file_name_current = char(filenames_TDCS_I(filenr));
EEGdataset = pop_loadset('filename', file_name_current, 'filepath', filepath2);
% Calculate PLV for current participant and frequency
% (Replace the following line with your PLV calculation code)
phase_synchronization_all(freq_idx, filenr) = calculate_PLV(EEGdataset, channel1, channel2, wavelet);
end
end
In this modified script:
  • You iterate over frequencies from 1 to 30 using frequencies = 1:30.
  • For each frequency, you generate the wavelet.
  • Then, you iterate over participants and calculate PLV for each frequency and each participant, storing the results in the phase_synchronization_all matrix.
Make sure to replace calculate_PLV with your actual PLV calculation code.
Let me know if you need further assistance!
Hope this helps.
Regards,
Nipun

Categories

Find more on Discrete Multiresolution Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!