[Eeglablist] Mindset's EEG file import

Dean Cvetkovic s9809696 at student.rmit.edu.au
Mon Dec 20 19:40:49 PST 2004


Hi Robert and other EEGLAB memebers,

I am able to read the older Mindset EEG data into Matlab using '.mat' file
format, however the scaling and little-endian ordering is required which I
am not so sure how to do in Matlab.

Does anyone know how to do correct scaling and conversion from little to
big-endian ordering?

Here is an explonation on how scaling is performed, ordering codes in C and
my matlab codes so far:

For an average of 20 Mindsets and 16 channels/Mindset, the absolute value
returned by the ADC is 363.63 counts per microvolt. The "363.63" figure
comes from empirical testing. This is the value used in the MindMeld
program.

For example, a 2uV peak-to-peak (1uV peak) signal will swing the ADC 363.63
(hex $16C) counts either side of $7000. ($7000 is the null, or
zero point.) That is, the ADC count will vary from $7000 - $16C to $7000 +
$16C, or $6E94 to $716C.

A 20 uV peak-to-peak (10uV peak) signal will swing the ADC count 3,636
($E34) either side of $7000. That is, the ADC count will go
from $61CC to $7E34. A 50 uV peak-to-peak (25uV peak) signal will swing it
from $4C74 to $938C.

Another way to look at it is each ADC count is about 2.75 nanovolts. There
is always some thermal noise present, so the readings are
accurate to about 0.5uV.

Since Matlab probably expects the data to be in little endian (intel)
format, I need to convert each 16 bit data sample to little
endian before assigning it to a Matlab variable.

I don't know how to do this in Matlab, but here's how to do it in C:

-----
unsigned short thesample;          // samples are 16 bits, unsigned
unsigned short highbyte, lowbyte;  // temporary variables

     thesample = getnextsample();   // get the next 16 bit data sample
from the file
     lowbyte = thesample & 0x00FF;  // isolate the low byte
     highbyte = thesample >> 8;     // isolate the high byte

     thesample = lowbyte << 8;      // move the low byte to high position
     thesample |= highbyte;         // merge the high byte into the low
position

-----

Another method is to get one byte at a time from the data stream:

-----
unsigned short thesample;          // samples are 16 bits, unsigned
byte highbyte, lowbyte;            // temporary variables

     highbyte = getnextsamplebyte(); // get the most significant byte
     lowbyte = getnextsamplebyte();  // get the least significant byte

     thesample = lowbyte << 8;      // move the low byte to high position
     thesample |= highbyte;         // merge the high byte into the low
position

-----

In the C language, the '<<' operator is a shift left.  So "<<= 8" shifts the
variable 8 places to the left, which is the same as
multiplying by 256.

Note that in C we're dealing with UNSIGNED variables, so that $FFFF is taken
as +65535 instead of -1, and $8000 is taken as +32768
instead of -32768. The endian conversion needs to be performed before
assigning the value
to a Matlab variable.

