3
$\begingroup$

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.

$\endgroup$
3
  • 2
    $\begingroup$ 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? $\endgroup$
    – xzczd
    Commented Nov 14, 2019 at 5:59
  • 3
    $\begingroup$ "unwrapping a phase" - have you seen this and this? $\endgroup$ Commented Nov 14, 2019 at 7:31
  • 3
    $\begingroup$ Related: PhaseUnwrap $\endgroup$ Commented Nov 14, 2019 at 14:47

1 Answer 1

6
$\begingroup$
a = {1.1, 1.3, 7.5, 1.4, 13.2};

FoldList[Plus, a[[1]], Mod[Differences[a], 6, -3]]

(*    {1.1, 1.3, 1.5, 1.4, 1.2}    *)

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

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.