MariusKlug / zapline-plus

Improvements of the ZapLine function to remove line noise from EEG/MEG data. Adds automatic detection of the number of components to remove, and chunks the data into segments to account for nonstationarities.
GNU General Public License v3.0
25 stars 9 forks source link

Return removed components #20

Closed prlabu closed 1 year ago

prlabu commented 1 year ago

Amazing work. Love the automated nature of the package and great documentation.

I'm developing a preprocessing pipeline for human intracranial data. We would like to preserve the rank of the data matrix (nchan x nsamples) at every step of the process such that we could, in theory, reconstruct the original/raw data.

Is there a way, with this zapline-plus, to return the removed components?

I'm thinking I could simply append the removed component to the data matrix as another channel. That way, we would have a matrix of size (nchan + 1) x nsamples, but the rank of the matrix would still be nchan.

Thanks!

MariusKlug commented 1 year ago

Hey, thanks! Technically speaking, the rank of the matrix is complete even after running Zapline-plus even if the noise is removed. That's the beauty of Zapline: It only removes components in the noisy part of the data but preserves the full clean part, so there's always full rank. This is also elaborated in depth in the original paper by de Cheveigné (2020).

So there is no easy way to just reconstruct the original data mathematically like when using only a spatial filter. If you had the removed components spatial filters, you would have to redo the entire process of chunking the data, filtering with the broad notch filter, and then reapplying the removed components. That is rather impractical so the best way would probably be to actually save the original data before running Zapline-plus...

prlabu commented 1 year ago

Thanks for the speedy reply. Understood! I see you're right about complete rank. I was thinking of common average referencing, which reduces the rank (I think...).