Weird behaviour when adding in reference and averaging

Hello,

I am getting some surprising output when adding in the original reference electrode which was not exported with the data (CPz), and then re-referencing to average. When I add in the new electrode, it is at around -3000, meaning when its averaged it distorts all other channels too. Not sure what could be driving the error in this case.
The code I use is as follows:

epochs = mne.add_reference_channels(epochs, ref_channels=['CPz'])
epochs.plot_psd(fmax = 45)
epochs = epochs.set_eeg_reference(ref_channels='average', ch_type = 'eeg')
epochs.plot_psd(fmax = 45)

Just to be sure, which channel is at the bottom in Figure 2?

hi @cbrnr , Its CPz which is at the bottom of Figure 2

OK, then I don’t understand why it’s so far at the bottom. Figure 1 is perfectly fine, because your new reference channel is by definition zero. I just tried the same procedure with one of my datasets, and the result (Figure 2) looks normal (i.e., there is no outlier channel).

Figure 1 also looks problematic, the line is faint, but CPz is at -3000, rather than being at zero, which from my understanding is where it should be

This should make it clearer:

No, this is fine. The units are in dB, so a power of zero corresponds (in theory) to -infinity (because log(0) = -infinity).

1 Like

Ah okay! I guess I expect CPz to sit sort of in the middle of the over channels on the PSD plot, so am confused about why it is still below them

Yes, the thing I don’t understand either is Figure 2. Can you post your mne.sys_info() output please? And you could try to omit the ch_type argument when you set the reference (default is 'auto').

Platform: Windows-10-10.0.19044-SP0
Python: 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]
Executable: C:\Users\hlw69\Anaconda3\python.exe
CPU: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel: 12 cores
Memory: 31.8 GB

mne: 1.3.1
numpy: 1.21.5 {MKL 2021.4-Product with 6 threads}
scipy: 1.7.3
matplotlib: 3.5.1 {backend=Qt5Agg}

sklearn: 1.0.2
numba: 0.55.1
nibabel: 4.0.1
nilearn: 0.9.1
dipy: Not found
openmeeg: Not found
cupy: Not found
pandas: 1.4.2
pyvista: Not found
pyvistaqt: Not found
ipyvtklink: Not found
vtk: Not found
qtpy: 2.0.1 {PyQt5=5.9.7}
ipympl: Not found
pyqtgraph: Not found
pooch: v1.6.0

mne_bids: Not found
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: Not found
mne_connectivity: Not found
mne_icalabel: 0.4

Can confirm that the same plot is produced when ch_type is set to ‘auto’. I am computing the average referencing after ICA (its at the very end of my preprocessing pipeline), because I was doing an iterative compute ICA then look again at bad segments to remove (as well as components) - and wanted to avoid average referencing prior as I had some particularly noisy channels that I did not want to smear noise across. Do you think this could have anything to do with it?

Yes, this could likely lead to what you’re seeing. Why do you want to add the original reference channel? Can you not just average reference without it?

I read a blog about the importance of adding the old reference back in before average referencing to avoid rank deficient data. Makoto's preprocessing pipeline - SCCN.
Maybe this isn’t a problem in my case anyway as I do ICA prior to re-referencing, but wanted to safeguard against this impacting further statistical analyses that I do on the data

I just tried rereferencing before ICA and have the same problem, So i don’t think ICA is the issue:

Okay, so, I’ve narrowed it down to a step I do in BESA software. Before this, CAR works fine. However, after using the automatic artifact correction function in BESA then exporting and importing to MNE, something goes wrong. Potentially to do with the montage being saved

@hWils I am just wondering what happens if you add the reference electrode (CPz) and setup the montage, afterwards set the eeg reference to average? Can you perform this at the raw object? Perhaps some outlines of the code would be helpful for us to debug.
P.S: Its easier if you set up all of the montage related things at the raw level.

best,
Dip

Hi @dasdiptyajit, just tried now with setting up the montage between adding the electrode and then setting to average. I have the same problem when trying this with epochs, and at the raw level. I really think its something in the exporting from BESA stage, I might just skip the preprocessing I was doing in there with eye blink removal and just use ICA in MNE. Really wanted to avoid the subjectivity of ICA. Do you know if any similar algorithms have been implemented in MNE, that do more template matching etc?

Just to understand you correctly, you would like to correct eye blinks/ heart related activity?
If that the case: you can use SSP/ICA/ even regression (EOG artifacts correction) techniques. ICA would be the one I would rather use for template matching. You can find these implementations with examples in the MNE example gallery.

And I would also recommend you to stick to one particular software and not doing back and forth unless there is a special need/reasoning.
best,

1 Like

I found the artifact correction in BESA extremely reliable and effective,whereas the template matching for EOG using ICA in mne I did not get as great results with. Compnents that were definitely not eye related would get pulled up as eye, and very obvious eye blink components got missed. However, could definitely just been that the data wasn’t in a sufficiently clean state prior to this for the algorithms to work effectively.

I agree about switching between softwares, seems it can add in unexpected issues. Will be sticking with MNE from now on.

thanks for all your help!