time-series scale

Hello guys, I’m working with the CHB-MIT scalp EEG database, i transformed the data to a data frame so I could visualize the time points and i think that is something wrong, i don’t understand the scale. Do i have to do some rescale? The recordings are 256Hz and 1 hour long (3600s)
image
code:

fname='chb24_01_edited.edf'
iir_params=dict(order=2, ftype='butter')
def preprocessing(file_path):
    datax=mne.io.read_raw_edf(file_path,preload=True)
    datax.set_eeg_reference()
    datax.filter(l_freq=0.5,h_freq=40.0, method='iir', iir_params=iir_params, verbose=True)
    epochs=mne.make_fixed_length_epochs(datax,duration=2)
    epochs=epochs.to_data_frame(picks=['F3-C3', 'C3-P3', 'F4-C4', 'C4-P4'])
    return epochs
data=preprocessing(fname)
print(data.shape)
print(data.head())

Hello,

It looks like the data is in uV.
It’s not very easy to tell from 5 times points in a table. To visualize it, could you plot some of those channels and their scale? Either via matplotlib or with raw.plot() (in your case datax.plot()).

MNE expects volts, so if it is indeed in uV, I suggest you rescale it. You can do this via the method raw.apply_function: mne.io.Raw — MNE 1.2.1 documentation

Mathieu

I see, i asked before about this and they told me mne does automatically. Anyway, after the raw.apply_function (lambda x: x * 1e-6) i get this :
image

But my question is about the time, why does it sums 3096? How is that related to the 3600 seconds of the recording or the 2 seconds (512 data points) epochs?

MNE expects data in Volts, but it’s up to the user to provide data in the correct scale.

Again, it’s hard to tell from 5 data-points, could you please share some plots?

The plot from the epochs data:
image

This one i did not put the data in a data frame before:
image

But my question is about the time, why does it sums 3096? How is that related to the 3600 seconds of the recording or the 2 seconds (512 data points) epochs?

I missed where you mentioned this was the issue. What do you mean by sum to 3096? Your tables don’t show it, right?
2 seconds epochs at 256 Hz should have 512 samples, what is the issue?


For the Y-range: based on the top plot for the epoch data, it looks like what you plotted ranges up to 0.0001 Volts, i.e. 100 uV. This does look correct to me.
To confirm, could you plot 30s of the raw recording? That would be more informative as we could see both:

  • actual brain signal and its quality
  • scale of the signal

Do mind that you may have a large DC offset, thus I would first high-pass filter the data.

raw = read_raw(fname, preload=True)
raw.filter(1., None)
raw.plot()

The default scaling of raw.plot() should display data without clipping (except for large artifacts such as eye blinks).

I mean in the time column of the data frame, shouldn’t be in seconds? starts in 0, then 0.003096 and 0.007812… I’m sorry if i’m not clear about this, It’s the first time i work with eeg data and I’m not sure if the data is in the correct shape.

image

raw.plot(start=0, duration=30, scalings='auto')
The last one is the plot without filtering


It is in seconds. If your sampling frequency is 256 Hz, then you have 1 / 256 seconds separating 2 samples. i.e. 0.003906 seconds, a little less than 4ms (which would be 250 Hz sampling).
A couple of quick common sampling frequencies in EEG:

  • 1 kHz → 1 sample every 1 ms, i.e. 0.001 seconds
  • 500 Hz → 1 sample every 2 ms, i.e. 0.002 seconds
1 Like

Thank you so much, I guess i’ve missed the basics math :slight_smile:

Also note that the DataFrame export defaults to a uV scale, even though MNE internally stores EEG data in Volts. So I believe the values you showed in your first posting are already correct and no rescaling is needed.

1 Like