I've been searching the answer for an exercise. This exercise gives us an array with numbers between -1 and 1. We are asked to count how many times the signal array changes sign. For example : you have this array : [0.7,0.5,0.6,-0.1,0.9,0.6,0.4,-0.2,-0.3,0.2,0.3,-0.3,-0.9,-0.7,0.1,0.2] It changes signs 7 times This is the code I have made that should get the "count" of how many times it changes signs. For some reason, it doesn't work, the count at the end is equal to 0 and it should be 7. Can you help me please ? Thank you very much.
--THE CODE--
import numpy as np
def zeroCrossing(signal):
j=0
ls=len(signal)
print(ls)
count=0
x=0
y=0
for j in range(0,ls):
if signal[j]>0 and x==1:
j=j+1
y=0
elif signal[j]>0 and x==0:
count==count+1
x=1
j=j+1
elif signal[j]<0 and y==1:
j=j+1
x=0
elif signal[j]<0 and y==0:
count==count+1
y=1
j=j+1
return count
print(zeroCrossing(np.array([0.7,0.5,0.6,-0.1,0.9,0.6,0.4,-0.2,-0.3,0.2,0.3,-0.3,-0.9,-0.7,0.1,0.2])))