Here is the Matlab code I wrote, but need to perform the little-endian
ordering:

    % function outarg = MindToMat(eegfilename,matfilename,nochannels);
    % Program to import Mindset older .eeg file into Matlab

    % Open .eeg File
    [fid,message]=fopen(EEGfilename.eeg','r','l');
    MATfile= 'EEGfilename.mat';

    % Read Header File Information

    [ident,c1]=fread(fid,8,'char');
    [revis,c2]=fread(fid,1,'char');
    [filetype,c3]=fread(fid,1,'char');
    [structrev,c4]=fread(fid,1,'char');
    [devicetype,c5]=fread(fid,1,'char');
    [nochannels,c6]=fread(fid,1,'char');
    [bytespersample,c7]=fread(fid,1,'char');
    [samplerate,c8]=fread(fid,1,'short');
    [nosamples,c9]=fread(fid,1,'int');

    % Read Main body of information

    status=fseek(fid,20,-1);
    [EEG,c10]=fread(fid,[nochannels,nosamples],'char');

    % EEG signal converted to microVolts (not Volts)

    EEG=((EEG-28672)/363.63);

    % Extract only the required channels
    switch channels (16 channels)

    case 1
        ch=EEG(1,:)';
    case 2
        ch=EEG(1:2,:)';
    .
    .
    .

    otherwise
        ch=EEG(1:16,:)';
    end

    % create the time data
    time = [0:(nosamples-1)]/samplerate;

    % Save New MatLab File

    save(MATfile,'ch','time','samplerate','nosamples');

    fclose(fid);
    outarg = load(MATfile);

Mindset Data File Formats

This document describes the .eeg and .bin file formats as saved by the
MindLab/WaveLab and MindMeld programs.

Older EEG File Format (MindLab/WaveLab)

.eeg files start with a 20 byte header followed by the actual data samples.
All values in the file are in hex.

Byte

Offset                         Data                           Meaning

0000                      4D494E4453455400         signature = "MINDSET" in
ASCII characters (null terminated)

0008                        01                                revision = 1

0009                        01                                filetype = 1

000A                       00                                structure
revision

000B                       01                                type of device
(1 = Mindset)

000C                       10                                number of
channels = 16

000D                       10                               number of
bits/sample = 16

000E                       0100                           samplerate = 256
sps

0010                      xx xx xx xx                  dword: the number of
samples that follow

0014                                                        the Data Samples
start here

Here's an actual header from an .eeg file:

4D494E4453455400 01 01 00 01 10 10 0001 101E0000 71DD 71CF 6F8E ...

Note the Intel ordering (little endian) for the header bytes and Motorola
ordering (big endian) for the data samples.

Here's the header as a C structure:

struct {

BYTE identifier[8]; // signature = "MINDSET" (null terminated)

BYTE revision; // revision = 1

BYTE filetype; // filetype = 1

BYTE structrev; // structure revision = 0

BYTE devicetype; // type of device (1 = Mindset MS-1000)

BYTE numberofchannels; // number of channels = 16

BYTE bitspersample; // number of bits/sample = 16

short samplerate; // samplerate

DWORD numberofsamples; // number of data samples (for each channel) in the
file

} eeg_header;

The data samples for the 16 channels are each 16 bits in length arranged as
follows:

Channel 1 Channel 2 Channel 3 .. Channel 16

Data Sample 1: 7000 7000 7000 .. 7000

Data Sample 2: 7000 7000 7000 .. 7000

Data Sample 3: 7000 7000 7000 .. 7000

.

.

.

Note that in this case each data sample is 32 bytes in length (one 16 bit
sample for each of the 16 channels). In the .eeg header the

"numberofsamples" field contains the number of data samples, each data
sample being 32 bytes in length.

Thank you very much.

Regards,

Dean
----- Original Message -----
From: "Robert Lawson" <robert at EEGWorks.com>
To: <s9809696 at student.rmit.edu.au>
Sent: Wednesday, December 15, 2004 7:40 AM
Subject: Re: [Eeglablist] Mindset's EEG file import


> Hi Dean
>
> Contact Wayne Noland, the manufacturer. He has an ASCII out utility now.
> EEGlab has native ASCII import. I have a perl script that converts the new
> format to ASCII you can have. Also- Wayne might give you an upgrade.
>
> wayne at nolancomputersystems.com
>
> If he does not support the old file format ASCII out, ask hi for the file
> format. Once you have that, people on the EEG lab list can help w/ the
> import.
>
> Robert
>
> ------Original Mail------
> From: "Dean Cvetkovic" <s9809696 at student.rmit.edu.au>
> To: "eeglablist" <eeglablist at sccn.ucsd.edu>
> Sent: Tue, 14 Dec 2004 19:15:53 +1100
> Subject: [Eeglablist] Mindset's EEG file import
>
> Hi all,
>
> Does anyone know if you can import Mindset's EEG file format '.eeg' (older
> version) into EEGLAB?
>
> Thank you very much.
>
> Dean




More information about the eeglablist mailing list