-
Notifications
You must be signed in to change notification settings - Fork 1
/
m_411_pan_tompkins.m~
143 lines (98 loc) · 2.74 KB
/
m_411_pan_tompkins.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
clear all;
close all;
clc;
%% Load Signals
load('ecg_normal_1.mat');
fs1 = Fs;
ecg1 = ecg;
tmin = 1;
tmax = 5;
ecg1_4sec = ecg1(tmin*fs1:tmax*fs1-1);
t_axis = tmin:1/fs1:tmax-(1/fs1);
%% Load Filters
load('h1.mat');
den1 = h1Den;
num1 = h1Num;
load('h2.mat');
den2 = h2Den;
num2 = h2Num;
%% Plot frequency reponse of h1 h2 and its corresponding band-pass
figure
freqz(num1, den1, 256, 1024);
title('low-pass filter frequency reponse');
figure
freqz(num2, den2, 256, 1024);
title('high-pass filter frequency response');
figure
freqz(conv(num1, num2), conv(den1, den2), 256, 1024);
title('resulting band-pass filter frequency response');
%% a) ECG filtering
figure
plot(t_axis, ecg1_4sec);
title('ECG Normal 1');
xlabel('time (s)');
ylabel('Voltage');
figure
plot(t_axis, fftshift(abs(fft(ecg1_4sec))));
title('Frequecy Spectrum of ECG Normal');
xlabel('time (s)');
ylabel('Amplitude');
ecg1_filtered1 = filter(num1, den1, ecg1_4sec);
figure
plot(t_axis, ecg1_filtered1);
title('ECG Normal 1 after filtered by low-pass filter');
xlabel('time (s)');
ylabel('Voltage');
figure
plot(t_axis, fftshift(abs(fft(ecg1_filtered1))));
title('Frequecy Spectrum of ECG Normal 1 after filtered by low-pass filter');
xlabel('time (s)');
ylabel('Amplitude');
ecg1_filtered2 = filter(num2, den2, ecg1_filtered1);
figure
plot(t_axis, ecg1_filtered2);
title('ECG Normal 1 after filtered by band-pass filter');
xlabel('time (s)');
ylabel('Voltage');
figure
plot(t_axis, fftshift(abs(fft(ecg1_filtered2))));
title('Frequecy Spectrum of ECG Normal 1 after filtered by band-pass filter');
xlabel('time (s)');
ylabel('Amplitude');
%% b) differentiation filter
b = [1 2 0 -2 -1];
a = [1];
a = a*8*(1/fs1);
freqz(b,a, 256, 1024);
title('derivative filter frequency response');
ecg1_filtered3 = filter(b, a, ecg1_filtered2);
figure
plot(t_axis, ecg1_filtered3);
title('ECG Normal 1 after filtered by derivative filter');
xlabel('time (s)');
ylabel('Voltage ');
figure
plot(t_axis, fftshift(abs(fft(ecg1_filtered3))));
title('Frequecy Spectrum of ECG Normal 1 after filtered by derivative filter');
xlabel('time (s)');
ylabel('Amplitude');
%% c) Signal squared
ecg1_filtered4 = abs(ecg1_filtered3).^2;
figure
plot(t_axis, ecg1_filtered4);
title('ECG Normal 1 after being squared');
xlabel('time (s)');
ylabel('Voltage');
%% d) Window proposal
N = window_determination(ecg1_filtered4, 1*10^13);
door=(1/N)*ones(1,N);
smwi=conv(ecg1_filtered4,door);
figure;
plot(smwi);
title('ECG Normal 1 after integration step');
xlabel('time (s)');
ylabel('Voltage');
%% e) Threshold proposal and temporal determination
clc;
threshold = 4*10^13; %aproximatively proposed according to the graph of ecg1_filtered4
[temporal_locations, max_values] = find_local_max2(ecg1_filtered4, fs1, threshold, tmin);