-
Notifications
You must be signed in to change notification settings - Fork 0
/
ECG_Spectrogram.m
116 lines (98 loc) · 3.49 KB
/
ECG_Spectrogram.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
close all
clear all
clc
%%%%%%%%%%% Counter initialization %%%%%%%%%%%%
neutral=1;
disgust=1;
sad=1;
happy=1;
anger=1;
surprise=1;
fear=1;
%%%%%%%%%%% Spectrogram parameters %%%%%%%%%%%%%%
window=hamming(256);
noverlap=148;
nfft=128;
fs=128;
load('SMOTE_ECG_Surprise.mat')
for i=1:96
data=AVG_ECG_STRUCT.AVG_ECG(i,1:7229);
S=spectrogram(data,window,noverlap,nfft,fs,'yaxis');
xlabel('time');
ylabel('Frequency hz');
figure
J = imresize(S,[227 227]);
imshow(J,[]);
redChannel = J(:,:,1); % Red channel
greenChannel = J(:,:,1); % Green channel
blueChannel = J(:,:,1); % Blue channel
allBlack = zeros(size(J, 1), size(J, 2), 'uint8');
just_red = cat(3, redChannel, allBlack, allBlack);
just_green = cat(3, allBlack, greenChannel, allBlack);
just_blue = cat(3, allBlack, allBlack, blueChannel);
% Recombine the individual color channels to create the original RGB image again.
recombinedRGBImage = cat(3, redChannel, greenChannel, blueChannel);
%imwrite(recombinedRGBImage,strcat('neutral',num2str(neutral),'.png'),'png')
imwrite(recombinedRGBImage,strcat('Surprise',num2str(anger),'.png'),'png')
%imwrite(J,strcat('Anger',num2str(anger),'.png'),'png')
anger=anger+1;
%anger if/else
% if isequal(GSR_STRUCT.Label{i,1},'Fear') %fear
%
%
% S=spectrogram(data,window,noverlap,nfft,fs,'yaxis');
%
% xlabel('time');
% ylabel('Frequency hz');
% figure
% J = imresize(S, [227 227]);
% imshow(J,[]);c
%
%
%
% redChannel = J(:,:,1); % Red channel
% greenChannel = J(:,:,1); % Green channel
% blueChannel = J(:,:,1); % Blue channel
% allBlack = zeros(size(J, 1), size(J, 2), 'uint8');
% just_red = cat(3, redChannel, allBlack, allBlack);
% just_green = cat(3, allBlack, greenChannel, allBlack);
% just_blue = cat(3, allBlack, allBlack, blueChannel);
% % Recombine the individual color channels to create the original RGB image again.
% recombinedRGBImage = cat(3, redChannel, greenChannel, blueChannel);
% %imwrite(recombinedRGBImage,strcat('neutral',num2str(neutral),'.png'),'png')
% imwrite(recombinedRGBImage,strcat('Fear',num2str(fear),'.png'),'png')
%
% %imwrite(J,strcat('Fear',num2str(fear),'.png'),'png')
% fear=fear+1;
%
% end%fear if/else
%
% if isequal(GSR_STRUCT.Label{i,1},'Sad') %sad
%
% S=spectrogram(data,window,noverlap,nfft,fs,'yaxis');
%
% xlabel('time');
% ylabel('Frequency hz');
% figure
% J = imresize(S, [227 227]);
% imshow(J,[]);
%
%
% redChannel = J(:,:,1); % Red channel
% greenChannel = J(:,:,1); % Green channel
% blueChannel = J(:,:,1); % Blue channel
% allBlack = zeros(size(J, 1), size(J, 2), 'uint8');
% just_red = cat(3, redChannel, allBlack, allBlack);
% just_green = cat(3, allBlack, greenChannel, allBlack);
% just_blue = cat(3, allBlack, allBlack, blueChannel);
% % Recombine the individual color channels to create the original RGB image again.
% recombinedRGBImage = cat(3, redChannel, greenChannel, blueChannel);
% %imwrite(recombinedRGBImage,strcat('neutral',num2str(neutral),'.png'),'png')
% imwrite(recombinedRGBImage,strcat('Sad',num2str(sad),'.png'),'png')
%
% %imwrite(J,strcat('Sad',num2str(sad),'.png'),'png')
% sad=sad+1;
%
% end %sad if-else end
%
end