|
| 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 | + |
0 commit comments