Switch to unified view

a b/featurebased-approach/subfunctions/ecgsqi.m
1
function feats = ecgsqi(signal,qrs,fs)
2
% This function calculates multiple SQIs for electrocardiogram (ECG) signals.
3
%
4
% Input:
5
%     signal            ECG signal (function only supports vectors)
6
%     fs                sampling frequency (in Hz)
7
%
8
% Output:
9
%     sqi               Resulting SQI for ABP signal
10
%    qrs_out            QRS samplestamps
11
%
12
%
13
% --
14
% ECG classification from single-lead segments using Deep Convolutional Neural 
15
% Networks and Feature-Based Approaches - December 2017
16
% 
17
% Released under the GNU General Public License
18
%
19
% Copyright (C) 2017  Fernando Andreotti, Oliver Carr
20
% University of Oxford, Insitute of Biomedical Engineering, CIBIM Lab - Oxford 2017
21
% fernando.andreotti@eng.ox.ac.uk
22
%
23
% 
24
% For more information visit: https://github.com/fernandoandreotti/cinc-challenge2017
25
% 
26
% Referencing this work
27
%
28
% Andreotti, F., Carr, O., Pimentel, M.A.F., Mahdi, A., & De Vos, M. (2017). 
29
% Comparing Feature Based Classifiers and Convolutional Neural Networks to Detect 
30
% Arrhythmia from Short Segments of ECG. In Computing in Cardiology. Rennes (France).
31
%
32
% Last updated : December 2017
33
% 
34
% This program is free software: you can redistribute it and/or modify
35
% it under the terms of the GNU General Public License as published by
36
% the Free Software Foundation, either version 3 of the License, or
37
% (at your option) any later version.
38
% 
39
% This program is distributed in the hope that it will be useful,
40
% but WITHOUT ANY WARRANTY; without even the implied warranty of
41
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
% GNU General Public License for more details.
43
% 
44
% You should have received a copy of the GNU General Public License
45
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
46
47
%% Parameters
48
WIN_ACCEPT = 0.10;    % acceptance interval for FP in QRS detection (in s)
49
WIN_QRS = 0.1;         % window used to delimit QRS complexes (in s)
50
51
% Temporal SQIs
52
% feat_flat = flatsqi(signal);  % flatline detection
53
feat_stdsqi  = stdsqi(signal);   % standard deviation
54
feat_ksqi  = ksqi(signal);   % standard deviation
55
feat_ssqi  = ssqi(signal);   % standard deviation
56
57
% Frequency bands
58
feat_psqi = psqi(signal,fs,[15 45],[0 100]);
59
60
% Detection-based SQIs
61
combs = nchoosek(1:length(qrs),2);
62
combs = num2cell(combs,2);
63
feat_bsqi = cellfun(@(x) bsqi(qrs{x(1)},qrs{x(2)},WIN_ACCEPT,fs),combs);
64
feat_rsqi = arrayfun(@(x) rsqi(qrs{x},fs,0.96),1:length(qrs));
65
feat_csqi = arrayfun(@(x) csqi(signal,qrs{x},fs,WIN_QRS),1:length(qrs));
66
feat_xsqi = arrayfun(@(x) xsqi(signal,qrs{x},fs,WIN_QRS),1:length(qrs));
67
68
69
feats = [feat_stdsqi, feat_ksqi, feat_ssqi, ...
70
    feat_psqi, feat_bsqi', feat_rsqi, feat_csqi, feat_xsqi];
71
72
feats(isnan(feats)) = 0; % making sure there are no NaNs
73
74
75
76