neurogeriatricskiel / KielMAT

Python based toolbox for processing motion data
https://neurogeriatricskiel.github.io/KielMAT/
Other
6 stars 1 forks source link

Find negative peaks #108

Closed rmndrs89 closed 1 month ago

rmndrs89 commented 1 month ago

https://github.com/neurogeriatricskiel/KielMAT/blob/c50191cad3e2a4d2631664c97afc738d4b08d582/kielmat/modules/ptd/_pham.py#L246

Dear @masoudabedinifar ,

this does not detect the negative peaks. It merely find the peaks whose values are greater than -0.2. To find the negative peaks you need to negate the signal:

import numpy as np
import scipy
import matplotlib.pyplot as plt

t = np.linspace(0, 1, num=1000, endpoint=False)
x = 3 * np.cos(2 * np.pi * 10 * t)

thr_pos = 0.5
ipks_pos, _ = scipy.signal.find_peaks(x, height=thr_pos)

thr_neg = -0.5
ipks_neg, _ = scipy.signal.find_peaks(x, height=thr_neg)

fig, ax = plt.subplots()
ax.plot(t, x)
ax.axhline(thr_pos, c="red", ls="-.")
ax.axhline(thr_neg, c="red", ls="-.")
ax.plot(t[ipks_pos], x[ipks_pos], ls="none", marker="*")
ax.plot(t[ipks_neg], x[ipks_neg], ls="none", marker="o", mfc="none", ms=10)
plt.show()

versus

import numpy as np
import scipy
import matplotlib.pyplot as plt

t = np.linspace(0, 1, num=1000, endpoint=False)
x = 3 * np.cos(2 * np.pi * 10 * t)

thr = 0.5
ipks_pos, _ = scipy.signal.find_peaks(x, height=thr)
ipks_neg, _ = scipy.signal.find_peaks(-x, height=thr)

fig, ax = plt.subplots()
ax.plot(t, x)
ax.axhline(thr, c="red", ls="-.")
ax.axhline(-thr, c="red", ls="-.")
ax.plot(t[ipks_pos], x[ipks_pos], ls="none", marker="*")
ax.plot(t[ipks_neg], x[ipks_neg], ls="none", marker="o", mfc="none", ms=10)
plt.show()

Could you update this, and maybe check if you have done this trick at some other places in the code as well?

LG Robbin

masoudabedinifar commented 1 month ago

Dear @rmndrs89,

This issue is currently mentioned in Orientation estimation using VQF and will be handled altogether.

Best, Masoud