matlabincrementreductionperiodic-processing

Periodic to incremental (data reduction)


It's some time I was thinking about solving this problem. I have a registration of angular data (Angle(~20000,1)) variating between 0 and 355 (a potentiometer attached to a rotary testing machine), and I wanted to convert it in an incremental form, since I want the final total angular displacement. The main issue is that between 355 and the next 0 there are no jumps but a fast decrement (with strongly negative slope in time vs angle space). I've tried 2 ways up to now:

  1. Calculate the Angslope=diff(Angle), extract with find the indexes j1=find(Angslope>0.2 & Angslope<0.2) to avoid the negative slopes due to the inversion of angular signal, then try to apply those indexes to the original Angle(n,1), as Angle2=Angle(j1). The trouble is the n-1 length of Angslope and the fact that somehow there is not a simple shift of my indexes of one position.

  2. For cycles and logical, wanting to exclude data if the previous one is < the current value,etc

    Angle2=zeros(size(Angle,1),1);
    
    for i=2:size(Angle,1) 
       if Angle(i,1)<Angle(i-1,1) 
       Angle2(i,1)=NaN;
       else    Angle2(i,1)=Angle(i,1);
       end
    end
    

Which works good, but I don't know how to "match up" the single increment steps I obtain!

Any help or simple comment would be of great help!!


Solution

  • You are probably looking for the unwrap function. For this you have to convert your angles into radians, but that's not a big deal.

    You can get the increments in one line:

    Inc = diff(unwrap(Angle*pi/180))*180/pi;
    

    and your total angular displacement:

    Tot = sum(Inc);
    

    Best,