-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpspm_get_biosemi.m
84 lines (72 loc) · 2.46 KB
/
pspm_get_biosemi.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
function [sts, import, sourceinfo] = pspm_get_biosemi(datafile, import)
% ● Description
% pspm_get_biosemi is the main function for import of BioSemi bdf files
% this function uses fieldtrip fileio functions
% ● Format
% [sts, import, sourceinfo] = pspm_get_biosemi(datafile, import);
% ● Arguments
% datafile:
% ┌─────import:
% ├────.typeno:
% ├───.channel:
% ├────────.sr:
% ├──────.data:
% ├────.marker:
% └.markerinfo:
% ├───.value:
% └────.name:
% ● History
% Introduced in PsPM 3.0
% Written in 2008-2015 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;
addpath(pspm_path('Import','fieldtrip','fileio'));
sourceinfo = [];
% get external file, using fieldtrip
% -------------------------------------------------------------------------
hdr = ft_read_header(datafile);
indata = ft_read_data(datafile);
try mrk = ft_read_event(datafile); catch, mrk = []; end;
% extract individual channels
% -------------------------------------------------------------------------
for k = 1:numel(import)
if strcmpi(settings.channeltypes(import{k}.typeno).data, 'wave')
% channel number ---
if import{k}.channel > 0
channel = import{k}.channel;
else
channel = pspm_find_channel(hdr.label, import{k}.type);
if channel < 1, return; end;
end;
if channel > size(indata, 1), warning('ID:channel_not_contained_in_file', 'Channel %02.0f not contained in file %s.\n', channel, datafile); return; end;
sourceinfo.channel{k, 1} = sprintf('Channel %02.0f: %s', channel, hdr.label{channel});
% sample rate ---
import{k}.sr = hdr.Fs;
% get data ---
import{k}.data = indata(channel, :);
else % event channels
% time unit
import{k}.sr = 1./hdr.Fs;
if ~isempty(mrk)
import{k}.data = [mrk(:).sample];
import{k}.marker = 'timestamps';
import{k}.markerinfo.value = [mrk(:).value];
import{k}.markerinfo.name = {mrk(:).type};
else
import{k}.data = [];
import{k}.marker = 'timestamps';
import{k}.markerinfo.value = [];
import{k}.markerinfo.name = [];
end;
end;
end;
% clear path and return
% -------------------------------------------------------------------------
rmpath(pspm_path('Import','fieldtrip','fileio'));
sts = 1;
return