-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKrishna_Swetha_code2.m
144 lines (131 loc) · 2.68 KB
/
Krishna_Swetha_code2.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
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
%plotting signal
x1 = csvread('a01_3.csv');
%display
t=0:27000:1
x= data(:,1); % you are reading signal to x1 variable but for rest of code you are using data variable. Rework on code.
y= data(:,2);
plot(x,y)
%filtering
fc= 100;
fs= 1000;
n= 4;
[b,a]= butter(n,2*fc/fs);
filtered = filter(b,a,data);
plot(filtered)
%
y=length(x1);
fs = 200;
N = length (x1);
t = [0:N-1]/fs;
figure(1)
subplot(2,1,1)
plot(t,x1)
subplot(2,1,2)
plot(t(200:600),x1(200:600))
xlim([1 3])
x1 = x1 - mean (x1 );
x1 = x1/ max( abs(x1 )) ;
figure(2)
subplot(2,1,1)
plot(t,x1)
subplot(2,1,2)
plot(t(200:600),x1(200:600))
xlim([1 3])
b=[1 0 0 0 0 0 -2 0 0 0 0 0 1];
a=[1 -2 1];
h=filter(b,a,[1 zeros(1,12)]);
x2 = conv (x1 ,h);
x2 = x2/ max( abs(x2 ));
figure(3)
subplot(2,1,1)
plot([0:length(x2)-1]/fs,x2)
xlim([0 max(t)])
subplot(2,1,2)
plot(t(200:600),x2(200:600))
xlim([1 3])
b = [-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1];
a = [1 -1];
h1=filter(b,a,[1 zeros(1,32)]);
x3 = conv (x2 ,h1);
x3 = x3/ max( abs(x3 ));
figure(4)
subplot(2,1,1)
plot([0:length(x3)-1]/fs,x3)
xlim([0 max(t)])
subplot(2,1,2)
plot(t(200:600),x3(200:600))
xlim([1 3])
h = [-1 -2 0 2 1]/8;
x4 = conv (x3 ,h);
x4 = x4 (2+[1: N]);
x4 = x4/ max( abs(x4 ));
figure(5)
subplot(2,1,1)
plot([0:length(x4)-1]/fs,x4)
subplot(2,1,2)
plot(t(200:600),x4(200:600))
xlim([1 3])
x5 = x4 .^2;
x5 = x5/ max( abs(x5 ));
figure(6)
subplot(2,1,1)
plot([0:length(x5)-1]/fs,x5)
subplot(2,1,2)
plot(t(200:600),x5(200:600))
xlim([1 3])
h = ones (1 ,31)/31;
Delay = 15;
x6 = conv (x5 ,h);
x6 = x6 (15+[1: N]);
x6 = x6/ max( abs(x6 ));
figure(7)
subplot(2,1,1)
plot([0:length(x6)-1]/fs,x6)
subplot(2,1,2)
plot(t(200:600),x6(200:600))
xlim([1 3])
figure(7)
subplot(2,1,1)
max1 = max(x6);
thresh = mean (x6 );
k=thresh*max1;
y =(x6>k)';
figure,plot(y,t)
figure (8)
subplot(2,1,1)
plot (t(200:600),x1(200:600)/max(x1))
box on
xlim([1 3])
subplot(2,1,2)
plot (t(200:600),x6(200:600)/max(x6))
xlim([1 3])
left = find(diff([0 y])==1);
right = find(diff([y 0])==-1);
left=left-20;
for i=1:length(left)
[Rv(i) Rl(i)] = max( x1(left(i):right(i)) );
Rl(i) = Rl(i)+left(i) ;
for j=1:20
x(j)=left(j);
for l=1:20;
k(l)=left(j)-left(j+1);
y=-1*mean2(k(l));
end
end
end
figure
plot (t,x1/max(x1) , t(Rl) ,Rv , 'r*');
xlim([1 3])
heartrate=(fs*60)/y;
tx=0:N-1/fs;
figure,plot(tx(200:600),x1(200:600))
disp('Heart rate is:::')
fprintf('%d\n', round(heartrate));
if (heartrate==72)
disp('Heart rate is normalL');
end
if(heartrate<72)
disp('Heart rate is below normal,subject is suffering from bradycadria');
else
disp('Heart rate is above normal,subject is suffering from trachycadria');
end