-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop_fmrib_qrsdetect.m
137 lines (119 loc) · 3.87 KB
/
pop_fmrib_qrsdetect.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
% pop_fmrib_qrsdetect() - GUI for fmrib_qrsdetect:
% Detect QRS events from ECG channel and add them to
% EEGLAB data event structure.
%
% Usage:
% >> [EEGOUT, COM] = pop_fmrib_qrsdetec(EEG) % for gui
% or >> [EEGOUT, COM] = pop_fmrib_qrsdetec(EEG,ecgchan,'ename','yes')
% for command line. 'no' or 'yes' can be used in the last argument:
%
% ecgchan: is the ecg channel number
% 'ename': event name to call the found peaks
% 'yes' or 'no': do you want to delete ecg channel?
%
% Inputs: EEG data structure
%
% GUI:
% Enter ECG Channel Number: ECG Data channel to extract QRS peaks from.
% What would you like to name the QRS events?: Event type to assign to
% the QRS peaks detected.
% Delete ECG channel when finished (yes/no)?: I think this is obvious!
%
%
% Author: Rami Niazy, FMRIB Centre, University of Oxford.
%
%
%
% Copyright (c) 2004 University of Oxford.
%
% Copyright (C) 2004 University of Oxford
% Author: Rami K. Niazy, FMRIB Centre
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% Last update:
% Oct 26, 2004
function [EEGOUT, command] = pop_fmrib_qrsdetect(EEG,varargin);
EEGOUT = [];
command = '';
% check inputs
%--------------------
nargchk(1,4,nargin);
if nargin>1 & nargin<4
error('incorrect input arguments','Please see help.');
end
if isempty(EEG.data)
errordlg2(strvcat('Error: no data'), 'Error');
error('pop_fmrib_qrsdetect error: no data','fmrib_qrsdetect() error!'); return;
end
% check for DSP Toolbox
%----------------------
if ~exist('firls')
error('QRS event detection requires the signal processing toolbox.','fmrib_qrsdetect() error!');
end
%Launch user input GUI and get inputs
%------------------------------------
if nargin ==1
prompt={'Enter ECG channel number:','What would you like to name the QRS events?','Delete ECG channel when finished (yes/no)?'};
def={'','qrs','no'};
dlgtitle='pop_fmrib_qrsdetect()';
helpfunc='fmrib_qrsdetect';
answer=inputdlg2(prompt,dlgtitle,1,def,helpfunc);
if ~isempty(answer)
ecgchan=str2num(char(answer(1)));
qrsevent=char(answer(2));
ecgdel=char(answer(3));
else
return;
end
else
ecgchan=varargin{1};
qrsevent=varargin{2};
ecgdel=varargin{3};
end
%Detect QRS
%----------
fprintf('\nFinding QRS Peaks...\n');
Peaks=fmrib_qrsdetect(EEG,ecgchan);
%Add Peaks to events
%-------------------
fprintf('Writing QRS events to event structure...\n');
for index = 1:length(Peaks)
EEG.event(end+1).type = qrsevent;
EEG.event(end).latency = Peaks(index);
if EEG.trials > 1 | isfield(EEG.event, 'epoch');
EEG.event(end).epoch = 1+floor((EEG.event(end).latency-1) / EEG.pnts);
end
end
if EEG.trials > 1
EEG = pop_editeventvals( EEG, 'sort', { 'epoch' 0 'latency', [0] } );
else
EEG = pop_editeventvals( EEG, 'sort', { 'latency', [0] } );
end
if isfield(EEG.event, 'urevent')
EEG.event = rmfield(EEG.event, 'urevent');
end
EEG = eeg_checkset(EEG, 'eventconsistency');
EEG = eeg_checkset(EEG, 'makeur');
% delete ECG channel
% ---------------
if strcmp(lower(ecgdel), 'yes')
EEG = pop_select(EEG, 'nochannel', ecgchan);
end
%return command
%--------------
EEGOUT=eeg_checkset(EEG);
command = sprintf('EEG=pop_fmrib_qrsdetect(EEG,%d,''%s'',''%s'')',ecgchan,qrsevent,ecgdel);
return;