Help with a pulse detection func

I can recall many times when code would run and the results were interpreted completely wrong. To be honest, I've done it with every bug I've had any trouble with.