|
a |
|
b/preprocessData.m |
|
|
1 |
function preprocessData(filename_id, rhythm, filename) |
|
|
2 |
% add preprocessing steps |
|
|
3 |
% Baseline wanderer removal |
|
|
4 |
% Noise removal |
|
|
5 |
% Make every 12 lead data as clean as possible |
|
|
6 |
% create a datastore based on the rhythm label on data |
|
|
7 |
fs = 500; |
|
|
8 |
table = readtable(filename_id); |
|
|
9 |
[b,a] = butter(5, 45/fs); %for filtering of the power line noises frequncy at 60 Hz |
|
|
10 |
[d,c] = butter(5, 10/fs, 'high'); %for filtering of baseline wander |
|
|
11 |
processed_data = zeros(size(table)); |
|
|
12 |
% doing of butterworth filtering from both side to remove the phase |
|
|
13 |
% shift problem |
|
|
14 |
for i = 1:12 |
|
|
15 |
data = table2array(table(:,i)); |
|
|
16 |
data_1 = filter(b, a, data); |
|
|
17 |
data_2 = filter(b, a, flip(data_1,1)); |
|
|
18 |
data_2 = flip(data_2,1); |
|
|
19 |
data_3 = filter(d, c, data_2); |
|
|
20 |
data_4 = filter(d, c, flip(data_3,1)); |
|
|
21 |
data_4 = flip(data_4,1); |
|
|
22 |
mask = smooth(smooth(data_4,300),10); |
|
|
23 |
data_4 = data_4 - mask; |
|
|
24 |
processed_data(:,i) = data_4; |
|
|
25 |
end |
|
|
26 |
|
|
|
27 |
rhythm = cell2mat(rhythm); |
|
|
28 |
if rhythm == "SB" |
|
|
29 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\SinusBradycardia"; |
|
|
30 |
elseif rhythm == "SR" |
|
|
31 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\SinusRhythm"; |
|
|
32 |
elseif rhythm == "AFIB" |
|
|
33 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\AtrialFibrilation"; |
|
|
34 |
elseif rhythm == "ST" |
|
|
35 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\SinusTachycardia"; |
|
|
36 |
elseif rhythm == "AF" |
|
|
37 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\AtrialFlutter"; |
|
|
38 |
elseif rhythm == "SA" |
|
|
39 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\SinusIrregularity"; |
|
|
40 |
elseif rhythm == "SVT" |
|
|
41 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\SupraventricularTachycardia"; |
|
|
42 |
elseif rhythm == "AT" |
|
|
43 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\AtrialTachycardia"; |
|
|
44 |
elseif rhythm == "AVNRT" |
|
|
45 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\AtrioventricularNodeReentrantTachycardia"; |
|
|
46 |
elseif rhythm == "AVRT" |
|
|
47 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\AtrioventricularReentrantTachycardia"; |
|
|
48 |
elseif rhythm == "SAAWR" |
|
|
49 |
filepath = "C:\Users\tripats\Documents\Biomedical Signal Analysis\Grad Single Project\ECG\SinusAtriumtoAtrialWanderingRhythm"; |
|
|
50 |
end |
|
|
51 |
|
|
|
52 |
EKG = processed_data; |
|
|
53 |
Leadc = {'I','II','III','aV_R','aV_L','aV_F','V_1','V_2','V_3','V_4','V_5','V_6'}; |
|
|
54 |
figu = figure('Visible','off'); |
|
|
55 |
e = 1; |
|
|
56 |
for f = 1:4 |
|
|
57 |
for g = 1:4:9 |
|
|
58 |
sbpt = (f-1)+g; |
|
|
59 |
subplot(3,4,sbpt) |
|
|
60 |
plot(EKG(1:1500,e)) |
|
|
61 |
title(Leadc{e}) |
|
|
62 |
grid |
|
|
63 |
e = e+1; |
|
|
64 |
end |
|
|
65 |
end |
|
|
66 |
|
|
|
67 |
figu.Position = [0 0 512 512]; |
|
|
68 |
saveas(figu, fullfile(strcat(filepath,'\',filename,'.png'))) |
|
|
69 |
end |