Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written an algorithm that calculates the number of zero-crossings within a signal. By this, I mean the number of times a value changes from + to - and vise versa.

The algorithm is explained like this:

If there are the following elements:

v1 = {90, -4, -3, 1, 3}

Then you multiply the value by the value next to it. (i * i+1)

Then taking the sign value sign(val) determine if this is positive or negative. Example:

e1 = {90 * -4} = -360 -> sigum(e1) = -1 
e2 = {-4 * -3} =  12  -> signum(e2) = 1
e3 = {-3 *  1} =  -3  -> signum(e3) = -1
e4 = {1 *   3} =  3   -> signum(e4) = 1

Therefore the total number of values changed from negative to positive is = 2 ..

Now I want to put this forumular, algorithm into an equation so that I can present it.

I have asked a simular question, but got really confused so went away and thought about it and came up with (what I think the equation should look like).. It's probably wrong, well, laughably wrong. But here it is:

enter image description here

Now the logic behind it:

I pass in a V (val)

I get the absolute value of the summation of the signum from calculating (Vi * Vi+1) .. The signum(Vi * Vi+1) should produce -1, 1, ..., values

If and only if the value is -1 (Because I'm only interested in the number of times zero is crossed, therefore, the zero values.

Does this look correct, if not, can anyone suggest improvements?

Thank you :)!

share|cite|improve this question
up vote 1 down vote accepted

I think you mean $(1-\text{sgn}(V_i V_{i+1}))/2$. That is $1$ if the signum is $-1$ and $0$ if the signum is $1$. The absolute value, on the other hand, is $1$ whether the signum is $+1$ or $-1$.

But what are you going to do about cases where $V_i = 0$?

share|cite|improve this answer
I think I get what you mean. I've discovered that my current equation sums up the sign even if the value isn't -1. sum(sign(v1 * v1+i)) But I don't understand the fix for this. Should I carry out the signum of the (v[1] * v[1+1]) and then IF the value is -1 then get the summation? – Phorce Nov 22 '12 at 0:47
The fix is to take $\sum_i (1 - \text{sgn}(V_i V_{i+1}))/2$. Thus you are adding $1$ when the signum is $-1$ and you are adding $0$ when the signum is $1$. The result is the number of times that the signum is $-1$. – Robert Israel Nov 22 '12 at 0:51
Thank you!!! That makes sense. By the "1 -" with the "-" does this symbol just represent subtracting? – Phorce Nov 22 '12 at 0:53
@RobertIsrael: That doesn't quite work... it doesn't distinguish between "+1,0,-1" and "+1,0,+1", although one has a zero crossing and the other doesn't. – mjqxxxx Nov 22 '12 at 6:01
@mjqxxxx: That's why I asked "But what are you going to do about cases where $V_i = 0$?" – Robert Israel Nov 22 '12 at 8:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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