Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero-crossings #17

Closed
DominiqueMakowski opened this issue Apr 22, 2022 · 2 comments
Closed

Zero-crossings #17

DominiqueMakowski opened this issue Apr 22, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@DominiqueMakowski
Copy link

DominiqueMakowski commented Apr 22, 2022

Hi Raph,

Was doing some cross-checking and I have a quick question to disperse a doubt in my mind regarding the counting of the number of inversions:

nzc = np.diff(np.signbit(x), axis=axis).sum(axis=axis)

Shouldn't it be: np.diff(np.signbit(np.diff( here? I.e., counting the changes in sign of the consecutive differences, rather than the difference of the sign of the consecutive samples 🤔

@raphaelvallat
Copy link
Owner

Hi @DominiqueMakowski!

You mean using np.diff(np.signbit(x), n=2).sum() instead of np.diff(np.signbit(x)).sum(), correct?

Taking a sine wave example, I think that the current method implemented in AntroPy is correct:

import numpy as np
import matplotlib.pyplot as plt
sf, f, dur = 100, 1, 4
N = sf * dur # Total number of discrete samples
t = np.arange(N) / sf # Time vector
x = np.sin(2 * np.pi * f * t)
plt.plot(t, x)
plt.xlim(t[0], t[-1])
plt.axhline(0);

image

There are 7 zero-crossings in x.

>>> def nzc(x, n):
>>>   return np.diff(np.signbit(x), n=n).sum()
>>> nzc(x, n=1), nzc(x, n=2)
(7, 14)

The n=1 method (default) gives the correct answer. The double differentiation leads to twice the expected number of zero-crossings.

Thanks,
Raphael

@raphaelvallat raphaelvallat self-assigned this Apr 22, 2022
@raphaelvallat raphaelvallat added the question Further information is requested label Apr 22, 2022
@DominiqueMakowski
Copy link
Author

Ah sorry yes I must have been asleep and missed one step ^^ (I was looking at here but I didn't see the that the diff was inside here) thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants