File size: 1,204 Bytes
3c10b34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
A set of mocap feature extraction functions

Created by Omid Alemi | Nov 17 2017

"""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import peakutils


def get_foot_contact_idxs(signal, t=0.02, min_dist=120):
    up_idxs = peakutils.indexes(signal, thres=t / max(signal), min_dist=min_dist)
    down_idxs = peakutils.indexes(-signal, thres=t / min(signal), min_dist=min_dist)

    return [up_idxs, down_idxs]


def create_foot_contact_signal(mocap_track, col_name, start=1, t=0.02, min_dist=120):
    signal = mocap_track.values[col_name].values
    idxs = get_foot_contact_idxs(signal, t, min_dist)

    step_signal = []

    c = start
    for f in range(len(signal)):
        if f in idxs[1]:
            c = 0
        elif f in idxs[0]:
            c = 1

        step_signal.append(c)

    return step_signal


def plot_foot_up_down(mocap_track, col_name, t=0.02, min_dist=120):
    signal = mocap_track.values[col_name].values
    idxs = get_foot_contact_idxs(signal, t, min_dist)

    plt.plot(mocap_track.values.index, signal)
    plt.plot(mocap_track.values.index[idxs[0]], signal[idxs[0]], "ro")
    plt.plot(mocap_track.values.index[idxs[1]], signal[idxs[1]], "go")