|
|
|
|
|
|
|
|
|
|
|
clear; clc; close all;
|
|
|
|
|
|
cwd = pwd;
|
|
|
addpath(cwd);
|
|
|
|
|
|
datalocation = [cwd '\ALL_DATA\ALL_Processed_Data\']; % Data are here
|
|
|
savelocation = [cwd '\ALL_DATA\ALL_Processed_Data\']; % Data save here
|
|
|
cd(datalocation);
|
|
|
|
|
|
[~, ~, SubjInfo] = xlsread([ cwd '\Patients_MS.xlsx'],'AllPedaling');
|
|
|
|
|
|
|
|
|
%%
|
|
|
for nn = 1: 2%size(SubjInfo,1)
|
|
|
|
|
|
type = SubjInfo{nn,1};
|
|
|
subj = SubjInfo{nn, 2};
|
|
|
|
|
|
disp([type,num2str(subj),'_Ped_Processed.mat']);
|
|
|
load([type,num2str(subj),'_Ped_Processed.mat']);
|
|
|
|
|
|
%Get Subj Info and remove the bad ICAs on the basis of VEOG correlation
|
|
|
%Bad ICAS 1,2,3 are ADJUST, VEOG correlation, and Gaussian template.
|
|
|
%ADJUST is a stand-alone program that isn't very good.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp1a = cell2mat(bad_ICAs(2));
|
|
|
temp1b = cell2mat(bad_ICAs(3));
|
|
|
temp1 = [temp1a temp1b];
|
|
|
tpidx = find (temp1==0);
|
|
|
temp1(tpidx)=[];
|
|
|
|
|
|
if isempty(temp1)
|
|
|
temp1 = 'NaN';
|
|
|
end
|
|
|
|
|
|
if isnumeric(temp1)
|
|
|
bad_ICAs_To_Remove=temp1;
|
|
|
elseif strmatch('NaN',temp1)
|
|
|
bad_ICAs_To_Remove=NaN;
|
|
|
else
|
|
|
bad_ICAs_To_Remove=str2num(temp1);
|
|
|
end
|
|
|
clear temp1a temp1b temp1 tpidx;
|
|
|
|
|
|
|
|
|
if ~(isnan(bad_ICAs_To_Remove))
|
|
|
EEG = pop_subcomp( EEG, bad_ICAs_To_Remove, 0);
|
|
|
end
|
|
|
clear bad_ICAs_To_Remove bad_chans bad_epochs bad_ICAs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tx=EEG.times;
|
|
|
b1=find(tx==-300); b2=find(tx==-100);
|
|
|
t1=find(tx==-500); t2=find(tx==2000);
|
|
|
tx2disp=-500:2:2000;
|
|
|
|
|
|
|
|
|
min_freq = 1.0233;
|
|
|
max_freq = 50;
|
|
|
num_freqs=50;
|
|
|
|
|
|
|
|
|
frex = logspace(log10(min_freq),log10(max_freq),num_freqs);
|
|
|
s=logspace(log10(3),log10(10),num_freqs)./(2*pi*frex);
|
|
|
|
|
|
|
|
|
t=-2:1/EEG.srate:2;
|
|
|
|
|
|
|
|
|
n_wavelet = length(t); half_of_wavelet_size = (n_wavelet-1)/2; clear dims
|
|
|
|
|
|
dims{1} = size(EEG.data); n_data{1} = dims{1}(2)*dims{1}(3); n_convolution{1} = n_wavelet+n_data{1}-1; n_conv_pow2{1} = pow2(nextpow2(n_convolution{1}));
|
|
|
|
|
|
|
|
|
channels = EEG.nbchan;
|
|
|
for chani = 1:channels
|
|
|
|
|
|
EEG_fft{1} = fft(reshape(EEG.data (chani,:,:),1,n_data{1}),n_conv_pow2{1});
|
|
|
|
|
|
for fi=1:num_freqs
|
|
|
wavelet{1} = fft( exp(2*1i*pi*frex(fi).*t) .* exp(-t.^2./(2*(s(fi)^2))) , n_conv_pow2{1} );
|
|
|
|
|
|
|
|
|
for convo=1
|
|
|
EEG_conv = ifft(wavelet{convo}.*EEG_fft{convo});
|
|
|
EEG_conv = EEG_conv(1:n_convolution{convo});
|
|
|
EEG_conv = EEG_conv(half_of_wavelet_size+1:end-half_of_wavelet_size);
|
|
|
EEG_multi_conv{convo} = reshape(EEG_conv,dims{convo}(2),dims{convo}(3)); clear EEG_conv;
|
|
|
temp_POWER{convo} = abs(EEG_multi_conv{convo}(t1:t2,:)).^2;
|
|
|
end
|
|
|
|
|
|
|
|
|
BASE = mean(mean(abs( EEG_multi_conv{1}(b1:b2,:)).^2));
|
|
|
|
|
|
temp_POWER_avg(:,1) = mean(temp_POWER{1}(:,:),2);
|
|
|
|
|
|
|
|
|
|
|
|
POWER(chani,fi,:,1) = 10*( log10(temp_POWER_avg(:,1)) - log10(repmat(BASE,size(temp_POWER_avg(:,1),1),1)) );
|
|
|
clear temp* EEG_multi_conv wavelet BASE1 BASE2;
|
|
|
end
|
|
|
clear *_fft;
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chanlocs = EEG.chanlocs;
|
|
|
MainOuts.POWER = POWER;
|
|
|
|
|
|
save([savelocation, type,num2str(subj),'_ANALYZED.mat'],'MainOuts','chanlocs' );
|
|
|
|
|
|
|
|
|
close all;
|
|
|
clearvars -except datalocation savelocation SubjInfo
|
|
|
|
|
|
end
|
|
|
|