Open EEG binary file

Hi,

I am trying to open an EEG BrainVision binary file, but I have a problem… Please help :frowning:

To open the binary, I am using the solution provided in this discussion by @stevengj (thank you).

The data is said to include 257 channels sampled at 1kHz for 10 minutes, as IEEE Float32.

Here is my code:

fs=1000        # sampling frequency
ch_numb=257    # 257 channels
record_time=10 # 10 minutes
read_bin(filename, dims) = read!(filename, Vector{Float32}(undef, dims)) # stevengji's function
data=read_bin(filename,ch_numb*record_time*60*fs) # get the data

So far so good, it gives the amount of data I am expecting given the data descriptor…BUT

data=read_bin(filename,ch_numb*record_time*60*fs+1000000) 

This code also gives me data(with no eror), I get 1 million values more than I should get.

My question is:
Is there a method to obtain the actual amount of Float32 values inside the binary file?
I mean beside increasing the dims value until I get an end of file error.

Thanks

Are you sure the file is unstructured like that? Usually this kind of data can have all kinds of metadata embedded in the file. @jrevels works a lot with EEG data, maybe he can point you in the right direction.

Thank you @Keno, This file actually is composed of three files, one binary and two with metadata(sampling frequency, number of channels ,etc). My problem is that it seems to have more data than expected.

Would you think would be appropriate to contact @jrevels directly??
(I guess using Discourse tools, I have never done it before)

Discourse will have emailed him, so he can chime in here if he knows something. Usually messaging people directly is discouraged, as it prevents other people from seeing an answer which may be useful to them (aside from any etiquette questions).

I understand. Thank you

What is the file extension?

Maybe you won’t believe this, but I was praying for you to come… Thank you.

It is BrainVision’s file, the .eeg file. I read (in a text editor) the metadata files, but I get the situation described above.

In fact, I would like to code something to read this format, and I was also thinking of contacting you to know if it could be added to you Neuro Julia projects.

I mean, if you think it is appropriate, I am just a beginner but with a couple of comments I would love to do it.

I haven’t worked with BrainVision’s format directly (@Zach_Christensen would be a better bet there - IIRC BIDS adopted the BrainVision format) but these links could be helpful:

BrainVision Core Data Format 1.0

It would definitely be within the scope of JuliaNeuroscience. The first thing would be to find out how they specify basic channel information in the header. For example, biosemi has this specification Biosemi EEG ECG EMG BSPM NEURO amplifiers systems

Great…

BrainVision file is actually composed of three files (here is the documentation):
.vhdr is the header
.vmrk the “marker” file
.eeg contains the data

The header(.vhdr) is pretty simple actually, here is the one I am working with(I cut the last 252 channels, it is too long):

Brain Vision Data Exchange Header File Version 1.0
; Data created by FieldTrip

[Common Infos]
DataFile=sub-01_ses-RestingState_task-PicturesNaming_eeg.eeg
MarkerFile=sub-01_ses-RestingState_task-PicturesNaming_eeg.vmrk
DataFormat=BINARY
DataOrientation=MULTIPLEXED
NumberOfChannels=257
SamplingInterval=1000

[Binary Infos]
BinaryFormat=IEEE_FLOAT_32

[Channel Infos]
Ch1=E1,,1
Ch2=E2,,1
Ch3=E3,,1
Ch4=E4,,1
Ch5=E5,,1

What do you think? I am wondering what the “JuliaNeuro” flavor would be

Hey thanks, I am gonna give it a try today

I’d start by importing it as a vector of 257 channels where each channel is a vector of floats. Usually that’s enough to get you to a productive work flow. Create some basic tests to ensure that your code still loads data properly as you improve on the whole IO process.

Try not to worry too much about doing things the “correct” way at first. If you ping me on GitHub I can help you out with getting basic traits working. They aren’t difficult but I’m very behind on documenting code right now (can you believe my PI wants me to publish papers instead of code documentation😉).

Unbelievable… :see_no_evil:
PIs, who can understand them ?

I understand what you say… In prooooogress