# bad channel detection before tsss

**URL:** <https://mne.discourse.group/t/bad-channel-detection-before-tsss/6692>\
**Category:** Support & Discussions\
**Tags:** preprocessing, maxwell-filter\
**Created:** [April 7, 2023, 11:09pm UTC](https://mne.discourse.group/t/bad-channel-detection-before-tsss/6692 "2023-04-07T23:09:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sushi](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sushi](https://mne.discourse.group/u/Sushi)\
**Post date:** [April 7, 2023, 11:09pm UTC](https://mne.discourse.group/t/bad-channel-detection-before-tsss/6692/1 "2023-04-07T23:09:38Z")

</div>

Hello!  
The MNE implementation of SSS / Maxwell filtering provides, among other things, basic bad channel detection (“find\_bad\_channels\_maxwell()”).

in the MNE tutorial for SSS and Maxwell they specifically warn that it is critical to mark bad channels in raw.info[‘bads’] before calling maxwell\_filtering(). Aligned with their warning, they run find\_bad\_channels\_maxwell() and mark bad channels in raw.info[‘bads’] before calling maxwell\_filtering().

My question: How does the “find\_bad\_channels\_maxwel” algorithm work? how does it detect bad channels?

Thank you!

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [April 11, 2023, 3:14pm UTC](https://mne.discourse.group/t/bad-channel-detection-before-tsss/6692/2 "2023-04-11T15:14:22Z")

</div>

did you read the Notes section of the function’s docstring? It says:

> This algorithm, for a given chunk of data:
> 
> 1. Runs SSS on the data, without removing external components.
> 2. Excludes channels as _flat_ that have had low variability (standard deviation \< 0.01 fT or fT/cm in a 30 ms window) in the given or any previous chunk.
> 3. For each channel `k`, computes the _range_ or peak-to-peak `d_k` of the difference between the reconstructed and original data.
> 4. Computes the average `mu_d` and standard deviation `sigma_d` of the differences (after scaling magnetometer data to roughly match the scale of the gradiometer data using `mag_scale`).
> 5. Marks channels as bad for the chunk when `d_k > mu_d + limit * sigma_d`. Note that this expression can be easily transformed into `(d_k - mu_d)/sigma_d > limit`, which is equivalent to `z(d_k) > limit`, with `z(d_k)` being the standard or z-score of the difference.
> 
> Data are processed in chunks of the given `duration`, and channels that are bad for at least `min_count` chunks are returned.

---

<div class="post-metadata">

**Author:** ![Sushi](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sushi](https://mne.discourse.group/u/Sushi)\
**Post date:** [January 1, 2024, 7:58pm UTC](https://mne.discourse.group/t/bad-channel-detection-before-tsss/6692/3 "2024-01-01T19:58:50Z")

</div>

thank you!
