forked from CoBrainImagingCenter/eegfmri
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriolog.m
More file actions
79 lines (70 loc) · 1.65 KB
/
triolog.m
File metadata and controls
79 lines (70 loc) · 1.65 KB
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
%!/usr/bin/octave
% read and parse Siemens Trio physio log files
% FvW 12/2017
function [t, data] = triolog(fname)
%disp(['[+] File: ' fname])
%disp('[+] Reading physio log...')
i = 1;
fid = fopen(fname);
tline = fgetl(fid);
filedata{i} = tline;
while ischar(tline)
tline = fgetl(fid);
i = i+1;
filedata{i} = tline;
end
fclose(fid);
n = length(filedata);
% --- find indices of keys ---
idx_logstart=0;
idx_logstop=0;
idx_samplerate=0;
for i=1:length(filedata)
if findstr(filedata{i}, 'Physiolog_START')
idx_logstart = i;
end
if findstr(filedata{i}, 'Physiolog_STOP')
idx_logstop = i;
end
if findstr(filedata{i}, 'Sampling_Rate')
idx_samplerate = i;
end
end
% --- parse sampling rate ---
l = filedata{idx_samplerate};
fs = str2num(l(findstr(l, ':')+2:end));
%fprintf('[+] Sampling rate: %0.2f Hz\n', fs)
%disp('[+] Parsing data...')
l = filedata{idx_samplerate+1};
%disp('[+] Splitting data values...')
sp = isspace(l);
if any(sp)
dw = diff(sp);
starts = [1, find(dw == -1) + 1];
stops = [find(dw == 1), length(l)];
n_values = numel(starts);
s = cell(1, n_values);
for i=1:n_values
s{i} = l(starts(i):stops(i));
end
else
s = {l};
end
% if you have at least Matlab2013b, you can substitute the
% last block of code, starting with 'sp = ', by:
% s = strsplit(l, ' ');
%disp('[+] Converting strings to numbers...')
data = [];
for i=1:length(s)
x = str2num(s{i});
if x
data = [data x];
end
end
%disp('[+] Deleting scanner triggers...')
trigs = [5000, 5002, 6000, 6002];
for trig=trigs
data(data==trig) = [];
end
% --- time axis ---
t = (0:length(data)-1)/fs;