Calculating PSD with 16-electrodes OpenBCi
I am using an ALL-IN-ONE BIOSENSING R&D BUNDLE, which contains 16 EEG electrodes and also two ear clips.
I am saving the data through the Python stream with .edf format and then loading it and using the following preprocessing:
LowPass_Freq = 0.5
HighPass_Freq = 30
Resampled_Frequency = 60
Epoch_Duration = 1
OverLap = 0.5
montage = mne.channels.make_standard_montage('standard_1020')
def read_data(file_path):
datax = mne.io.read_raw_edf(file_path, preload=True)
datax.drop_channels(['Fp2', 'O1', 'F4'])
print("Channel names before applying montage:", datax.ch_names)
datax.crop(tmax=27)
datax.filter(l_freq=LowPass_Freq, h_freq=HighPass_Freq)
datax.resample(sfreq=Resampled_Frequency)
datax.set_eeg_reference()
datax.set_montage(montage)
epochs = mne.make_fixed_length_epochs(datax, duration=Epoch_Duration, overlap=OverLap)
return epochs
My first question is do I need to set any channels as references? I meant this part in my code
datax.set_eeg_reference()
Also, I dropped 3 channels since the stream data through GUI is not railed and does not have a good signal-to-noise ratio.
Moreover, I am using following code to calculate PSD
Epochs[3].compute_psd().plot()
but once want to hardcode it and use the frequencies, the range is somehow like this:
[1.37151917e-11, 1.47513447e-11, 5.01511143e-12]
Also used 10*np.log10(psd_data)
and the data would be in range of
[ -78.16904615, -75.18809093, -75.52985457,...]
which is weird.
so, how should I convert the PSD to dB to match that plot?
Thanks in advance
Best,
Comments
Hi Sorous,
I'm not sure there are that many MNE experts here monitoring this Forum. Have you considered posting on the forum that is specific to MNE?
https://mne.tools/stable/help/index.html
https://mne.discourse.group/
I do wonder about the
datax.resample(60)
that you are doing. The Cyton sample rate is already pretty low (250 Hz for 8 channel and 125 Hz for 16). So downsampling to 60 Hz sample rate will lose a lot of resolution.https://mne.tools/stable/auto_tutorials/preprocessing/30_filtering_resampling.html#resampling
Regards, William
Hi William,
Thanks for the reply.
Yes I already posted there as well, but still have not gotten any answer.
Resampling my EEG data to 60 Hz can be highly beneficial for my motor imagery analysis without causing significant loss of important information. The key frequencies involved in motor imagery tasks primarily lie within the alpha (8-12 Hz) and beta (13-30 Hz) bands. By resampling to 60 Hz, which has a Nyquist frequency of 30 Hz, I can accurately capture these critical frequency ranges. Additionally, resampling reduces the data size and computational load, making processing and analysis more efficient. To ensure no important infoformation is lost, applying a low-pass filter to remove frequencies above 30 Hz before resampling prevents aliasing, thus maintaining the integrity of the essential data for my motor imagery tasks.
Overall, I was thinking downsaples the data is better. Would you mind telling your thought about it?
Thanks
The quote above from the MNE page suggests that downsampling (to reduce data size) is mainly appropriate for expensive research type amplifiers that sample at (for example) 1000 Hz. The 125 Hz sample rate is already fairly low resolution and does not need any further reduction.
Additionally, even though you might think that 60 Hz sample rate can accurately record 30 Hz signals, it's not really the case. Think of a 30 Hz signal sampled at 60 Hz, but at the zero crossing points. This is called aliasing. The signal appears to be zero, but in fact that perception is just an artifact of the sample rate.
A better metric for ensuring adequate sample rate for a given signal, is to (for example) have your sample rate roughly 5 times the signal frequency. That way the signal is recorded at 5 times during each signal waveform. And less affected by alias artifacts.
5 times 30 equals 150 Hz, which is close to the 125 Hz Daisy rate.
Regards,