0
$\begingroup$

I have developed an algorithm that counts the number of times a particular block (within a 2D Matrix) crosses zero. Here's an example:

Matrix = {             1, 2, -1, -0.1,             4, 3, -6, -12,             12, 2, -5, 19,             8, -1, 12, -9,           } 

Then the matrix is split into sub-matrices (or blocks)

B1 = {         1, 2,         4, 3      }  B2 = {         -1, -0.1,         -6, -12,      }  ...,  ...,   ... 

An example summing up each of the blocks is:

Ex=∑n|x[n]|2

Find the signum value of each element within the block (will return "1", "-1", "0") respectively.

If the signum value returns -1 then count increments by 1.

This will repeat until the there is no blocks, however, will only produce 1 value per block.

I am looking for a way to put all this process into an equation so I can demonstrate this rather than having to explain the processes in written text everytime. Is this possible?

  • 0
    @ErickWong If we forget about the "blocks" and just assumed we have an array of double values.. "0.1, -0.90, ...," would copper.hat's equation be right?2012-11-21

2 Answers 2

2

Suppose your data is $x_1,...,x_n$, then let $C(x) = | \{i | i=0,...,n-1,\ \mathbb{sgn}\, x_i \neq \mathbb{sgn}\, x_{i+1} \} |$.

Unfortunately the above is wrong when $x$ contains zeros. The fix is cumbersome: $ C(x) = | \{i | i < n,\, \exists j >i,\, j\leq n,\, |\mathbb{sgn}\, x_i -\mathbb{sgn}\, x_j|=2, \, x_{i+1} = \cdots = x_{j-1} = 0 \} |$ This presumes that $\mathbb{sgn}\, 0 = 0$.

  • 0
    No no, what you have done is great. I have developed and coded the algorithm and it's perfect, I just needed a way to represent it mathematically. But thank you once again for your help2012-11-21
2

If data is $B=(b_1, b_2, \ldots, b_n)$ and all numbers are nonzero then the number of zero cross-overs will be

$N(B)=\sum_{i=1}^{n-1} \frac{1}{2}|\mathrm{sgn} b_i - \mathrm{sgn} b_{i+1} |$

If you have zeros in the data, you should remove them before applying this, otherwise a closed-form equation would be too cumbersome.

  • 0
    Ok, I understand it.. Just the "−" between the two sgn .. are you representing the values with this line?2012-11-21