/
biopac_acq.m
76 lines (66 loc) · 2.71 KB
/
biopac_acq.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
function varargout = biopac_acq(filename, hdr, begsample, endsample, chanindx)
% BIOPAC_ACQ is a wrapper to for the reading function from Mathworks file exchange.
%
% Use as
% hdr = biopac_acq(filename);
% dat = biopac_acq(filename, hdr, begsample, endsample, chanindx);
% evt = biopac_acq(filename, hdr);
%
% See also FT_FILETYPE, FT_READ_HEADER, FT_READ_DATA, FT_READ_EVENT
% See also BIDS_TSV, BIOPAC_ACQ, BUCN_TXT, EEGSYNTH_TSV, EVENTS_TSV, LIBERTY_CSV, MAUS_TEXTGRID, MOTION_C3D, OPENBCI_TXT, OPENPOSE_KEYPOINTS, OPENSIGNALS_TXT, OPENVIBE_MAT, OPM_FIL, QUALISYS_TSV, SCCN_XDF, SENSYS_CSV, SNIRF, UNICORN_CSV, XSENS_MVNX
% Copyright (C) 2018-2024 Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip 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 3 of the License, or
% (at your option) any later version.
%
% FieldTrip 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 FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$
persistent acq previous_fullname
% add fieldtrip/external/fileexchange to the path
ft_hastoolbox('fileexchange', 1);
needhdr = (nargin==1);
needevt = (nargin==2);
needdat = (nargin==5);
% use the full filename including path to distinguish between similarly named files in different directories
fullname = which(filename);
if isempty(previous_fullname) || ~isequal(fullname, previous_fullname)
% remember the full filename including path
previous_fullname = fullname;
% read the header and data
acq = load_acq(filename, false);
else
% use the persistent variable to speed up subsequent read operations
end
if needhdr
% convert to FieldTrip header representation
hdr.Fs = 1000/acq.hdr.graph.sample_time;
hdr.nChans = size(acq.data,2);
hdr.nSamples = size(acq.data,1);
hdr.nSamplesPre = 0;
hdr.nTrials = 1; % assume that it is a single continuous segment
for i=1:numel(acq.hdr.per_chan_data)
hdr.label{i} = acq.hdr.per_chan_data(i).comment_text;
end
hdr.orig = acq.hdr;
varargout{1} = hdr;
elseif needevt
% convert to FieldTrip event representation
event = [];
varargout{1} = event;
elseif needdat
% select the requested channels and samples from the data and transpose
dat = acq.data(begsample:endsample,chanindx)';
varargout{1} = dat;
end