Home > NoiseTools > nt_badChannels.m

# nt_badChannels

## PURPOSE

iBadChans=nt_badChannels(x,threshRel,threshAbs,prop) - find bad channels using heuristics

## SYNOPSIS

function iBadChans=nt_badChannels(x,threshRel,threshAbs,prop)

## DESCRIPTION

    iBadChans=nt_badChannels(x,threshRel,threshAbs,prop) - find bad channels using heuristics

      iBadChans: bad channel numbers

      x: data
      threshRel: threshold relative to robust std over all channels [default: 3]
      threshAbs: absolute threshold
      prop: proportion beyond which channel is irrecuperable [default 0.7]

     NoiseTools

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_demean [y,mn]=nt_demean(x,w) - remove weighted mean over cols
- nt_greetings nt_greetings - display message the first time the toolbox is used
- nt_unfold y=nt_fold(x) - unfold 3D to 2D
- nt_wmean y=nt_wmean(x,w,dim) - weighted average

This function is called by:

- nt_star2 [y,w,ww]=nt_star2(x,thresh,closest,w) - sensor noise suppression

## SOURCE CODE

    0001 function iBadChans=nt_badChannels(x,threshRel,threshAbs,prop)
    0002 %iBadChans=nt_badChannels(x,threshRel,threshAbs,prop) - find bad channels using heuristics
    0003 %
    0004 %  iBadChans: bad channel numbers
    0005 %
    0006 %  x: data
    0007 %  threshRel: threshold relative to robust std over all channels [default: 3]
    0008 %  threshAbs: absolute threshold
    0009 %  prop: proportion beyond which channel is irrecuperable [default 0.7]
    0010 %
    0011 % NoiseTools
    0012 nt_greetings;
    0013
    0014 if nargin<1; error('!'); end
    0015 if nargin<2||isempty(threshRel); threshRel=3; end
    0016 if nargin<3; threshAbs=[]; end
    0017 if nargin<4; prop=0.7; end
    0018
    0019 x=nt_unfold(x);
    0020
    0021 % robust STD
    0022 w=ones(size(x));
    0023 for iIter=1:4
    0024     xx=nt_demean(x,w);
    0025     STD=sqrt(nt_wmean(xx(:).^2,w(:)));
    0026     w(find(abs(xx)/STD>3))=0;
    0027 end
    0028
    0029 x=nt_demean(x,w);
    0030
    0031 iBadChans=[];
    0032 for iChan=1:size(x,2)
    0033     if numel(find(abs(x(:,iChan))/STD>threshRel)) / size(x,1) > prop
    0034         iBadChans=[iBadChans,iChan];
    0035     end
    0036 end
    0037
    0038 if ~isempty(threshAbs)
    0039     for iChan=1:size(x,2)
    0040         if numel(find(abs(x(:,iChan))>threshAbs)) / size(x,1) > prop
    0041             iBadChans=[iBadChans,iChan];
    0042         end
    0043     end
    0044 end
    0045
    0046