1
$\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
    Nov 14 '19 at 5:59
  • 3
    $\begingroup$ "unwrapping a phase" - have you seen this and this? $\endgroup$
    – J. M.'s torpor
    Nov 14 '19 at 7:31
  • 3
    $\begingroup$ Related: PhaseUnwrap $\endgroup$ Nov 14 '19 at 14:47
4
$\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, privacy policy and cookie policy

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