-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpspm_get_brainvis.m
87 lines (76 loc) · 2.61 KB
/
pspm_get_brainvis.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
function [sts, import, sourceinfo] = pspm_get_brainvis(datafile, import)
% ● Description
% pspm_get_brainvis is the main function for import of BrainVision files
% this function uses fieldtrip fileio functions
% ● Format
% [sts, import, sourceinfo] = pspm_get_brainvis(datafile, import);
% ● Arguments
% datafile:
% import:
% ● Developer's Note
% I did not have sample files, simply assumed that hdr.labels would be
% a cell array - might have to be changed in lines 38 and 41
% ● 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 = [];
addpath(pspm_path('Import','fieldtrip','fileio'));
% get data
% -------------------------------------------------------------------------
hdr = ft_read_header(datafile);
indata = ft_read_data(datafile);
try mrk = ft_read_event(datafile); catch, mrk = []; end;
% extract individual channels
% -------------------------------------------------------------------------
% loop through import jobs
for k = 1:numel(import)
if strcmpi(settings.channeltypes(import{k}.typeno).data, 'wave')
% define 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 > numel(hdr.label), 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 % marker channels: get the ascending flank of each marker
sourceinfo.channel{k, 1} = 'Automatically extracted marker recordings';
% time unit
import{k}.sr = 1./hdr.Fs;
import{k}.marker = 'timestamps';
import{k}.data = [mrk.sample];
m_val = {mrk.value};
val_length = length(m_val);
val = cell(val_length, 1);
% convert empty cells into empty strings
for i=1:val_length
v = m_val{i};
if ~ischar(v) && isempty(v)
val{i} = '';
else
val{i} = v;
end;
end;
% convert into double
num_val = str2double(regexprep(val, '[^0-9]*([0-9,.]*)', '$1'));
import{k}.markerinfo.value = num_val;
import{k}.markerinfo.name = {mrk.type}';
end;
end;
% clear path
rmpath(pspm_path('Import','fieldtrip','fileio'));
%% return values
sts = 1;
end