-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added bbci_recordSignals and required functions
fixed some functions that were adapted to the new toolbox before
- Loading branch information
1 parent
e7260cc
commit 6c561ee
Showing
9 changed files
with
191 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
function file_writeBVheader(file, varargin) | ||
% FILE_WRITEBVHEADER - Write Header in BrainVision Format | ||
% | ||
% Synopsis: | ||
% file_writeBVheader(FILE, 'Property1', Value1, ...) | ||
% | ||
% Arguments: | ||
% FILE: string containing filename to save in. | ||
% | ||
% Properties: | ||
% 'Fs': sampling interval of raw data, required | ||
% 'CLab': cell array, channel labels, required | ||
% 'Scale': scaling factors for each channel, required | ||
% 'DataPoints': number of datapoints, required | ||
% 'Precision': precision (default 'int16') | ||
% 'DataFile': name of corresponding .eeg file (default FILE) | ||
% 'MarkerFile': name of corresponding .mrk file (default FILE) | ||
% 'Impedances': for each channel | ||
% | ||
% See also: file_* | ||
|
||
|
||
global BBCI | ||
|
||
props= {'Folder' BBCI.TmpDir 'CHAR'}; | ||
opt= opt_proplistToStruct(varargin{:}); | ||
opt= opt_setDefaults(opt, props); | ||
|
||
if fileutil_isAbsolutePath(file), | ||
fullName= file; | ||
else | ||
fullName= fullfile(opt.export_dir, file); | ||
end | ||
|
||
[pathstr, fileName]= fileparts(fullName); | ||
props= {'Precision' 'int16' 'CHAR(int16 int32 single double float32 float64)' | ||
'DataFile' fileName 'CHAR' | ||
'MarkerFile' fileName 'CHAR' | ||
'Impedances' [] 'DOUBLE'}; | ||
opt= opt_setDefaults(opt, props); | ||
|
||
if ~ischar(opt.DataPoints), %% not sure, why DataPoints is a string | ||
opt.DataPoints= sprintf('%d', opt.DataPoints); | ||
end | ||
|
||
fid= fopen([fullName '.vhdr'], 'w','b'); | ||
if fid==-1, error(sprintf('cannot write to %s.vhdr', fullName)); end | ||
fprintf(fid, ['Brain Vision Data Exchange Header File Version 1.0' 13 10]); | ||
fprintf(fid, ['; Data exported from BBCI Matlab Toolbox' 13 10]); | ||
fprintf(fid, [13 10 '[Common Infos]' 13 10]); | ||
fprintf(fid, ['DataFile=%s.eeg' 13 10], opt.DataFile); | ||
fprintf(fid, ['MarkerFile=%s.vmrk' 13 10], opt.MarkerFile); | ||
fprintf(fid, ['DataFormat=BINARY' 13 10]); | ||
fprintf(fid, ['DataOrientation=MULTIPLEXED' 13 10]); | ||
fprintf(fid, ['NumberOfChannels=%d' 13 10], length(opt.CLab)); | ||
fprintf(fid, ['DataPoints=%s' 13 10], opt.DataPoints); | ||
fprintf(fid, ['SamplingInterval=%g' 13 10], 1000000/opt.Fs); | ||
fprintf(fid, [13 10 '[Binary Infos]' 13 10]); | ||
switch(lower(opt.Precision)), | ||
case 'int16', | ||
fprintf(fid, ['BinaryFormat=INT_16' 13 10]); | ||
fprintf(fid, ['UseBigEndianOrder=NO' 13 10]); | ||
case 'int32', | ||
fprintf(fid, ['BinaryFormat=INT_32' 13 10]); | ||
fprintf(fid, ['UseBigEndianOrder=NO' 13 10]); | ||
case {'float32','single','float'}, | ||
fprintf(fid, ['BinaryFormat=IEEE_FLOAT_32' 13 10]); | ||
case {'float64','double'}, | ||
fprintf(fid, ['BinaryFormat=IEEE_FLOAT_64' 13 10]); | ||
otherwise, | ||
error(['Unknown precision, not implemented yet: ' opt.Precision]); | ||
end | ||
fprintf(fid, [13 10 '[Channel Infos]' 13 10]); | ||
for ic= 1:length(opt.CLab), | ||
fprintf(fid, ['Ch%d=%s,,%g' 13 10], ic, opt.CLab{ic}, ... | ||
opt.Scale(min(ic,end))); | ||
end | ||
fprintf(fid, ['' 13 10]); | ||
|
||
if ~isempty(opt.Impedances), | ||
fprintf(fid, ['Impedance [kOhm].' 13 10]); | ||
for ic= 1:length(opt.CLab) | ||
if isinf(opt.Impedances(ic)) | ||
fprintf(fid, [opt.CLab{ic} ': Out of Range!' 13 10]); | ||
else | ||
fprintf(fid, [opt.CLab{ic} ': ' num2str(opt.Impedances(ic)) 13 10]); | ||
end | ||
end | ||
end | ||
|
||
fclose(fid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function data= bbci_recordSignals(bbci_in, filename) | ||
%BBCI_RECORDSIGNALS - Record acquired brain signals | ||
% | ||
%Synopsis: | ||
% DATA= bbci_recordSignals(BBCI, BASENAME) | ||
% | ||
%Arguments: | ||
% BBCI: Type 'help bbci_apply_structures' to get a description of the | ||
% structure 'bbci'. This function only uses the fields | ||
% 'source': while defines the data acquisition, and | ||
% 'quit_condition' | ||
% BASENAME: Basename of the files. Nummers are appended in order to avoid | ||
% overwriting. | ||
|
||
if nargin<2, | ||
filename= '/tmp/bbci_recording'; | ||
end | ||
|
||
bbci= struct_copyFields(bbci_in, {'source','quit_condition'}); | ||
bbci.feature.ival= [-100 0]; | ||
|
||
%default_param= {'internal',1, 'precision','double'}; | ||
default_param= {'internal',1}; | ||
props= {'record_signals' 1 'BOOL', | ||
'record_basename' filename 'CHAR', | ||
'record_param' default_param 'PROPLIST'}; | ||
bbci.source= opt_setDefaults(bbci.source, props); | ||
|
||
fprintf('Recording started.\n'); | ||
|
||
bbci= bbci_apply_setDefaults(bbci); | ||
[data, bbci]= bbci_apply_initData(bbci); | ||
run= true; | ||
while run, | ||
[data.source, data.marker]= ... | ||
bbci_apply_acquireData(data.source, bbci.source, data.marker); | ||
if ~data.source.state.running, | ||
break; | ||
end | ||
data.marker.current_time= data.source.time; | ||
run= bbci_apply_evalQuitCondition(data.marker, bbci); | ||
end | ||
bbci_apply_close(bbci, data); | ||
|
||
fprintf('Recording finished -> %s\n', data.source.record.filename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
C= 2; | ||
T= 10000; | ||
cnt= struct('fs', 100); | ||
cnt.x= 50*randn(T, C); | ||
cnt.clab= cprintf('Ch%d', 1:C); | ||
|
||
M= 100; | ||
mrk= struct; %('fs', cnt.fs); | ||
mrk.time= round(linspace(0, T/cnt.fs*1000, M+2)); | ||
mrk.time([1 end])= []; | ||
%mrk.desc= cprintf('S%3d', ceil(rand(1,M)*10))'; | ||
mrk.desc= ceil(rand(1,M)*10); | ||
|
||
|
||
% --- Setup a very simple system for (simulated) online processing | ||
bbci= struct; | ||
bbci.source.acquire_fcn= @bbci_acquire_offline; | ||
bbci.source.acquire_param= {cnt, mrk}; | ||
bbci.source.log.output= 'screen'; | ||
data= bbci_recordSignals(bbci, '/tmp/rec_test'); | ||
|
||
[cnt_re, mrk_re]= file_readBV(data.source.record.filename); | ||
|
||
isequal(cnt.clab, cnt_re.clab) | ||
max(abs(cnt.x(:)-cnt_re.x(:))) | ||
|
||
isequal(mrk.pos, mrk_re.pos(2:end)) | ||
isequal(mrk.desc, mrk_re.desc(2:end)) | ||
|