Skip to content

Commit 920bb6b

Browse files
authored
Add files via upload
1 parent 9305533 commit 920bb6b

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
41.9 KB
Loading
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
%18BEC0042 - T.DINESH RAM SAI
3+
4+
function ecg2cwtscg(ecgdata,cwtfb,ecgtype)
5+
nos=10; %number of signals pieces. I.e, there are 65536 samples. We cut them into 500 sample blocks, i.e each block contains 500 samples each. We take first 10 blocks
6+
nol=500; %signal length
7+
colormap=jet(128); %Defining the colormap for scalogram images
8+
if strcmp(ecgtype, 'ARR') %equivalent to ecgtype=='ARR'
9+
folder=strcat('C:\Users\DINESH RAM SAI\Desktop\Subsystem-1\ecgdataset\arr\arr'); %Destination Folder for saving Images
10+
findx=0; %Required Variable Declaration for using in loops
11+
for i=1:30
12+
indx=0; %Required Variable Declaration for using in loops
13+
for k=1:nos
14+
ecgsignal=ecgdata(i,indx+1:indx+nol); %Extracting the ECG Signal from the ecgdata matrix. It equivaletly extracts 500 sample blocks
15+
cfs = abs(cwtfb.wt(ecgsignal)); %Finding the wavelet coefficients using filter 'fb'. abs() is used because coefficients are complex.
16+
im = ind2rgb(im2uint8(rescale(cfs)),colormap); %by this command, we are converting the images into scalogram images.
17+
%First rescaling the coefficients from 0 to 1.Then converting them into unsigned interger 8 so that it becomes image
18+
%and converting this index mode into rgb color mode
19+
filenameindex=findx+k; %Required Variable Declaration for using in naming the images
20+
filename=strcat(folder,sprintf('%d.jpg',filenameindex)); %Naming the images. D is the loop execution number. Hence for first time execution, it produces 1.jpg
21+
imwrite(imresize(im,[227 227]),filename); %Stored in the current directory using imwrite. Before storing, it changes image dimensions to 227x227 px which is applicable to AlexNet
22+
indx=indx+nol; %Incrementing the value of appropriate variable for running the next iteration
23+
end
24+
findx=findx+nos; %Incrementing the value of appropriate variable for running the next iteration
25+
end
26+
elseif strcmp(ecgtype, 'CHF') %Procedure is same, except the ECG Datatype is CHF
27+
folder=strcat('C:\Users\DINESH RAM SAI\Desktop\Subsystem-1\ecgdataset\chf\chf');
28+
findx=0;
29+
for i=1:30
30+
indx=0;
31+
for k=1:nos
32+
ecgsignal=ecgdata(i,indx+1:indx+nol);
33+
cfs = abs(cwtfb.wt(ecgsignal));
34+
im = ind2rgb(im2uint8(rescale(cfs)),colormap);
35+
filenameindex=findx+k;
36+
filename=strcat(folder,sprintf('%d.jpg',filenameindex));
37+
imwrite(imresize(im,[227 227]),filename);
38+
indx=indx+nol;
39+
end
40+
findx=findx+nos;
41+
end
42+
elseif strcmp(ecgtype, 'NSR')%Procedure is same, except the ECG Datatype is NSR
43+
folder=strcat('C:\Users\DINESH RAM SAI\Desktop\Subsystem-1\ecgdataset\nsr\nsr');
44+
findx=0;
45+
for i=1:30
46+
indx=0;
47+
for k=1:nos
48+
ecgsignal=ecgdata(i,indx+1:indx+nol);
49+
cfs = abs(cwtfb.wt(ecgsignal));
50+
im = ind2rgb(im2uint8(rescale(cfs)),colormap);
51+
filenameindex=findx+k;
52+
filename=strcat(folder,sprintf('%d.jpg',filenameindex));
53+
imwrite(imresize(im,[227 227]),filename);
54+
indx=indx+nol;
55+
end
56+
findx=findx+nos;
57+
end
58+
end
59+
60+
61+
62+
63+
64+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
%18BEC0042 - T.DINESH RAM SAI
3+
4+
clc; clear all; close all;
5+
% create CWT Image Database from ECG Signals
6+
% Loading ECG Data
7+
%load(fullfile('C:','Users','DINESH RAM SAI','Documents','VIT', '5th Semester - Fall Sem 2020 - 2021','Digital Signal Processing (ECE2006)','Project','Project Files','1 - ECG Signal Classification','ECGData.mat'));
8+
load('ECGData.mat'); % Loading the ECG Data
9+
data=ECGData.Data; %Getting Database from the loaded Data. It is a 162x65536 matrix which means it consists of 162 ECG Signals each with sample size of 65536
10+
labels=ECGData.Labels; %Getting Labels from the loaded Data. Name of the Signals Can be get from Labels
11+
12+
ARR=data(1:30,:); %Taken first 30 Recordings of each ECG type
13+
CHF=data(97:126,:);
14+
NSR=data(127:156,:);
15+
signallength=500; %Limiting the Sample Size of Signal to 500 instead of 65536
16+
17+
%Defining filterbanks for CWT with amor wavelet and 12 filters per octave
18+
fb=cwtfilterbank('SignalLength',signallength,'Wavelet','amor','VoicesPerOctave',12); %used to define cwt coefficients.
19+
20+
%Making Folders
21+
22+
mkdir('ecgdataset'); %MainFolder
23+
mkdir('ecgdataset\arr'); %SubFolder
24+
mkdir('ecgdataset\chf');
25+
mkdir('ecgdataset\nsr');
26+
27+
28+
29+
ecgtype={'ARR','CHF','NSR'};
30+
31+
%Function to convert ECG to Image
32+
ecg2cwtscg(ARR,fb,ecgtype(1)); %User Defined function to convert ecg signal into scalogram image using cwt
33+
ecg2cwtscg(CHF,fb,ecgtype(2));
34+
ecg2cwtscg(NSR,fb,ecgtype(3));
35+
36+

0 commit comments

Comments
 (0)