Download this file

148 lines (117 with data), 4.4 kB

  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
138
139
140
141
142
143
144
145
146
147
clear all
clc
format long
%%
% Read the Data and Create Dataset
Stack_Dataset = [];
num_trial = 20;
for i = 1:64
Dataset = ['Dataset_', num2str(i), '.mat'];
Dataset = load(Dataset);
Dataset = Dataset.Dataset;
Dataset = reshape(Dataset, num_trial*84, 640);
[row, column] = size(Dataset);
Dataset = reshape(Dataset', 1, row*column);
Stack_Dataset = [Stack_Dataset; Dataset];
end
Stack_Dataset = Stack_Dataset - mean(Stack_Dataset, 1);
Stack_Dataset = Stack_Dataset';
%% Compute Covariance Matrix
covariance_matrix = cov(Stack_Dataset);
xlswrite('covariance_matrix.xlsx', covariance_matrix);
figure(1)
imagesc(covariance_matrix)
axis square
title('Covariance Matrix for 20 Subjects', 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold')
xlabel('Channels'), ylabel('Channels')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
colorbar
print('Covariance_Matrix_for_20_Subjects', '-dpng', '-r600')
%% Compute Pearson Matrix
Pearson_matrix = corrcoef(Stack_Dataset);
xlswrite('Pearson_matrix.xlsx', Pearson_matrix);
figure(2)
imagesc(Pearson_matrix)
axis square
title('Pearson Matrix for 20 Subjects', 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold')
xlabel('Channels'), ylabel('Channels')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
colorbar
print('Pearson_matrix_for_20_Subjects', '-dpng', '-r600')
%% Compute Absolute Pearson Matrix
Absolute_Pearson_matrix = abs(Pearson_matrix);
xlswrite('Absolute_Pearson_matrix.xlsx', Absolute_Pearson_matrix);
figure(3)
imagesc(Absolute_Pearson_matrix)
axis square
title('Absolute Pearson Matrix for 20 Subjects', 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold')
xlabel('Channels'), ylabel('Channels')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
colorbar
print('Absolute_Pearson_matrix_for_20_Subjects', '-dpng', '-r600')
%% Compute Adjacency Matrix
Eye_Matrix = eye(64, 64);
Adjacency_Matrix = Absolute_Pearson_matrix - Eye_Matrix;
xlswrite('Adjacency_Matrix.xlsx', Adjacency_Matrix);
figure(4)
imagesc(Adjacency_Matrix)
axis square
title('Adjacency Matrix for 20 Subjects', 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold')
xlabel('Channels'), ylabel('Channels')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
colorbar
print('Adjacency_Matrix_for_20_Subjects', '-dpng', '-r600')
%% Compute Degree Matrix
diagonal_vector = sum(Adjacency_Matrix, 2);
Degree_Matrix = diag(diagonal_vector);
figure(5)
imagesc(Degree_Matrix)
axis square
title('Degree Matrix for 20 Subjects', 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold')
xlabel('Channels'), ylabel('Channels')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
colorbar
print('Degree_Matrix_for_20_Subjects', '-dpng', '-r600')
%% Compute Laplacian Matrix
Laplacian_Matrix = Degree_Matrix - Adjacency_Matrix;
figure(6)
imagesc(Laplacian_Matrix)
axis square
title('Laplacian Matrix for 20 Subjects', 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold')
xlabel('Channels'), ylabel('Channels')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
colorbar
print('Laplacian_Matrix_for_20_Subjects', '-dpng', '-r600')
%% Read and Create Labels
Labels = load('Labels_1.mat');
Labels = Labels.Labels;
Labels = reshape(Labels, num_trial*84, 4);
[row, column] = size(Labels);
New_Labels = [];
parfor i = 1:row
location = find(Labels(i, :) == 1);
location = location - 1;
New_Labels = [New_Labels; location];
end
Labels = New_Labels;
Extend_Labels = [];
parfor i =1:640
Extend_Labels = [Extend_Labels, Labels];
end
Labels = Extend_Labels;
[row, column] = size(Labels);
Labels = reshape(Labels', 1, row*column);
Labels = Labels';
%%
All_Data = [Stack_Dataset, Labels];
rowrank = randperm(size(All_Data, 1));
All_Dataset = All_Data(rowrank, :);
[row, ~] = size(All_Dataset);
training_set = All_Dataset(1:fix(row/10*9), 1:64);
test_set = All_Dataset(fix(row/10*9)+1:end, 1:64);
training_label = All_Dataset(1:fix(row/10*9), end);
test_label = All_Dataset(fix(row/10*9)+1:end, end);
xlswrite('training_set.xlsx', training_set);
xlswrite('test_set.xlsx', test_set);
xlswrite('training_label.xlsx', training_label);
xlswrite('test_label.xlsx', test_label);