bdf_ChanOps

Function to read in, write, and perform any mathematical operation on BDFs.
292 Downloads
Updated 2 Oct 2013

View License

%% DESCRIPTION:
%
% Performs channel operations on Biosemi Data Files (BDFs). This proved
% useful when files are too big to open in their entirety due to high
% sampling rates or long experiment times.
%
% At its core, this function operates much as bdf_trim did, but in a much
% more flexible way. That is, this function can be used to trim files or
% perform more complex operations, like averaging over channels, etc.
%
% INPUT:
%
% IN: string, path to original BDF.
% OUT: string, path to trimmed BDF.
% CHANOPS: cell array, each element contains a mathematical evaluation
% string (e.g. '(A1 + A2)./2' to average channels A1 and A2).
% Note that channel names in CHANOPS must match the channel
% names in the BDF precisely.
%
% *Note*: Function assumes all channels included in a given
% operation -- that is, an element of the cell array -- are
% of the same transducer type and sampling rate. A safe
% assumption for EEG, but could be a problem for other
% applications.
% OCHLAB: cell array, output channel names. Must be the same length as
% CHANOPS. (optional input)
%
% OUTPUT:
%
% HDR: structure with the following fields
% IDCODE: identification code (8 bytes)
% LSID: local subject identification (80 bytes)
% LRID: local recording identification (80 bytes)
% SDATE: start date (8 bytes)
% STIME: start time (8 bytes)
% NBYTES: number of bytes in header (8 bytes)
% VDFRM: version data format (44 bytes; "24BIT" for BDF)
% NDREC: number of data records (8 bytes)
% DDREC: duration of data record in seconds (8 bytes)
% NCHAN: number of channels (4 bytes)
% CHLAB: channel labels (Nx16 bytes)
% TTYPE: transducer type (Nx80bytes)
% PHDIM: physical dimension of channels (Nx8 bytes)
% PHMIN: physical minimum in units (Nx8 bytes)
% PHMAX: physical maximim in units (Nx8bytes)
% DGMIN: digital minimum (Nx8 bytes)
% DGMAX: digital maximum (Nx8 bytes)
% PRFLT: prefiltering (Nx80 bytes)
% NSAMP: Number of samples in each data record (i.e. sample rate if
% DDREC=1 sec; Nx8 bytes)
% RESRV: reservered (Nx32 bytes)
%
% HEADER: header string of INput file.
% HEADEROUT: header string of OUTput file.
% DATA: Operated data.
%
%
% NOTES:
%
% 120626CWB: Function tested to read and write file as is (first pass
% sanity check). Linux command line "diff" function shows
% that original file is identical to output from
% bdf_ChanOps.m.
%
% IN='s3188/eeg/s3188_PEABR_Exp02C (6.79 msec).bdf';
% OUT='s3188/eeg/s3188_bdf_chanops.bdf';
% CHANOPS={'A1' 'A2' 'A3' 'A4' 'A5' 'A6' 'EXG1' 'EXG2' 'EXG3' 'EXG4' 'Status'};
% OCHLAB={'A1' 'A2' 'A3' 'A4' 'A5' 'A6' 'EXG1' 'EXG2' 'EXG3' 'EXG4' 'Status'};
%
% 120704CWB: Substantial rewrite of function, including addition of
% several smaller functions (e.g. BDF2DATA). Ran the command
% above to read in a file and rewrite it with no changes
% made. This led to no differences using the "diff" command.
%
% 120704CWB: Testing with average of first 6 channels and a single
% channel reference.
% IN='s3188/eeg/s3188_PEABR_Exp02C (6.79 msec).bdf';
% OUT='s3188/eeg/s3188_bdf_chanops.bdf';
% CHANOPS={'(A1+A2+A3+A4+A5+A6)./6' 'EXG1' 'Status'};
% OCHLAB={'Vertex' 'Reference' 'Status'};
%
% These data look great, but will NOT match EEGLAB perfectly.
% I fiddled around with this and it
% seems this is PROBABLY because BDFs have an inherent
% maximum resolution of ~0.0312 uV (at 24 bit resolution),
% while MATLAB has much greater precision when doing
% averaging, even with SINGLE precision.
%
% Bishop, Christopher W.
% UC Davis
% Miller Lab 2011
% cwbishop@ucdavis.edu

Cite As

Chris Bishop (2024). bdf_ChanOps (https://www.mathworks.com/matlabcentral/fileexchange/35761-bdf_chanops), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on EEG/MEG/ECoG in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

Far more flexible.

1.0.0.0