-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCKC_reader_Max_reader_128_poly5.m
112 lines (101 loc) · 3.8 KB
/
CKC_reader_Max_reader_128_poly5.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function data = CKC_reader_Max_reader_128_poly5(filepath,filename,epoch_length,options)
%CKC_READER_MAX_READER_128_POLY5_GUI_BUGFIX For reading surface EMG acquired by TMSi-SAGA using Polybench and 4x 64 8x8 standard PCB grids.
%
% SYNTAX:
% data = CKC_reader_Max_reader_128_poly5_gui_bugfix(filepath, filename, epoch_length, 'Name', value, ...);
%
% INPUTS:
% - filepath: directory with the SIG file to be loaded.
% - filename: EMG file to be loaded.
% - epoch_length: (optional) length of the epoch of signal to be loaded (in s)
%
% OPTIONS:
% ChannelMap {mustBeMember(options.ChannelMap,{'default_tmsi_pcb_64.mat','default_tmsi_pcb_128.mat','default_tmsi_pcb_254_gui_bugfix.mat'default_tmsi_pcb_256.mat'})} = 'default_tmsi_pcb_254_gui_bugfix.mat';
% RawChannelMap = [];
% ID = [];
% IED (1,1) {mustBeNumeric, mustBePositive} = 8;
% Montage {mustBeTextScalar, mustBeMember(options.Montage,{'MONO','SD'})} = 'SD';
% SampleRate (1,1) {mustBeNumeric, mustBePositive} = 4000;
% Description {mustBeTextScalar} = "No description given.";
% AUXchannels = [];
% REFchannels = [];
%
% OUTPUT:
% data: structure with the following fields;
% SIG - two dimensional cell array with surface EMG channel in each
% cell - SIG{r,c} is the channel in row r and column c. Missing
% electrodes are denoted by empty arrays, e.g. SIG{1,1} = [];
% fsamp - sampling frequency of sEMG
% signal_length - length of a surface EMG signals (in samples)
% montage - montage of electrodes - 'MONO' for monopolar, 'SD' for
% single differential
% IED - inter-electrode distance (in mm)
% ref_signal - measured reference signal (e.g. force) when avalable, empty array otherwise
% AUXchannels - auxilary channels (currently not used by DEMUSEtool
% description - text describing the data
%
% Adapted: Max Murphy 2024-04-25
arguments
filepath
filename
epoch_length (1,1) = inf;
options.ChannelMap {mustBeMember(options.ChannelMap,{'default_tmsi_pcb_64.mat','default_tmsi_pcb_128.mat','default_tmsi_pcb_254_gui_bugfix.mat','default_tmsi_pcb_256.mat'})} = 'default_tmsi_pcb_254_gui_bugfix.mat';
options.RawChannelMap = reshape(1:128,8,16);
options.ID = [];
options.IED (1,1) {mustBeNumeric, mustBePositive} = 8.75; % mm
options.Montage {mustBeTextScalar, mustBeMember(options.Montage,{'MONO','SD'})} = 'MONO';
options.SampleRate (1,1) {mustBeNumeric, mustBePositive} = 2000;
options.Description char {mustBeTextScalar} = 'No description given.';
options.AUXchannels = [];
options.REFchannels = [];
end
f=load(fullfile(filepath,filename));
if ~isinf(epoch_length)
f.uni = f.uni(:,1:min(size(f.uni,2),epoch_length));
end
if ~isempty(options.RawChannelMap)
channelMap = options.RawChannelMap;
else
channelMap = getfield(load(options.ChannelMap,'channelMap'),'channelMap');
end
data.SIG = cell(size(channelMap));
n = size(f.uni,2);
for ii=1:numel(channelMap) % electrode array
if channelMap(ii) > 0
data.SIG{ii} = f.uni(channelMap(ii),:);
else
data.SIG{ii} = zeros(1,n);
end
end
if isempty(options.REFchannels)
if isfield(f, 'sync')
data.ref_signal = f.sync;
else
data.ref_signal = [];
end
else
data.ref_signal = options.REFchannels;
end
data.signal_length = n;
data.montage = options.Montage;
data.IED = options.IED;
if isfield(f,'sample_rate')
data.fsamp = f.sample_rate;
else
data.fsamp = options.SampleRate;
end
if isempty(options.AUXchannels)
if isfield(f, 'x') && isfield(f,'y')
data.AUXchannels = [f.x; f.y];
else
data.AUXchannels = [];
end
else
data.AUXchannels = options.AUXchannels;
end
if isfield(f,'description')
data.description = char(f.description);
else
data.description = options.Description;
end
end