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
Next revision
Previous revision
implementation_unwrap_modulo [2018/09/19 16:45]
supergnu
implementation_unwrap_modulo [2018/09/19 17:11]
supergnu
Line 1: Line 1:
-====== C implementation of a modulo function ======+====== C implementation of the Octave/Matlab unwrap function ======
  
 +The unwrap function in Octave/Matlab is simplifying the modulo of an arrray.
 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 modulo.c> +<code C unwrap.c> 
-int modulo(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