Extracting sampling rate from EDF file

MNE version: 1.0.3
operating system: Google Collab

“In particular, the nominal sampling rate of the recording system is of substantial importance for any type of analysis, like seizure analysis, sleep analysis, or cognition related analysis” (WEIERGRABER, M., 2016)

Assuming standard EEG data from Physionnet EEG Motor Movement/Imagery Dataset v1.0.0

How can sampling rate be extracted/calculated from a raw EDF file?

The further I got was “raw.first_samp” and “raw.last_samp”.

Does anyone have examples to share?

Best wishes,
Iuri

raw.info["sfreq"] contains the sampling frequency.

1 Like

lol! that was easy!

What does happen to the statement below?

The sampling rate is (i) the arithmetic average of number of samples, (ii) which is the number of records times the number of samples in a data record (iii) times the number of signals.

I find this statement weird, it doesn’t mention time anywhere??

http://paulbourke.net/dataformats/edf/

This website doesn’t contain that statement. What exactly do you want to do? The EDF specification website states:

The first 256 bytes of the header record specify the version number of this format, local patient and recording identification, time information about the recording, the number of data records and finally the number of signals (ns) in each data record. Then for each signal another 256 bytes follow in the header record, each specifying the type of signal (e.g. EEG, body temperature, etc.), amplitude calibration and the number of samples in each data record (from which the sampling frequency can be derived since the duration of a data record is also known). In this way, the format allows for different gains and sampling frequencies for each signal.

Makes sense?

Yes, You can find the statement in the website:
“The number of samples will be the number of records times the number of samples in a data record times the number of signals.”

I, myself, added the “average” part because, previously, I had only raw.first_samp and raw.last_samp numbers.

Perhaps, It was me who didn’t understand well. Even because I’m no expert in BCI.

Nevertheless, quoted paragraph does make total sense, and as you asked. I’m trying to parse an EDF file, to the following .MAT structure,

sample_rate = m[‘nfo’][‘fs’][0][0][0][0]
EEG = m[‘cnt’].T
nchannels, nsamples = EEG.shape
channel_names = [s[0] for s in m[‘nfo’][‘clab’][0][0][0]]
event_onsets = m[‘mrk’][0][0][0]
event_codes = m[‘mrk’][0][0][1]
labels = np.zeros((1, nsamples), int)
labels[0, event_onsets] = event_codes
cl_lab = [s[0] for s in m[‘nfo’][‘classes’][0][0][0]]
cl1 = cl_lab[0] # left
cl2 = cl_lab[1] # right
nclasses = len(cl_lab)
nevents = len(event_onsets)

originally from the dataset1, BCI competition IV, Data Set 1 for the BCI Competition IV

Let me know if you’ve got any enlightening ideas.

Best wishes,
I

Errm, the only thing these two have to do with the sampling rate is that they’re connected with said sampling rate via recording duration. You don’t want to average those…

What is your question? Please open a new topic for new questions. I believe the one regarding the sampling rate has been answered. Thank you!