-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadSignals.m
137 lines (106 loc) · 3.91 KB
/
loadSignals.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
%function pxxSubj = loadPxxSubj(subject)
close all; clear;
iSubject =5;
subjects = {'XiaMian', ...
'Tiffany', ...
'Yiheng', ...
'Xiangjun',...
'ZhengYang'}
rateType = 3;
Yh = [1:105 107:112 114:123 125:126];
%1=subject's valence rating
%2=subject's arousal rating
%3=IAPS valence rating
%4=IAPS arousal rating
subject =subjects{iSubject};
datadir = 'C:\Users\User\Documents\SRP\matlab\Matlab Reference\LoadEEGFunctions\';
%datadir = 'C:\Users\zy\Desktop\Tiffany Progress 16 Dec 2015\ProcessedData';
dataTrainingFolder = 'DataTraining';
Raw_sub = loadeegdata(subject,'rootdir', datadir,'datadir',dataTrainingFolder);
%FINDS THE FOUR TYPES OF RATINGS BY COLUMN
%1=subject's valence rating
%2=subject's arousal rating
%3=IAPS valence rating
%4=IAPS arousal rating
ratingsGrid = findSubjRatings([datadir '\' subject], loadRatings());
%RETURNS THREE SETS OF BOOLEAN VALUES TO SPECIFY WHICH TRIALS BELONG
%TO EACH OF THE THREE CATEGORIES
subjRating(1,:) = ratingsGrid(:, rateType)>6;
subjRating(2,:) = ratingsGrid(:, rateType)<=6 & ratingsGrid(:,rateType)>=4;
subjRating(3,:) = ratingsGrid(:, rateType)<4;
if iSubject == 3
subjRating = subjRating(:,Yh);
end
Raw_sub.EEG = double(Raw_sub.EEG)*Raw_sub.resolution;
% TAKES THE INDICES OF SELECTED CHANNELS
% sel_chan = Raw_sub.sel_chan_list;
%
% nSelChan = size(sel_chan);
% sel_chan_no = zeros(nSelChan, 1);
%
% for a = 1:nSelChan
% channel = sel_chan(a, 1);
% [rn, cn]=find(strcmp(Raw_sub.chan_list, channel));
% sel_chan_no(a, 1) = rn;
% end
sel_chan_no = [3 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 34 35 36 39 40];
%sel_chan_no = [30 31 32 34 35 36 39 40];
nChs = size(sel_chan_no, 2); %Number of Channels
nSample = 1500; %Length of Sample
nOpen = 500; %Length of Open Eyes
nClose = 3000; %Length of Close Eyes
halfSec = 125;
Fs = 250; %Sampling frequency
T = 1/Fs; %Sample time
L = nSample; %Length of signal
t = (0:L-1)*T; %Time vector
i = (1:L) %counter
%pxxSubj = {};
%LOAD THE AVERAGE PWELCH'S PER CHANNEL FOR THREE CATEGORIES
for rating = 1:size(subjRating,1)
%TAKES STARTING TIMES OF TRIALS
stimLocations=find(Raw_sub.stimcode==240);
if iSubject == 3
stimLocations = stimLocations(:, Yh);
end
stimLocations = stimLocations(subjRating(rating,:)) -1; %finds the position of stimcodes with that rating value
nTrials = size(stimLocations, 2);
stimTimings = Raw_sub.stimpos(stimLocations);
% baseLocations = stimLocations - 2;
% baseTimings = Raw_sub.stimpos(baseLocations);
pxxCat = zeros(nTrials, nSample, nChs);
for n = 1:nTrials
%extracts the channel signal from channel and makes them vertical
y = extract(stimTimings(n)-halfSec-150, nSample+halfSec*2, Raw_sub.EEG, sel_chan_no);
y = y';
%detrends and filters
y = generalFilter(2.5, 35, y);
y = y(halfSec:nSample+halfSec - 1, :); %cuts off the half a second before and after the signal
%spatial common average reference filtering
% car = mean(y,2);
% y = y - repmat(car, [1 size(y,2)]);
pxxCat(n,:,:) = y(:,:);
end
pxxAve = mean(pxxCat);
pxxSubj(rating, :, :) = pxxAve(1,:,:);
end
%PLOTS THE GRAPHS
rows = 2;
columns = 4;
total = rows*columns;
for channel = 1:nChs
if rem(channel,total)== 1
figure;
end
plotSpot = rem(channel,total);
if plotSpot == 0
plotSpot = total
legend('High', 'Mid', 'Low');
end
subplot(rows,columns, plotSpot);
plot(pxxSubj(:,:,channel)');
title(Raw_sub.chan_list(sel_chan_no(channel)));
hold on;
ylabel('dB');
axis([0,550,-7,7]);
end