Mid-term feature extraction
(signal, sampling_rate, mid_window, mid_step,
short_window, short_step)
| 85 | |
| 86 | |
| 87 | def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step, |
| 88 | short_window, short_step): |
| 89 | """ |
| 90 | Mid-term feature extraction |
| 91 | """ |
| 92 | |
| 93 | short_features, short_feature_names = \ |
| 94 | ShortTermFeatures.feature_extraction(signal, sampling_rate, |
| 95 | short_window, short_step) |
| 96 | |
| 97 | n_stats = 2 |
| 98 | n_feats = len(short_features) |
| 99 | #mid_window_ratio = int(round(mid_window / short_step)) |
| 100 | mid_window_ratio = round((mid_window - |
| 101 | (short_window - short_step)) / short_step) |
| 102 | mt_step_ratio = int(round(mid_step / short_step)) |
| 103 | |
| 104 | mid_features, mid_feature_names = [], [] |
| 105 | for i in range(n_stats * n_feats): |
| 106 | mid_features.append([]) |
| 107 | mid_feature_names.append("") |
| 108 | |
| 109 | # for each of the short-term features: |
| 110 | for i in range(n_feats): |
| 111 | cur_position = 0 |
| 112 | num_short_features = len(short_features[i]) |
| 113 | mid_feature_names[i] = short_feature_names[i] + "_" + "mean" |
| 114 | mid_feature_names[i + n_feats] = short_feature_names[i] + "_" + "std" |
| 115 | |
| 116 | while cur_position < num_short_features: |
| 117 | end = cur_position + mid_window_ratio |
| 118 | if end > num_short_features: |
| 119 | end = num_short_features |
| 120 | cur_st_feats = short_features[i][cur_position:end] |
| 121 | |
| 122 | mid_features[i].append(np.mean(cur_st_feats)) |
| 123 | mid_features[i + n_feats].append(np.std(cur_st_feats)) |
| 124 | cur_position += mt_step_ratio |
| 125 | mid_features = np.array(mid_features) |
| 126 | mid_features = np.nan_to_num(mid_features) |
| 127 | return mid_features, short_features, mid_feature_names |
| 128 | |
| 129 | |
| 130 | """ Feature Extraction Wrappers |
no outgoing calls
no test coverage detected