# Phase unwrapping

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.

• 1. 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? Nov 14 '19 at 5:59
• "unwrapping a phase" - have you seen this and this? Nov 14 '19 at 7:31
• Related: PhaseUnwrap Nov 14 '19 at 14:47

a = {1.1, 1.3, 7.5, 1.4, 13.2};

If and For are not ideal; better do list processing.