Home > matutils > instability.m

instability

PURPOSE ^

function flag=instability(v,t,flag,spike,maxt)

SYNOPSIS ^

function flag=instability(v,t,flag,spike,maxt)

DESCRIPTION ^

 function flag=instability(v,t,flag,spike,maxt)

 will find unstable regions.  this includes singular spikes

 Input:
     v - data vector
     t - time, or x axis value
  flag - if empty will be initialized to zeros
         otherwise it is bad values within v
  spike- max difference considered to be unstable
  maxt - max time jump

 Output;
  flag - location of bad points

 Michael Loh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function flag=instability(v,t,flag,spike,maxt)
0002 
0003 % function flag=instability(v,t,flag,spike,maxt)
0004 %
0005 % will find unstable regions.  this includes singular spikes
0006 %
0007 % Input:
0008 %     v - data vector
0009 %     t - time, or x axis value
0010 %  flag - if empty will be initialized to zeros
0011 %         otherwise it is bad values within v
0012 %  spike- max difference considered to be unstable
0013 %  maxt - max time jump
0014 %
0015 % Output;
0016 %  flag - location of bad points
0017 %
0018 % Michael Loh
0019 
0020 if (isempty(flag))
0021   flag=zeros(size(v));
0022 end
0023 
0024 difv=diff(v);
0025 f=find(abs(difv)<spike);
0026 difv(f)=0;
0027 
0028 % use findramp to find potential ramps using specs for strings
0029 ramploc=findramp(v,[],spike);
0030 f=find(ramploc);
0031 difv(f)=0;
0032 
0033 % now find real unstable points
0034 f=find(abs(difv)<spike);
0035 difv(f)=0;
0036 [s,e]=group(difv~=0);
0037 
0038 string=find((e-s)>0);
0039 
0040 for i=1:length(string)
0041   start=s(string(i));
0042   stop=e(string(i));
0043   if (start==1)
0044     tstart=start;
0045   else
0046     tstart=start+1;
0047   end
0048   if ((t(stop)-t(tstart))>=maxt)
0049     flag(start+1:stop)=1;
0050   elseif ((stop-start)==1)
0051     % do findspike stuff here.
0052     % since all ramps are already caught, everything here should be
0053     % alternating
0054     for j=start:stop-1
0055       ph1=difv(j);
0056       ph2=difv(j+1);
0057       if (abs(ph1+ph2)>=spike)
0058     flag(j:j+2)=1;
0059       else
0060     flag(j+1)=1;
0061       end
0062     end
0063   end
0064   difv(start:stop)=0;
0065 end
0066

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005