0001 function [toGood,fromGood]=interpolate_bad_channels(x,iBad,coordinates,n)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
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 disp(size(closest));
0028 disp(size(d));
0029 if size(closest,1)~=nchans; error('!'); end
0030
0031 fromGood=eye(nchans);
0032 for iChan=iBad
0033 iOthers=closest(iChan,:);
0034 iOthers=setdiff(iOthers, iBad, 'stable');
0035 if numel(iOthers)<n; error('!'); end
0036 iOthers=iOthers(1:n);
0037 w=1./(d(iChan,iOthers) + eps);
0038 w=w/sum(w);
0039 fromGood(iOthers,iChan)=w;
0040 end
0041 fromGood(iBad,:)=[];
0042
0043 topo=ones(nchans,1);
0044 topo(iBad)=0;
0045 if nargout==0
0046 figure(100); clf
0047 subplot 121; nt_imagescc(fromGood);
0048 subplot 122; nt_topoplot(coordinates,topo);
0049 end
0050