-
Notifications
You must be signed in to change notification settings - Fork 9
/
Frequency-domain Analysis of Heart Sounds.m
311 lines (240 loc) · 14.4 KB
/
Frequency-domain Analysis of Heart Sounds.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
% Frequency-domain Analysis of Heart Sounds
close all; clear all; clc; % Clear everything
% -------------------------------------------------------------------------
% ---------------------------------------------------------------- pec1.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec1.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec1.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec1.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
% Find the Sync Average of the PSDs for each segment
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec1.wav'); % Make an audio wave file of the PCG signal
% -------------------------------------------------------------------------
% ---------------------------------------------------------------- pec1.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec1.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec1.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec1.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
% Find the Sync Average of the PSDs for each segment
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec1.wav'); % Make an audio wave file of the PCG signal
% -------------------------------------------------------------------------
% --------------------------------------------------------------- pec22.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec22.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec22.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec22.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% Find the Sync Average of the PSDs for each segment
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec22.wav'); % Make an audio wave file of the PCG signal
% -------------------------------------------------------------------------
% --------------------------------------------------------------- pec33.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec33.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec33.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec33.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
% Find the Sync Average of the PSDs for each segment
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec33.wav'); % Make an audio wave file of the PCG signal
% -------------------------------------------------------------------------
% -------------------------------------------------------------- pec41.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec41.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec41.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec41.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
% Find the Sync Average of the PSDs for each segment
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec44.wav'); % Make an audio wave file of the PCG signal
% -------------------------------------------------------------------------
% --------------------------------------------------------------- pec42.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec42.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec42.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec42.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
% Find the Sync Average of the PSDs for each segment
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec42.wav'); % Make an audio wave file of the PCG signal
% -------------------------------------------------------------------------
% --------------------------------------------------------------- pec52.dat
% -------------------------------------------------------------------------
% ------------------------------------------------------- Part 1: Load File
Signal = load('pec52.dat'); % loading ascii file into an array
% Separating pcg, ecg, and carotid signals
PCG = Signal(:,1);
ECG = Signal(:,2);
Carotid = Signal(:,3);
Fs = 1000; % Sampling frequency is 1000Hz
TimeAxis = [1:length(PCG)]/Fs;
% ----------------------------------------------------- Part 2: Segment PCG
DownSampledECG = DownSample(ECG, Fs); % Down sample ECG signal to 200 Hz
DownSampledTimeAxis = TimeAxis(5:5:end); % Takes every fifth sample
% Apply the Pan–Tompkins algorithmto the ECG signal and detect the QRS complexes.
QRSPeakIndex = FindQRS(DownSampledECG, DownSampledTimeAxis, Fs);
% starting from the beginning of each QRS complex.
QRSBeginIndex = FindQRSBegin(DownSampledECG, DownSampledTimeAxis, QRSPeakIndex, Fs);
QRSBeginIndex = QRSBeginIndex * 5; % Rescale the sample index up to 1000 Hz
% Segment the systolic portions of the PCG signal by selecting a window of duration 300 − 350 ms
PCGS1BeginIndex = QRSBeginIndex;
PCGS1EndIndex = QRSBeginIndex + 300; % 300 ms = 350 samples
% Plot PCG with S1 segments indicated
PCGS1Segmented = figure('Name','Pec52.dat - PCG with S1 sounds segmented'); % Create a new figure
plot(TimeAxis, PCG); hold on;
plot(TimeAxis(PCGS1BeginIndex), PCG(PCGS1BeginIndex), 'r*');
plot(TimeAxis(PCGS1EndIndex), PCG(PCGS1EndIndex), 'r+'); hold off;
title('pec52.dat - PCG with S1 sounds segmented (w/ segment starts red "*" ends red "+"');
xlabel('Time (Sec)'); ylabel('PCG (Mv)'); axis auto;
% --------------------------------------- Part 3: Sync average segment PSDs
% Find the Sync Average of the PSDs for each segment
SegmentPSDSyncAve(PCG,PCGS1BeginIndex, PCGS1EndIndex, Fs)
% ----------------------------------------------- Part 4: Create Audio file
MakeWave(PCG, 'pec52.wav'); % Make an audio wave file of the PCG signal