Commit 7fccde1e authored by Bruno Colombet's avatar Bruno Colombet

Finished implementing read function

parent ea6e484d
# matlab_ades
MATLAB functions to read/write ADES file format.
\ No newline at end of file
# matlab_ades
MATLAB functions to read/write ADES file format.
Read ADES file:
infos = aw_read_ades(filePath);
infos.labels : cell array of strings => electrodes labels.
infos.types : corresponding channel types.
infos.units : correspinding amplitude units.
infos.srate : sampling rate of data (Hz)
infos.n_samples : number of samples per channel.
infos.date : acquisition date. (optional)
infos.time : acquisition time. (optional)
\ No newline at end of file
......@@ -9,14 +9,30 @@ if ~strcmpi(line, '#ADES HEADER FILE')
error('Invalid ADES header');
end
types = containers.Map;
units = containers.Map;
% default units for types
units('SEEG') = 'V';
units('EEG') = 'V';
units('ECG') = 'V';
units('EMG') = 'V';
units('ECOG') = 'V';
units('MEG') = 'T';
units('GRAD') = 'T/m';
units('TRIGGER') = 'n/a';
units('OTHER') = 'n/a';
units('ICA') = 'n/a';
units('SOURCE') = 'n/a';
units('REFERENCE') = 'T';
channels = containers.Map;
electrodes = containers.List;
infos.labels = {};
infos.types = {};
infos.units = {};
value = '';
while ~feof(fid)
line = fgetl(fid);
tokens = split(deblank(line), '=');
tokens = deblank(tokens);
tokens = split(line, '=');
tokens = strip(tokens);
key = tokens{1, 1};
if numel(tokens) == 2
value = tokens{2, 1};
......@@ -27,11 +43,10 @@ while ~feof(fid)
infos.srate = str2double(value);
elseif strcmpi(key, 'UNIT') && ~isempty(value)
% get type
unit_tokens = deblank(split(value, ','));
unit_tokens = split(value, ',');
unit_tokens = strip(unit_tokens);
if numel(unit_tokens) == 2
type = unit_tokens(1);
unit = unit_tokens(2);
types(type) = unit;
units(unit_tokens(1)) = unit_tokens(2);
end
elseif strcmpi(key, 'DATE')
infos.date = value;
......@@ -44,10 +59,19 @@ while ~feof(fid)
value = 'EEG';
end
channels(key) = value;
electrodes.append(key);
infos.labels{ 1, end + 1} = key;
infos.types{1, end + 1} = value;
infos.units{1, end + 1} = units(value);
end
end
infos.labels = electrodes.values();
% look for data file
dataPath = replace(path, '.ades', '.dat');
data_fid = fopen(dataPath, 'rb');
infos.data = fread(data_fid, [size(infos.labels, 2) infos.n_samples] , 'float32');
fclose(data_fid);
% apply gain factors depending on units specified
fclose(fid);
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment