-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpspm_get_biotrace.m
65 lines (60 loc) · 1.82 KB
/
pspm_get_biotrace.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
function [sts, import, sourceinfo] = pspm_get_biotrace(datafile, import)
% ● Description
% pspm_get_biotrace is the main function for import of text-exported
% Mindemedia BioTrace files
% ● Format
% [sts, import, sourceinfo] = pspm_get_biotrace(datafile, import);
% ● Arguments
% datafile:
% import:
% ● History
% Introduced in PsPM 3.0
% Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)
% Maintained in 2022 by Teddy Chao (UCL)
%% Initialise
global settings
if isempty(settings)
pspm_init;
end
sts = -1;
sourceinfo = [];
% get data
% -------------------------------------------------------------------------
fid = fopen(datafile);
bio.header = textscan(fid, '%s', 'Delimiter', '|');
fclose(fid);
fid = fopen(datafile);
bio.data = textscan(fid, '%n%s', 'Delimiter', '\t', 'HeaderLines', 14);
fclose(fid);
% extract individual channels
% -------------------------------------------------------------------------
% check sample rate ---
if isempty(strfind(bio.header{1}{1}, 'RAW'))
warning('Unrecognised data format\n.'); return
else
foo = regexp(bio.header{1}{7}, '\s', 'split');
sr = str2num(foo{3});
end;
% retrieve recording channel, date and time ---
foo = regexp(bio.header{1}{9}, ':', 'split');
sourceinfo.channel{1} = foo{2};
foo = regexp(bio.header{1}{4}, '\s', 'split');
sourceinfo.date = foo{2};
foo = regexp(bio.header{1}{5}, '\s', 'split');
sourceinfo.time = foo{2};
% loop through import jobs ---
for k = 1:numel(import)
if strcmpi(import{k}.type, 'marker')
foo = char(bio.data{end});
import{k}.data = find(foo(:, 1) ~= ' ');
import{k}.sr = 1/sr;
import{k}.marker = 'timestamp';
import{k}.markerinfo.name = bio.data{end}{import{k}.data};
else
import{k}.data = bio.data{1};
import{k}.sr = sr;
end;
end;
%% Return values
sts = 1;
return