User Tools

Site Tools


implementation_unwrap_modulo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
implementation_unwrap_modulo [2018/09/19 17:11]
supergnu old revision restored (2018/09/19 14:52)
implementation_unwrap_modulo [2018/09/19 17:11] (current)
supergnu
Line 4: Line 4:
 It's an easy piece of code but handy to have it around off the shelf: It's an easy piece of code but handy to have it around off the shelf:
 <code C unwrap.c>​ <code C unwrap.c>​
-int unwrap(int *values, int numberOfValues,​ int modulo)+int unwrap(int *values, int numberOfValues,​ int modulo)//modulo = 360
 { {
-    for (int i = 0; i < numberOfValues;​ i++)+    ​int add = 0; 
 +    ​for (int i = 1; i < numberOfValues;​ i++)
     {     {
-        while(values[i] ​> modulo/2 || values[i] ​modulo/2)+        while(abs(values[i-1values[i])  > modulo/2)
         {         {
-            (values[i] > modulo/2) ? values[i] ​-= modulo : values[i] += modulo+            (values[i-1] > values[i]) ? add += modulo : add -= modulo; //could be faster if i kept the phase between samples 
-        }+            ​values[i] += add                                         // but longer and less easy to read, in case of perfomance 
 +        }                                                              // issue, there'​s probably a way to scrape a few cycles here 
 +        add = 0;
     }     }
 } }
 </​code>​ </​code>​
implementation_unwrap_modulo.txt · Last modified: 2018/09/19 17:11 by supergnu