-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
nelsoncardenas
wants to merge
1
commit into
blue-yonder:main
Choose a base branch
from
nelsoncardenas:patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.