Giter Site home page Giter Site logo

Zero-crossings about antropy HOT 2 CLOSED

raphaelvallat avatar raphaelvallat commented on May 20, 2024
Zero-crossings

from antropy.

Comments (2)

raphaelvallat avatar raphaelvallat commented on May 20, 2024

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

from antropy.

DominiqueMakowski avatar DominiqueMakowski commented on May 20, 2024

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!

from antropy.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.