3

I am facing a problem in unwrapping a phase. I have a data set presented by $a_i$, where $i$ varies from $1$ to $N$. I need it as follows:

  • If $\mathrm{abs}(a_{i+1} - a_i) > 3$, add $6 k \,$ to $a_{i+1}$, otherwise return $a_{i+1}$. If $a_{i+1} > a_i$ for the first time, $k = -1$, otherwise $k = 1$.

  • For every time $\mathrm{abs}(a_{i+1} - a_i) > 3$ and $a_{i+1} > a_i$, $k \to k + 1$ otherwise $k \to k - 1$.

    For example, the first time $\mathrm{abs}(a_{i+1} - a_i) > 3$, add $6$ if $a_{i+1} > a_i$. For the second time $\mathrm{abs}(a_{i+1} - a_i) > 3$, add $12$ if $a_{i+1} > a_i$. And for third time, if $a_{i+1} < a_i$, add $6$ not $18$.

So, can anyone please help me to write the code in Mathematica for the above logic. I am getting stuck. And thank you in adv. for the help.

P Pyne
  • 453
  • 2
  • 9
  • 2
  • Is this question about software Mathematica? 2. If the answer to the first problem is yes, then please illustrate your problem with a specific example, currently your question is not clear. 3. What have you tried so far?
  • – xzczd Nov 14 '19 at 05:59
  • 3
    "unwrapping a phase" - have you seen this and this? – J. M.'s missing motivation Nov 14 '19 at 07:31
  • 3