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

Add: slope_sign_change, log_detector and willison_amplitude #826

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions tsfresh/feature_extraction/feature_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2361,3 +2361,66 @@ def query_similarity_count(x, param):
res[key] = count

return [(key, value) for key, value in res.items()]


@set_property("fctype", "simple")
def slope_sign_change(x, t=0):
"""
Returns the number of times that slope of the EMG signal changes sign. This feature meassures frequency. It uses a threshold to avoid noise. See SSC in [1].

:param x: the time series to calculate the feature of
:type x: numpy.ndarray
:param t: value used as threshold
:type t: float
:return: the value of this feature
:return type: int

References
| [1] Phinyomark, A., Phukpattaranont, P., & Limsakul, C. (2012). Feature reduction and selection for EMG signal classification. Expert systems with applications, 39(8), 7420-7431.
"""
# Calculation of feature as int
x = np.asarray(x)
left = x[1:-1] - x[:-2]
right = x[1:-1] - x[2:]
product = left * right
f = np.sum(product > t)
return f


@set_property("fctype", "simple")
def log_detector(x):
"""
Returns a number related to the "force" of a signal. These approaches are based on a functional mathematical model for EMG signal generation. See Log detector in [1] and [2].

:param x: the time series to calculate the feature of
:type x: numpy.ndarray
:return: the value of this feature
:return type: float

References
| [1] Phinyomark, A., Phukpattaranont, P., & Limsakul, C. (2012). Feature reduction and selection for EMG signal classification. Expert systems with applications, 39(8), 7420-7431.
| [2] Zardoshti-Kermani, M., Wheeler, B. C., Badie, K., & Hashemi, R. M. (1995). EMG feature evaluation for movement control of upper extremity prostheses. IEEE Transactions on Rehabilitation Engineering, 3(4), 324-333.
"""
# Calculation of feature as float
x = np.asarray(x)
n = len(x)
x = x + (x == 0)*0.000000000001
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the motivation behind this line?

Copy link
Author

@nelsoncardenas nelsoncardenas May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I investigated it better and I think what I did is not a good strategy. The idea was to avoid errors generated by values equal to zero for the next line but we use a low value, and this tends to infinity.

return np.exp(np.sum(np.log(np.abs(x)))/n)


@set_property("fctype", "simple")
def willison_amplitude(x, t):
"""
Returns how many times the difference between the signal amplitude among two adjoining segments exceeds a pre-defined threshold. See WAMP in [1].

:param x: the time series to calculate the feature of
:type x: numpy.ndarray
:return: the value of this feature
:return: type: int

References
| [1] Phinyomark, A., Phukpattaranont, P., & Limsakul, C. (2012). Feature reduction and selection for EMG signal classification. Expert systems with applications, 39(8), 7420-7431.
"""
# Calculation of feature as int
return np.sum(np.abs(x[1:] - x[:-1]) > t)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of x[1:] - x[:-1] I think you could use np.diff