Home > vbmeg > functions > device > eeg > brainamp > in_fread_brainamp.m

in_fread_brainamp

PURPOSE ^

IN_FREAD_BRAINAMP: Read a block of recordings from BrainVision BrainAmp .eeg file

SYNOPSIS ^

function F = in_fread_brainamp(sFile, sfid, SamplesBounds)

DESCRIPTION ^

 IN_FREAD_BRAINAMP:  Read a block of recordings from BrainVision BrainAmp .eeg file

 USAGE:  F = in_fread_brainamp(sFile, sfid, SamplesBounds=[])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function F = in_fread_brainamp(sFile, sfid, SamplesBounds)
0002 % IN_FREAD_BRAINAMP:  Read a block of recordings from BrainVision BrainAmp .eeg file
0003 %
0004 % USAGE:  F = in_fread_brainamp(sFile, sfid, SamplesBounds=[])
0005 
0006 % @=============================================================================
0007 % This software is part of the Brainstorm software:
0008 % http://neuroimage.usc.edu/brainstorm
0009 %
0010 % Copyright (c)2000-2013 Brainstorm by the University of Southern California
0011 % This software is distributed under the terms of the GNU General Public License
0012 % as published by the Free Software Foundation. Further details on the GPL
0013 % license can be found at http://www.gnu.org/copyleft/gpl.html.
0014 %
0015 % FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
0016 % UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
0017 % WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
0018 % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
0019 % LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
0020 %
0021 % For more information type "brainstorm license" at command prompt.
0022 % =============================================================================@
0023 %
0024 % Authors: Francois Tadel, 2012-2013
0025 % 2014-12-08 rhayashi Added scale calculation
0026 
0027 % Parse inputs
0028 if (nargin < 3) || isempty(SamplesBounds)
0029     SamplesBounds = sFile.prop.samples;
0030 end
0031 
0032 % BINARY and MULTIPLEXED files
0033 if (strcmpi(sFile.header.DataFormat, 'BINARY') && strcmpi(sFile.header.DataOrientation, 'MULTIPLEXED'))
0034     nChan = sFile.header.NumberOfChannels;
0035     % Get start and length of block to read
0036     offsetData = SamplesBounds(1) * nChan * sFile.header.bytesize;
0037     nSamplesToRead = SamplesBounds(2) - SamplesBounds(1) + 1;
0038     % Position file at the beginning of the data block
0039     fseek(sfid, offsetData, 'bof');
0040     % Read all values at once
0041     F = fread(sfid, [nChan, nSamplesToRead], sFile.header.byteformat);
0042     % Convert from microVolts to Volts
0043     F = F * 1e-6;
0044     
0045 % ASCII and VECTORIZED files
0046 elseif (strcmpi(sFile.header.DataFormat, 'ASCII') && strcmpi(sFile.header.DataOrientation, 'VECTORIZED'))
0047     % Open file
0048     fid = fopen(sFile.filename, 'r');
0049     % Initialize data matrix
0050     F = zeros(sFile.header.NumberOfChannels, sFile.header.DataPoints);
0051     iChannel = 1;
0052     % Read the entire file line by line
0053     while(1)
0054         % Display message
0055         % disp(sprintf('BRAINAMP> Reading channel #%d...', iChannel));
0056         % Reached the end of the file: exit the loop
0057         if feof(fid)
0058             break; 
0059         end;
0060         % Read one line
0061         strChan = strtrim(fgetl(fid));
0062         if isempty(strChan)
0063             continue;
0064         end
0065         % Find the first separator
0066         iSep = min([find(strChan == ' ',1), find(strChan == sprintf('\t'),1)]);
0067         % Replace "," with "." for the numbers
0068         strChan(strChan == ',') = '.';
0069         % Read the values
0070         F(iChannel,:) = sscanf(strChan(iSep+1:end), '%f')';
0071         iChannel = iChannel+1;
0072     end
0073     % Close file
0074     fclose(fid);
0075     % Select only the requested time points
0076     iTime = (SamplesBounds(1):SamplesBounds(2)) - sFile.prop.samples(1) + 1;
0077     F = F(:,iTime);
0078     % Convert from microVolts to Volts
0079     F = F * 1e-6;
0080 end
0081 
0082 % Scale data
0083 for ch=1:sFile.header.NumberOfChannels
0084     F(ch, :) = F(ch, :) * sFile.channelmat.Channel(ch).scale;
0085 end
0086

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005