Home > NoiseTools > nt_find_outliers2.m

# nt_find_outliers2

## PURPOSE

w=nt_find_outliers2(x,cutoff,iterations) - outliers based on mahalanobis distance

## SYNOPSIS

function w=nt_find_outliers2(x,cutoff,iterations);

## DESCRIPTION

    w=nt_find_outliers2(x,cutoff,iterations) - outliers based on mahalanobis distance

      w: mask matrix (0: bad, 1: good)

      x: data
      cutoff: outlier if (m.d.)/nchans > cutoff (default: 2)
      iterations: number of times to iterate (default: 1)
     NoiseTools

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_find_outliers2 w=nt_find_outliers2(x,cutoff,iterations) - outliers based on mahalanobis distance
- nt_fold y=fold(x,epochsize) - fold 2D to 3D
- nt_unfold y=nt_fold(x) - unfold 3D to 2D

This function is called by:

- nt_find_outliers2 w=nt_find_outliers2(x,cutoff,iterations) - outliers based on mahalanobis distance

## SOURCE CODE

    0001 function w=nt_find_outliers2(x,cutoff,iterations);
    0002 %w=nt_find_outliers2(x,cutoff,iterations) - outliers based on mahalanobis distance
    0003 %
    0004 %  w: mask matrix (0: bad, 1: good)
    0005 %
    0006 %  x: data
    0007 %  cutoff: outlier if (m.d.)/nchans > cutoff (default: 2)
    0008 %  iterations: number of times to iterate (default: 1)
    0009 % NoiseTools
    0010
    0011 if nargin<1; error('!'); return; end
    0012 if nargin<2 || isempty(cutoff); cutoff=2; end
    0013 if nargin<3 || isempty(iterations); iterations=1; end
    0014
    0015 [m,n,o]=size(x);
    0016 x=nt_unfold(x);
    0017
    0018 w=ones(size(x,1),1);
    0019 if iterations>1
    0020     w=nt_find_outliers2(x(find(w),:),cutoff,iterations-1);
    0021     return
    0022 end
    0023
    0024 d=mahal(x,x(find(w),:));
    0025 d=d/n; % normalize by number of channels
    0026 w=d<cutoff;
    0027
    0028 w=nt_fold(w,m);