0

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!!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Aretu
  • 5
  • 3

1 Answers1

1

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,

knedlsepp
  • 6,065
  • 3
  • 20
  • 41
Ratbert
  • 5,463
  • 2
  • 18
  • 37
  • Cool, didn't know about `unwrap`! – knedlsepp Feb 15 '15 at 12:14
  • 1
    Did you mean `cumsum`? – knedlsepp Feb 15 '15 at 12:18
  • Well, both sum and cumsum can be used, depending on what you want to do. – Ratbert Feb 15 '15 at 13:38
  • 1
    Oh! I see we don't need the `diff` and `cumsum` then! In this case I even think *BasSwinckels*' answer is what the OP wants. – knedlsepp Feb 15 '15 at 13:42
  • Thank you for the answer, but probably I have mispoken the starting data: https://dl.dropboxusercontent.com/u/72363476/angle.fig When I use diff and unwrap as you told me, the total displacement is strongly affected by the angle inversion between a 355 and the next 0, thus I've got a strongly negative cumulative angle ~-60 – Aretu Feb 15 '15 at 13:56
  • @Aretu: I don't get it. The proposed solution works for me. (loose the `sum` and `diff`) What's the problem? – knedlsepp Feb 15 '15 at 15:03
  • Thank you for making me know about the unwrap, I solved it with Angle2 from the for cycle and then unwrapping it! – Aretu Feb 15 '15 at 15:27