Home > NoiseTools > nt_interpolate_bad_channels.m

nt_interpolate_bad_channels

PURPOSE ^

y=interpolate_bad_channels(x,iBad,coordinates,n) - interpolate bad channels from good

SYNOPSIS ^

function [toGood,fromGood]=interpolate_bad_channels(x,iBad,coordinates,n)

DESCRIPTION ^

y=interpolate_bad_channels(x,iBad,coordinates,n) - interpolate bad channels from good

  y: interpolated data
 
  x: data to interpolate
  iBad: indices of bad channels
  coordinates: coordinate map (see nt_proximity)
  n: number of neighboring channels to use [default: 3]

 NoiseTools;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [toGood,fromGood]=interpolate_bad_channels(x,iBad,coordinates,n)
0002 %y=interpolate_bad_channels(x,iBad,coordinates,n) - interpolate bad channels from good
0003 %
0004 %  y: interpolated data
0005 %
0006 %  x: data to interpolate
0007 %  iBad: indices of bad channels
0008 %  coordinates: coordinate map (see nt_proximity)
0009 %  n: number of neighboring channels to use [default: 3]
0010 %
0011 % NoiseTools;
0012 
0013 nt_greetings;
0014 
0015 if nargin<3; 
0016     error('!'); 
0017 end
0018 if nargin<4; 
0019     n=3;
0020 end
0021 
0022 nchans=size(x,2);
0023 toGood=eye(nchans);
0024 toGood(:,iBad)=[];
0025 
0026 [closest,d]=nt_proximity(coordinates);
0027 if size(closest,1)~=nchans; error('!'); end
0028 
0029 fromGood=eye(nchans);
0030 for iChan=iBad
0031     iOthers=closest(iChan,:);
0032     iOthers=setdiff(iOthers, iBad, 'stable'); % don't include bad channels
0033     if numel(iOthers)<n; error('!'); end
0034     iOthers=iOthers(1:n);
0035     w=1./(d(iChan,iOthers) + eps);
0036     w=w/sum(w);
0037     fromGood(iOthers,iChan)=w;
0038 end
0039 fromGood(iBad,:)=[];
0040     
0041 topo=ones(nchans,1);
0042 topo(iBad)=0;
0043 if nargout==0
0044     figure(100); clf
0045     subplot 121; nt_imagescc(fromGood);
0046     subplot 122; nt_topoplot(coordinates,topo);
0047 end
0048

Generated on Tue 09-Oct-2018 10:58:04 by m2html © 2005