Voss Connection Detection  1
Detect a connector click using realtime code on Bela hardware
conndetect_features.h
Go to the documentation of this file.
1 #pragma once
2 #include "config.h"
3 #include <array>
4 #include <libraries/Fft/Fft.h>
5 #include <vector>
6 
18 class Features {
19 
20  const Channel *_rawdata;
24  Channel _window;
30  Channel _absdelta;
34  std::vector<float> _wbd;
38  std::array<float, BLOCKSIZE / 2 + 1> _freq;
39 
40  Fft fft;
44  std::array<float, BLOCKSIZE / 2 + 1> _Ssq;
48  float _fc;
52  us _idx_peak;
53 
57  float _Ssq_tot;
58 
63  Channel _signal_squared;
64 
68  float _ms = 0.0f;
69 
70 public:
76  Features(const float fs);
83  void setChannel(const Channel &channel);
84 
93  float peak_dB();
94 
104  float rms_dB();
105 
114  float kurtosis();
115 
129  float peak_freq();
130 
139  float wamp(float wampl);
140 
147  float zc(float zc_l);
148 
156  float TM3();
164  float TM5();
165 
179  float inverse_variance();
180 
181 private:
182  bool _ms_computed = false;
183  bool _fft_computed = false;
184  bool _delta_computed = false;
185 
189  void compute_ms();
190  void compute_fft();
191  void compute_delta();
192 };
193 
194 #include <numeric>
195 #include <algorithm>
201  public:
209  static float average(const Channel& i) {
210  return std::accumulate(i.begin(), i.end(), 0.0)/BLOCKSIZE;
211  }
219  static float hasNonZero(const Channel& i) {
220  auto nonzero = [](us i) { return i>1e-6; };
221  return (float) (std::any_of(i.begin(), i.end(), nonzero));
222  }
231  static float maximum(const Channel& i){
232  return *std::max_element(i.begin(), i.end());
233  }
234 
235 };
236 
Features::TM3
float TM3()
Temporal moment 3, defined as.
Definition: conndetect_features.cpp:164
SimpleFeatures
Some very simple features that are more easily kept in a different class.
Definition: conndetect_features.h:200
Channel
std::array< float, BLOCKSIZE > Channel
A Channel contains data for the length of BLOCKSIZE.
Definition: config.h:183
Features::wamp
float wamp(float wampl)
Willson amplitude. Counts the number of difss in amplitude that have an absolute change in value larg...
Definition: conndetect_features.cpp:143
SimpleFeatures::maximum
static float maximum(const Channel &i)
Find the maximum value in a strictly positive array. No checks on positiveness are done!
Definition: conndetect_features.h:231
Features::inverse_variance
float inverse_variance()
Inverse of the variance in the center frequency, defined as:
Definition: conndetect_features.cpp:179
Features::rms_dB
float rms_dB()
Compute the rms level in dB (full scale, normalized to 1). The equation is:
Definition: conndetect_features.cpp:65
Features::Features
Features(const float fs)
Create features instance.
Definition: conndetect_features.cpp:31
Features::peak_freq
float peak_freq()
Compute the frequency at which the spectrum has the most power. It is defined as:
Definition: conndetect_features.cpp:129
BLOCKSIZE
const us BLOCKSIZE
The size of a buffer in a block. Should be an integer number of samples, and preferrably a integer po...
Definition: config.h:105
us
unsigned int us
Used to much to not abbreviate.
Definition: config.h:38
Features::setChannel
void setChannel(const Channel &channel)
Set channel data to operate on. BORROWS the data on which it operates, be carefull not to delete the ...
Definition: conndetect_features.cpp:43
Features
This class provides the calculations of single-signal features, computed from a single channel with l...
Definition: conndetect_features.h:18
config.h
Configuration parameters for connection detection.
Features::kurtosis
float kurtosis()
Compute the kurtosis , scaled. It is defined as:
Definition: conndetect_features.cpp:70
Features::zc
float zc(float zc_l)
Compute zero-crossings with a difference larger than zcl.
Definition: conndetect_features.cpp:153
SimpleFeatures::hasNonZero
static float hasNonZero(const Channel &i)
Find a nonzero in the array.
Definition: conndetect_features.h:219
Features::peak_dB
float peak_dB()
Compute the peak level in dB (full scale, normalized to 1). The equation is:
Definition: conndetect_features.cpp:55
Features::TM5
float TM5()
Temporal moment 5, defined as.
Definition: conndetect_features.cpp:172
SimpleFeatures::average
static float average(const Channel &i)
Compute the average of a channel value.
Definition: conndetect_features.h:209