Voss Connection Detection  1
Detect a connector click using realtime code on Bela hardware
classifier.cpp
Go to the documentation of this file.
1 #include "classifier.h"
2 
3 #if CONNDETECT_THRESHOLD_BASED == 1
4 #include "thresholds_config.h"
5 
6 
8 
9  bool conndetect = true;
10 
11  typedef FeatureType f;
12 
13  conndetect &= MIN_PEAK_HP8k_MICT <= ft[(int) f::HP_8k_PEAKdB_MICT];
14  conndetect &= MAX_PEAK_HP8k_MICT >= ft[(int) f::HP_8k_PEAKdB_MICT];
15 
16  conndetect &= MIN_PEAK_HP8k_MICW <= ft[(int) f::HP_8k_PEAKdB_MICW];
17  conndetect &= MAX_PEAK_HP8k_MICW >= ft[(int) f::HP_8k_PEAKdB_MICW];
18 
19  conndetect &= MIN_PEAK_HP2k_VPU <= ft[(int) f::HP_2k_PEAKdB_VPU];
20  conndetect &= MAX_PEAK_HP2k_VPU >= ft[(int) f::HP_2k_PEAKdB_VPU];
21 
22  conndetect &= MIN_PEAK_LP500_MICT <= ft[(int) f::LP_500_PEAKdB_MICT];
23  conndetect &= MAX_PEAK_LP500_MICT >= ft[(int) f::LP_500_PEAKdB_MICT];
24 
25  conndetect &= MIN_PEAK_LP500_MICW <= ft[(int) f::LP_500_PEAKdB_MICW];
26  conndetect &= MAX_PEAK_LP500_MICW >= ft[(int) f::LP_500_PEAKdB_MICW];
27 
28  conndetect &= MIN_PEAK_LP500_VPU <= ft[(int) f::LP_500_PEAKdB_VPU];
29  conndetect &= MAX_PEAK_LP500_VPU >= ft[(int) f::LP_500_PEAKdB_VPU];
30 
31  conndetect &= MIN_PEAKFREQ_HP2K_MICT <= ft[(int) f::HP_2k_PEAKFREQ_MICT];
32 
33  conndetect &= MIN_INVERSE_FREQ_VARIANCE_MICT <= ft[(int) f::INVERSE_FREQ_VARIANCE_MICT];
34 
35  conndetect &= MIN_WAMP_MICT <= ft[(int) f::WAMP_MICT];
36 
37  conndetect &= MIN_ZC_MICT <= ft[(int) f::ZC_MICT];
38 
39  conndetect &= MIN_AVG_IMU_ABS_ROT <= ft[(int) f::AVG_IMU_ABS_ROT];
40  conndetect &= MAX_AVG_IMU_ABS_ROT >= ft[(int) f::AVG_IMU_ABS_ROT];
41 
42  /* conndetect &= MIN_WAMP_MICW <= ft[(int) f::WAMP_MICW]; */
43  /* conndetect &= MIN_WAMP_VPU <= ft[(int) f::WAMP_VPU]; */
44 
45  /* conndetect &= MIN_ZC_MICT <= ft[(int) f::ZC_MICT]; */
46  /* conndetect &= MIN_ZC_MICW <= ft[(int) f::ZC_MICW]; */
47  /* conndetect &= MIN_ZC_VPU <= ft[(int) f::ZC_VPU]; */
48 
49  /* conndetect &= MIN_MIC_DELAY_MS <= ft[(int) f::TIMEDELAY_MICW_MICT]; */
50  /* conndetect &= MAX_MIC_DELAY_MS >= ft[(int) f::TIMEDELAY_MICW_MICT]; */
51 
52  /* conndetect &= MIN_INVERSE_FREQ_VARIANCE_MICT <= ft[(int) f::INVERSE_FREQ_VARIANCE_MICT]; */
53  /* conndetect &= MAX_INVERSE_FREQ_VARIANCE_MICT >= ft[(int) f::INVERSE_FREQ_VARIANCE_MICT]; */
54 
55  /* conndetect &= MIN_INVERSE_FREQ_VARIANCE_MICW <= ft[(int) f::INVERSE_FREQ_VARIANCE_MICW]; */
56  /* conndetect &= MAX_INVERSE_FREQ_VARIANCE_MICW >= ft[(int) f::INVERSE_FREQ_VARIANCE_MICW]; */
57 
58  /* conndetect &= MIN_KURTOSIS_MICT <= ft[(int) f::KURTOSIS_MICT]; */
59  /* conndetect &= MAX_KURTOSIS_MICT >= ft[(int) f::KURTOSIS_MICT]; */
60 
61  /* conndetect &= MIN_KURTOSIS_MICW <= ft[(int) f::KURTOSIS_MICW]; */
62  /* conndetect &= MAX_KURTOSIS_MICW >= ft[(int) f::KURTOSIS_MICW]; */
63 
64  /* conndetect &= MIN_KURTOSIS_VPU <= ft[(int) f::KURTOSIS_VPU]; */
65  /* conndetect &= MAX_KURTOSIS_VPU >= ft[(int) f::KURTOSIS_VPU]; */
66 
67  return conndetect;
68 }
69 #elif CONNDETECT_ML_BASED == 1
70 /* static_assert(false, "ML_BASED not implemented"); */
71 
72 #include "converted_ml_model.h"
73 
74 const ComputedFeatures NORMALIZE_OFFSET = {
75  -57.999f, // HP_8k_PEAKdB_MICT
76  -47.991f, // HP_8k_PEAKdB_MICW
77  -53.700f, // LP_500_PEAKdB_MICT
78  -34.158f, // LP_500_PEAKdB_MICW
79  -50.532f, // HP_2k_PEAKdB_VPU
80  -43.400f, // LP_500_PEAKdB_VPU
81  3.218e3f, // HP_2k_PEAKFREQ_MICT
82  6.389e-5f, // KURTOSIS_MICT
83  3.976e-1f, // INVERSE_FREQ_VARIANCE_MICT
84  1.734f, // WAMP_MICT
85  1.774e-7f, // TM3_MICT
86  3.174e-1f, // ZC_MICT
87  8.559e-4f, // KURTOSIS_MICW
88  1.498e-1f, // INVERSE_FREQ_VARIANCE_MICW
89  88.891f, // WAMP_MICW
90  1.678e-6f, // TM3_MICW
91  9.413f, // ZC_MICW
92  1.1e-3f, // KURTOSIS_VPU
93  84.877f, // WAMP_VPU
94  2.532e-6f, // TM3_VPU
95  4.086e-1f, // ZC_VPU
96  5.403f, // TIMEDELAY_MICW_MICT
97  5.75e-2f, // AVG_IMU_ABS_ROT
98  3.049e-1f, // AVG_IMU_ABS_ACC
99  0.0f, // PEDAL ==========================< NOT REQUIRED
100  0.0f // CLASS ==========================< NOT REQUIRED
101 
102 };
103 
104 const ComputedFeatures NORMALIZE_SCALE = {
105  5.452f, // HP_8k_PEAKdB_MICT
106  8.018f, // HP_8k_PEAKdB_MICW
107  4.785f, // LP_500_PEAKdB_MICT
108  5.694f, // LP_500_PEAKdB_MICW
109  5.838f, // HP_2k_PEAKdB_VPU
110  6.768f, // LP_500_PEAKdB_VPU
111  2.133e3f, // HP_2k_PEAKFREQ_MICT
112  2.4e-3f, // KURTOSIS_MICT
113  1.302f, // INVERSE_FREQ_VARIANCE_MICT
114  22.359f, // WAMP_MICT
115  4.709e-5f, // TM3_MICT
116  4.095f, // ZC_MICT
117  1.00e-2f, // KURTOSIS_MICW
118  3.417e-1f, // INVERSE_FREQ_VARIANCE_MICW
119  239.989f, // WAMP_MICW
120  1.944e-4f, // TM3_MICW
121  43.284f, // ZC_MICW
122  1.78e-2f, // KURTOSIS_VPU
123  161.151f, // WAMP_VPU
124  4.130e-4f, // TM3_VPU
125  4.876f, // ZC_VPU
126  11.772f, // TIMEDELAY_MICW_MICT
127  7.57e-2f, // AVG_IMU_ABS_ROT
128  3.54e-2f, // AVG_IMU_ABS_ACC
129  0.0f, // PEDAL ==========================< NOT REQUIRED
130  0.0f // CLASS ==========================< NOT REQUIRED
131 };
132 
133 bool Classifier::classify(const ComputedFeatures& ft) {
134 
135  ComputedFeatures normalized;
136 
137 
138  for(us i=0;i< static_cast<int>(FeatureType::NumberOfFeatures)-2; i++) {
139  normalized[i] = (ft[i] - NORMALIZE_OFFSET[i])/NORMALIZE_SCALE[i];
140  }
141  array<float, 12> used_features = {
142  normalized[1],
143  normalized[2],
144  normalized[3],
145  normalized[4],
146  normalized[5],
147  normalized[9],
148  normalized[12],
149  normalized[13],
150  normalized[14],
151  normalized[18],
152  normalized[21],
153  normalized[22],
154  };
155 
156  Eloquent::ML::Port::SVM svm;
157  return svm.predict((float *)used_features.data()) == 0;
158 
159 }
160 
161 #else
162 #error "Please choose either CONNDETECT_ML_BASED or CONNDETECT_THRESHOLD_BASED."
163 
164 #endif
Classifier::classify
bool classify(const ComputedFeatures &ft)
Perform classification, i.e. detect the threshold.
Definition: classifier.cpp:7
MIN_AVG_IMU_ABS_ROT
const float MIN_AVG_IMU_ABS_ROT
Definition: thresholds_config.h:74
MAX_PEAK_HP8k_MICT
const float MAX_PEAK_HP8k_MICT
Definition: thresholds_config.h:36
MIN_PEAK_HP8k_MICW
const float MIN_PEAK_HP8k_MICW
Minimum and maximum value of the 8k high-passed signal of the wrist microphone.
Definition: thresholds_config.h:40
FeatureType
FeatureType
These are the features extracted from the filtered data. They should be self-explaining regarding the...
Definition: conndetect.h:32
MIN_PEAK_HP8k_MICT
const float MIN_PEAK_HP8k_MICT
The minimal delay in ms the microphone signals should have, for a positive connection detection.
Definition: thresholds_config.h:35
thresholds_config.h
Configuration parameters for connection detection based on thresholds. Note that these values are "in...
MAX_PEAK_HP2k_VPU
const float MAX_PEAK_HP2k_VPU
Definition: thresholds_config.h:47
MIN_INVERSE_FREQ_VARIANCE_MICT
const float MIN_INVERSE_FREQ_VARIANCE_MICT
Definition: thresholds_config.h:68
MAX_AVG_IMU_ABS_ROT
const float MAX_AVG_IMU_ABS_ROT
Definition: thresholds_config.h:75
MIN_PEAK_LP500_MICW
const float MIN_PEAK_LP500_MICW
Minimum and maximum value of the 500 low-passed signal of the wrist microphone.
Definition: thresholds_config.h:57
MAX_PEAK_LP500_MICW
const float MAX_PEAK_LP500_MICW
Definition: thresholds_config.h:58
MIN_PEAK_HP2k_VPU
const float MIN_PEAK_HP2k_VPU
Minimum and maximum value of the 2k high-passed signal of the VPU.
Definition: thresholds_config.h:46
MIN_PEAK_LP500_VPU
const float MIN_PEAK_LP500_VPU
Minimum and maximum value of the 500 low-passed signal of the VPU.
Definition: thresholds_config.h:63
ComputedFeatures
std::array< float,(us) NUMBER_FEATURES > ComputedFeatures
Definition: conndetect.h:78
MAX_PEAK_HP8k_MICW
const float MAX_PEAK_HP8k_MICW
Definition: thresholds_config.h:41
MIN_PEAKFREQ_HP2K_MICT
const float MIN_PEAKFREQ_HP2K_MICT
Definition: thresholds_config.h:66
MIN_PEAK_LP500_MICT
const float MIN_PEAK_LP500_MICT
Minimum and maximum value of the 500 low-passed signal of the thumb microphone.
Definition: thresholds_config.h:52
MIN_WAMP_MICT
const float MIN_WAMP_MICT
Definition: thresholds_config.h:70
classifier.h
us
unsigned int us
Used to much to not abbreviate.
Definition: config.h:38
MIN_ZC_MICT
const float MIN_ZC_MICT
Definition: thresholds_config.h:72
MAX_PEAK_LP500_MICT
const float MAX_PEAK_LP500_MICT
Definition: thresholds_config.h:53
FeatureType::NumberOfFeatures
@ NumberOfFeatures
MAX_PEAK_LP500_VPU
const float MAX_PEAK_LP500_VPU
Definition: thresholds_config.h:64