53 const MatrixXd& matData,
68 qWarning() <<
"[findBadChannelsMaxwell] No MEG channels found.";
75 int nTimes =
static_cast<int>(matData.cols());
76 MatrixXd megData(nMeg, nTimes);
77 for (
int i = 0; i < nMeg; ++i) {
82 MatrixXd reconData =
SSS::apply(matData, basis);
85 MatrixXd megRecon(nMeg, nTimes);
86 for (
int i = 0; i < nMeg; ++i) {
92 for (
int i = 0; i < nMeg; ++i) {
93 VectorXd diff = megData.row(i) - megRecon.row(i);
94 result.
residuals(i) = std::sqrt(diff.squaredNorm() / nTimes);
100 std::sort(sorted.data(), sorted.data() + sorted.size());
102 double median = sorted(nMeg / 2);
103 if (nMeg % 2 == 0 && nMeg > 1) {
104 median = (sorted(nMeg / 2 - 1) + sorted(nMeg / 2)) / 2.0;
107 VectorXd absDev(nMeg);
108 for (
int i = 0; i < nMeg; ++i) {
109 absDev(i) = std::abs(result.
residuals(i) - median);
111 std::sort(absDev.data(), absDev.data() + absDev.size());
113 double mad = absDev(nMeg / 2);
114 if (nMeg % 2 == 0 && nMeg > 1) {
115 mad = (absDev(nMeg / 2 - 1) + absDev(nMeg / 2)) / 2.0;
119 double scale = mad * 1.4826;
120 if (scale < 1e-30) scale = 1e-30;
123 for (
int i = 0; i < nMeg; ++i) {
128 for (
int i = 0; i < nMeg; ++i) {
132 if (origIdx < info.
ch_names.size()) {
138qInfo(
"[findBadChannelsMaxwell] Detected %lld bad channel(s) out of %d MEG channels.",
139 static_cast<long long>(result.
badChannels.size()), nMeg);
Bad channel detection via SSS reconstruction residuals.
Signal-Space Separation (SSS) and temporal SSS (tSSS) for MEG data.
FIFF file I/O, in-memory data structures and high-level readers/writers.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
DSPSHARED_EXPORT BadChannelsMaxwellResult findBadChannelsMaxwell(const Eigen::MatrixXd &matData, const FIFFLIB::FiffInfo &info, const BadChannelsMaxwellParams ¶ms=BadChannelsMaxwellParams())
Detect bad MEG channels using SSS reconstruction residuals.
Parameters for SSS-based bad channel detection.
Result of SSS-based bad channel detection.
Eigen::VectorXd residuals
Implements Signal Space Separation (SSS) and temporal SSS (tSSS) for MEG data.
static Basis computeBasis(const FIFFLIB::FiffInfo &fiffInfo, const Params ¶ms=Params())
static Eigen::MatrixXd apply(const Eigen::MatrixXd &matData, const Basis &basis)
Precomputed SSS basis and projectors for a given sensor array.
QVector< int > megChannelIdx
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...