Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
leejheth committed Sep 23, 2018
1 parent f5318d9 commit 82c559c
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 289 deletions.
19 changes: 19 additions & 0 deletions functions/Arousal.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function mean_engage_across_channels = Arousal(n_epoch, stim_spectrum,baseline_spectrum)

clear arousal_ratio;
for epoch = 1:n_epoch
for seg = 1:size(stim_spectrum{epoch,1},2)
alpha_ratio=0;
beta_ratio=0;
for ch = [3 12] %calculate Arousal level at channels F3 and F4
% power ratio of signal with respect to the baseline
alpha_ratio = alpha_ratio+(mean(baseline_spectrum{epoch,1}(ch,4:6))-mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6)))/mean(baseline_spectrum{epoch,1}(ch,4:6)); % 8~12Hz
beta_ratio = beta_ratio+(mean(baseline_spectrum{epoch,1}(ch,7:15))-mean(stim_spectrum{epoch,1}{ch,seg}(1,7:15)))/mean(baseline_spectrum{epoch,1}(ch,7:15)); % 14~30Hz
end

arousal_ratio(epoch,seg) = beta_ratio/alpha_ratio;
end
end

% Average the arousal level across epochs and segments, excluding NaNs that may occur.
mean_engage_across_channels = mean2(arousal_ratio(~isnan(arousal_ratio)));
41 changes: 28 additions & 13 deletions functions/FAA_calculation.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
function FAA = FAA_calculation(n_epoch, stim_spectrum,baseline_spectrum)

clear alpha_ratio
for ch = [2 3 4 11 12 13] %calculate alpha power at F7, F3, FC5, FC6, F4, F8
for epoch = 1:n_epoch
for seg = 1:size(stim_spectrum{epoch,1},2)
% alpha power ratio of signal with respect to the baseline
alpha_ratio{ch}(epoch,seg) = mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6))/mean(baseline_spectrum{epoch,1}(ch,4:6));
end
end
end

FAA = log((mean(alpha_ratio{2},1)+mean(alpha_ratio{3},1)+mean(alpha_ratio{4},1))/3) - log((mean(alpha_ratio{11},1)+mean(alpha_ratio{12},1)+mean(alpha_ratio{13},1))/3);
% function FAA = FAA_calculation(n_epoch, stim_spectrum,baseline_spectrum)
%
% clear alpha_ratio
% for ch = [2 3 4 11 12 13] %calculate alpha power at F7, F3, FC5, FC6, F4, F8
% for epoch = 1:n_epoch
% for seg = 1:size(stim_spectrum{epoch,1},2)
% % alpha power ratio of signal with respect to the baseline
% alpha_ratio{ch}(epoch,seg) = mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6))/mean(baseline_spectrum{epoch,1}(ch,4:6));
% end
% end
% end
%
% FAA = log((mean(alpha_ratio{2},1)+mean(alpha_ratio{3},1)+mean(alpha_ratio{4},1))/3) - log((mean(alpha_ratio{11},1)+mean(alpha_ratio{12},1)+mean(alpha_ratio{13},1))/3);

% Modified on June 10, 2018 by Jihyun Lee
function FAA = FAA_calculation(n_epoch, stim_spectrum,baseline_spectrum)

clear alpha_ratio
for ch = [2 3 4 11 12 13] %calculate alpha power at F7, F3, FC5, FC6, F4, F8
for epoch = 1:n_epoch
for seg = 1:size(stim_spectrum{epoch,1},2)
% alpha power ratio of signal with respect to the baseline
alpha_ratio{ch}(epoch,seg) = (mean(baseline_spectrum{epoch,1}(ch,4:6))-mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6)))/mean(baseline_spectrum{epoch,1}(ch,4:6));
end
end
end

FAA = (mean(alpha_ratio{2},1)+mean(alpha_ratio{3},1)+mean(alpha_ratio{4},1))./(mean(alpha_ratio{11},1)+mean(alpha_ratio{12},1)+mean(alpha_ratio{13},1));
46 changes: 23 additions & 23 deletions functions/alpha_power.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
function mean_alpha_across_channels = alpha_power(n_epoch, stim_spectrum,baseline_spectrum,selected_ch_id)

clear alpha_ratio
for ch = selected_ch_id' %calculate alpha power at selected channels
for epoch = 1:n_epoch
for seg = 1:size(stim_spectrum{epoch,1},2)
% alpha power ratio of signal with respect to the baseline
alpha_ratio{ch}(epoch,seg) = mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6))/mean(baseline_spectrum{epoch,1}(ch,4:6));
end
end
end

% Average the alpha power ratio across the selected channels
sum_alpha_ratio=0;
for ch = selected_ch_id'
if sum(sum(isnan(alpha_ratio{ch}))) || sum(sum(isinf(alpha_ratio{ch})))
% skip epochs which has NaN or inf
continue
end

sum_alpha_ratio = sum_alpha_ratio + alpha_ratio{ch};
end

function mean_alpha_across_channels = alpha_power(n_epoch, stim_spectrum,baseline_spectrum,selected_ch_id)

clear alpha_ratio
for ch = selected_ch_id' %calculate alpha power at selected channels
for epoch = 1:n_epoch
for seg = 1:size(stim_spectrum{epoch,1},2)
% alpha power ratio of signal with respect to the baseline
alpha_ratio{ch}(epoch,seg) = (mean(baseline_spectrum{epoch,1}(ch,4:6))-mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6)))/mean(baseline_spectrum{epoch,1}(ch,4:6));
end
end
end

% Average the alpha power ratio across the selected channels
sum_alpha_ratio=0;
for ch = selected_ch_id'
if sum(sum(isnan(alpha_ratio{ch}))) || sum(sum(isinf(alpha_ratio{ch})))
% skip epochs which have NaN or inf
continue
end

sum_alpha_ratio = sum_alpha_ratio + alpha_ratio{ch};
end

mean_alpha_across_channels = sum_alpha_ratio/size(selected_ch_id,1);
20 changes: 20 additions & 0 deletions functions/alpha_power_all.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function mean_alpha_across_epochs = alpha_power_all(n_epoch, stim_spectrum,baseline_spectrum,selected_ch_id)

clear alpha_ratio
for ch = selected_ch_id' %calculate alpha power at selected channels
for epoch = 1:n_epoch
for seg = 1:size(stim_spectrum{epoch,1},2)
% alpha power ratio of signal with respect to the baseline
alpha_ratio{ch}(epoch,seg) = (mean(baseline_spectrum{epoch,1}(ch,4:6))-mean(stim_spectrum{epoch,1}{ch,seg}(1,4:6)))/mean(baseline_spectrum{epoch,1}(ch,4:6));
end
end
end

% Average the alpha power ratio across epochs
ch_count=1;
for ch = selected_ch_id'
alpha_across_epoch(ch_count) = mean(nanmean(alpha_ratio{ch},1));
ch_count = ch_count + 1;
end

mean_alpha_across_epochs = alpha_across_epoch;
Loading

0 comments on commit 82c559c

Please sign in to comment.