|
| 1 | +clear variables |
| 2 | +eeglab |
| 3 | +len = 256; |
| 4 | +Fs = 256; |
| 5 | +nfft = 512; %should be power of 2 |
| 6 | +%noverlap = 0; %we'll do 50% overlap, better b/c welch uses hamming window |
| 7 | + |
| 8 | + |
| 9 | +group= {'Aging' }%'Control' 'ASD'}; |
| 10 | + |
| 11 | +for group_count = 1:length(group) |
| 12 | + if strcmp(group{group_count},'Aging') |
| 13 | + subject_list = {'12022' '12023' '12031' '12081' '12094' '12188' '12255' '12335' '12339' '12362' '12364' '12372' '12376' '12390' '12398' '12407' '12408' '12451' '12454' '12457' '12458' '12459' '12468' '12478' '12498' '12510' '12517' '12532' '12564' '12631' '12633' '12634' '12636' '12665' '12670' '12696' '12719' '12724' '12751' '12763' '12769' '12776' '12790' '12806' '12814' '12823' '12830' '12847' '12851' '12855' '12856' '12857' '12859' '12871' '12872' '12892'}; |
| 14 | + people_no_trigger = []; |
| 15 | + people_no50_trigger = []; |
| 16 | + people_no51_trigger = []; |
| 17 | + trigger50_51_same = []; |
| 18 | + elseif strcmp(group{group_count},'ASD') |
| 19 | + subject_list = {'1101' '1164' '1808' '1852' '1855' '11014' '11094' '11151' '11170' '11275' '11349' '11516' '11558' '11583' '11647' '11729' '11735' '11768' '11783' '11820' '11912' '1106' '1132' '1134' '1154' '1160' '1173' '1174' '1179' '1190' '1838' '1839' '1874' '11013' '11056' '11098' '11106' '11198' '11244' '11293' '11325' '11354' '11375' '11515' '11560' '11580' '11667' '11721' '11723' '11750' '11852' '11896' '11898' '11913' '11927' '11958' '11965'}; %all the IDs for the indivual particpants; |
| 20 | + people_no_trigger = []; |
| 21 | + people_no50_trigger = []; |
| 22 | + people_no51_trigger = []; |
| 23 | + trigger50_51_same = []; |
| 24 | + elseif strcmp(group{group_count},'Control') |
| 25 | + subject_list = {'12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899' '10033' '10130' '10131' '10158' '10165' '10257' '10281' '10293' '10360' '10369' '10384' '10394' '10407' '10438' '10446' '10451' '10463' '10467' '10476' '10501' '10526' '10534' '10545' '10561' '10562' '10581' '10585' '10616' '10615' '10620' '10639' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '10844' '10956' '12005' '12007' '12010' '12215' '12328' '12360' '12413' };% ------------------------------------------------ |
| 26 | + people_no_trigger = []; |
| 27 | + people_no50_trigger = []; |
| 28 | + people_no51_trigger = []; |
| 29 | + trigger50_51_same = []; |
| 30 | + end |
| 31 | + path_1 = ['C:\Users\dohorsth\Desktop\Testing restingstate\' group{group_count} '\']; |
| 32 | + |
| 33 | + for subject_list_count = 1:length(subject_list) |
| 34 | + path = [path_1 subject_list{subject_list_count} '\']; |
| 35 | + EEG = pop_loadset('filename',[subject_list{subject_list_count} '_inter.set'],'filepath', path ); |
| 36 | + %% separate EO from EC |
| 37 | + info = []; |
| 38 | + for i = 1:length(EEG.event) |
| 39 | + if strcmp(EEG.event(i).type, 'boundary') % in there because of manual artefact rejection |
| 40 | + continue |
| 41 | + elseif isfield(EEG.event,'edftype') %isempty(EEG.event(i).edftype)~=1 |
| 42 | + info(i,1) = string(EEG.event(i).edftype); |
| 43 | + elseif isfield(EEG.event,'type') %isempty(EEG.event(i).type)~=1 |
| 44 | + info(i,1) = string(EEG.event(i).type); |
| 45 | + end |
| 46 | + info(i,2) = EEG.event(i).latency; |
| 47 | + end |
| 48 | + if size(info,1)==2 && length(info)==2 %because there were no boundries, the data is in a 2x2 matrix instead of a 1x4) |
| 49 | + info(3,1)=0; %we add a zero, so it does the same |
| 50 | + end |
| 51 | + info(info==0) = []; %delete all zeros |
| 52 | + |
| 53 | + if isempty(info)%if there are no triggers, we are going to choose the data ourselves but take less to be safe |
| 54 | + durations=0; |
| 55 | + %when 1 or more triggers are missing, this loop happens. using the latencies + durations of the boundaries in EEG.event to reproduce the original continues data. |
| 56 | + %calculating which boundary is the one that would have included the trigger and using there latency to instead of the missing trigger's |
| 57 | + for ii= 1:length(EEG.event) |
| 58 | + durations=durations+EEG.event(ii).duration; %this will sum all the durations of the deleted data |
| 59 | + if EEG.event(ii).latency+durations-EEG.event(ii).duration-1<EEG.urevent(1).latency && EEG.event(ii).latency+durations+1>EEG.urevent(1).latency %if the start of the boundry is before the latency of the original 50 and the duration last until after) (-1 and +1 just to prevent rounding up/down issues) |
| 60 | + info=[50, 51, EEG.event(ii).latency]; %keeps the 2 correct ones from info, but uses the start of the boundry event for the first trigger |
| 61 | + people_no50_trigger = [people_no50_trigger, subject_list(subject_list_count)]; |
| 62 | + elseif EEG.event(ii).latency+durations-EEG.event(ii).duration-1<EEG.urevent(2).latency && EEG.event(ii).latency+durations+1>EEG.urevent(2).latency %if the start of the boundry is before the latency of the original 50 and the duration last until after) |
| 63 | + info=[info(1), info(2), info(3), EEG.event(ii).latency]; %don't think this is correct, I think this wil |
| 64 | + end |
| 65 | + end |
| 66 | + people_no_trigger = [people_no_trigger, subject_list(subject_list_count)]; |
| 67 | + elseif length(info)~=4 %if one of the two triggers got deleted by the auto cleaning |
| 68 | + if info(1)==50 %trigger 51 is deleted (EC) will find the correct time and add it |
| 69 | + durations=0; |
| 70 | + for ii= 1:length(EEG.event) |
| 71 | + durations=durations+EEG.event(ii).duration; %this will sum all the durations of the deleted data |
| 72 | + if EEG.event(ii).latency+durations-EEG.event(ii).duration-1<EEG.urevent(2).latency && EEG.event(ii).latency+durations+1>EEG.urevent(2).latency %if the start of the boundry is before the latency of the original 50 and the duration last until after) |
| 73 | + info=[info(1), 51, info(2), EEG.event(ii).latency]; %don't think this is correct, I think this wil |
| 74 | + people_no51_trigger = [people_no51_trigger, subject_list(subject_list_count)]; |
| 75 | + end |
| 76 | + end |
| 77 | + elseif info(1)==51 %trigger 51 is deleted (EC) will find the correct time and add it |
| 78 | + durations=0; |
| 79 | + for ii= 1:length(EEG.event) |
| 80 | + durations=durations+EEG.event(ii).duration; %this will sum all the durations of the deleted data |
| 81 | + if EEG.event(ii).latency+durations-EEG.event(ii).duration-1<EEG.urevent(1).latency && EEG.event(ii).latency+durations+1>EEG.urevent(1).latency %if the start of the boundry is before the latency of the original 50 and the duration last until after) (-1 and +1 just to prevent rounding up/down issues) |
| 82 | + info=[50, info(1), EEG.event(ii).latency, info(2)]; %keeps the 2 correct ones from info, but uses the start of the boundry event for the first trigger |
| 83 | + people_no50_trigger = [people_no50_trigger, subject_list(subject_list_count)]; |
| 84 | + end |
| 85 | + end |
| 86 | + else |
| 87 | + breakhere |
| 88 | + |
| 89 | + end |
| 90 | + end |
| 91 | + if info(4)-info(3)<2 %this looks if trigger 50&51 are at almost the same time 1==1sec/256 |
| 92 | + info(3)=1000; |
| 93 | + trigger50_51_same= [trigger50_51_same; subject_list(subject_list_count)]; |
| 94 | + end |
| 95 | + data_EO = EEG.data(:,info(3):info(4)); |
| 96 | + data_EO(:,1:2560)=[];%added to delete first 10 sec |
| 97 | + if info(4)+(info(4)-info(3))>EEG.pnts |
| 98 | + data_EC = EEG.data(:,info(4):end); %if the EC part is shorter then the EO part it would exceed the max pnts value |
| 99 | + else |
| 100 | + data_EC = EEG.data(:,info(4):info(4)+(info(4)-info(3))); %this makes sure they are both equally long |
| 101 | + end |
| 102 | + data_EC(:,1:2560)=[];%added to delete first 10 sec |
| 103 | + % end |
| 104 | + %% Compute Power |
| 105 | + CPz = 32; |
| 106 | + Pz = 31; |
| 107 | + Cz = 48; |
| 108 | + |
| 109 | + [P_EO_CPz freqs] = pwelch(data_EO(CPz,:),len,[],nfft,Fs); %does not produce an image with outputs |
| 110 | + P_EO_Pz = pwelch(data_EO(Pz,:),len,[],nfft,Fs); %does not produce an image with outputs |
| 111 | + P_EO_Cz = pwelch(data_EO(Cz,:),len,[],nfft,Fs); %does not produce an image with outputs |
| 112 | + P_EC_CPz = pwelch(data_EC(CPz,:),len,[],nfft,Fs); %does not produce an image with outputs |
| 113 | + P_EC_Pz = pwelch(data_EC(Pz,:),len,[],nfft,Fs); %does not produce an image with outputs |
| 114 | + P_EC_Cz = pwelch(data_EC(Cz,:),len,[],nfft,Fs); %does not produce an image with outputs |
| 115 | + |
| 116 | + PSD_EO_CPzlog(:,subject_list_count) = 10*log10(P_EO_CPz); |
| 117 | + PSD_EO_Pzlog(:,subject_list_count) = 10*log10(P_EO_Pz); |
| 118 | + PSD_EO_Czlog(:,subject_list_count) = 10*log10(P_EO_Cz); |
| 119 | + PSD_EC_CPzlog(:,subject_list_count) = 10*log10(P_EC_CPz); |
| 120 | + PSD_EC_Pzlog(:,subject_list_count) = 10*log10(P_EC_Pz); |
| 121 | + PSD_EC_Czlog(:,subject_list_count) = 10*log10(P_EC_Cz); |
| 122 | + |
| 123 | + end |
| 124 | + % save([path_1 'PSD_EO_CPzlog_' group{group_count}], 'PSD_EO_CPzlog') |
| 125 | + % save([path_1 'PSD_EO_Pzlog_' group{group_count}], 'PSD_EO_Pzlog') |
| 126 | + % save([path_1 'PSD_EO_Czlog_' group{group_count}], 'PSD_EO_Czlog') |
| 127 | + % save([path_1 'PSD_EC_CPzlog_' group{group_count}], 'PSD_EC_CPzlog') |
| 128 | + % save([path_1 'PSD_EC_Pzlog_' group{group_count}], 'PSD_EC_Pzlog') |
| 129 | + % save([path_1 'PSD_EC_Czlog_' group{group_count}], 'PSD_EC_Czlog') |
| 130 | + save([path_1 'trigger50_51_same_' group{group_count}], 'trigger50_51_same') |
| 131 | + save([path_1 'people_no_trigger_' group{group_count}], 'people_no_trigger') |
| 132 | + save([path_1 'people_1_trigger_' group{group_count}], 'people_1_trigger') |
| 133 | + |
| 134 | +end |
| 135 | + |
0 commit comments