![]() |
![]() |
|
EDGEAI API
|
PRELIMINARY Feature Extraction for EdgeAI
WARNING These set of functions are PRELIMINARY, and subject to change in the next few months.
To use the Feature Extraction library, include this header file in the application as follows:
This library will serve as a pre-processing stage where raw signal inputs will be fed to the feature extraction library and the resulting output will be fed into the pre-compiled NN model. The function that have been implemented so far are the following:
To use the Feature Extraction Library call the previous APIs accordingly.
#include <stddef.h>#include <stdint.h>
Go to the source code of this file.
Macros | |
| #define | ADCSAMPLESIZE 125 |
| #define | SAMPLING_FREQ 25 |
| #define | PADDING_SIZE_LEFT 4 |
| #define | PADDING_SIZE_RIGHT 3 |
| #define | PADDED_INPUT_SIZE (ADCSAMPLESIZE + PADDING_SIZE_LEFT + PADDING_SIZE_RIGHT) |
| #define | WINDOW_SIZE 32 |
| #define | WINDOW_STRIDE_SIZE 4 |
| #define | NUM_WINDOWS 25 |
| #define | FFT_SIZE 64 |
| #define | NUM_BINS (FFT_SIZE / 2) |
| #define | POOLED_BINS (NUM_BINS / 2) |
| #define | TOP_N_FREQ 2 |
| #define | KURTOSIS_CHUNK_SIZE 8 |
| #define | KURTOSIS_STRIDE_SIZE 8 |
| #define | NUM_FEAT_FFT 16 |
| #define | NUM_FEAT_TOPFREQ TOP_N_FREQ |
| #define | NUM_FEAT_KURTOSIS 4 |
| #define | NUM_FEAT_ZCR 1 |
| #define | NUM_FEAT_SLOPE 1 |
| #define | NUM_FEAT_PW_SPEC 1 |
| #define | NUM_TOTAL_FEATURES 25 |
Enumerations | |
| enum | fe_status_t { FE_OK = 0x00, FE_ERR_NULLPTR = 0x01, FE_ERR_BAD_PARAM = 0x02, FE_ERR_DSP = 0x03 } |
| Specifies the FE status codes. More... | |
Functions | |
| fe_status_t | FE_applyWindow (const uint8_t *data_stream, uint8_t output_windows[25][32]) |
| Builds padded/sliding windows from an input stream considering a stride size. More... | |
| fe_status_t | FE_zeroCrossingRate (const uint8_t *input_window, float *zcr_out) |
| Measures of how often a signal crosses the zero axis, indicating the frequency or noisiness of a signal. More... | |
| fe_status_t | FE_slopeChanges (const uint8_t *input_window, float *slope_changes) |
| Counts the sign changes of signal differences. More... | |
| fe_status_t | FE_fftPool (const uint8_t *input_window, float *fft_output_pool_mag) |
| calculate FFT magnitudes and pooling (averaging) to produce NUM_FEAT_FFT features. More... | |
| fe_status_t | FE_topFrequencies (const uint8_t *input_window, float *top_freqs) |
| Extract the index of the dominant frequencies (Hz) per window. More... | |
| fe_status_t | FE_spectralEntropy (const uint8_t *input_window, float *entropy_out) |
| Calculates the Shannon spectral entropy. The Spectral Entropy acts as an indicator of how spread out the power is. More... | |
| fe_status_t | FE_kurtosis (const uint8_t *input_window, float *kurtosis_output) |
| Calculates the fisher or excess kurtosis without bias for each segment of a given series. Kurtosis describes the "peakedness" of a probability distribution. More... | |
| fe_status_t | FE_concatenateFeatures (const float *fft_output_pool_mag, uint32_t window_index, const float *kurtosis_output, const float *zcr, const float *slope_changes, const float *top_dominant_freq, const float *power_spectrum, float *concatenated_features) |
| Concatenate many feature arrays into a big feature vector. The offsets are determined by NUM_FEAT_X and NUM_WINDOWS macros. More... | |
Variables | |
| uint32_t | samplingfreq |
| #define ADCSAMPLESIZE 125 |
| #define SAMPLING_FREQ 25 |
| #define PADDING_SIZE_LEFT 4 |
| #define PADDING_SIZE_RIGHT 3 |
| #define PADDED_INPUT_SIZE (ADCSAMPLESIZE + PADDING_SIZE_LEFT + PADDING_SIZE_RIGHT) |
| #define WINDOW_SIZE 32 |
| #define WINDOW_STRIDE_SIZE 4 |
| #define NUM_WINDOWS 25 |
| #define FFT_SIZE 64 |
| #define NUM_BINS (FFT_SIZE / 2) |
| #define POOLED_BINS (NUM_BINS / 2) |
| #define TOP_N_FREQ 2 |
| #define KURTOSIS_CHUNK_SIZE 8 |
| #define KURTOSIS_STRIDE_SIZE 8 |
| #define NUM_FEAT_FFT 16 |
| #define NUM_FEAT_TOPFREQ TOP_N_FREQ |
| #define NUM_FEAT_KURTOSIS 4 |
| #define NUM_FEAT_ZCR 1 |
| #define NUM_FEAT_SLOPE 1 |
| #define NUM_FEAT_PW_SPEC 1 |
| #define NUM_TOTAL_FEATURES 25 |
| enum fe_status_t |
Specifies the FE status codes.
This enum defines the return states of the FE functions.
| fe_status_t FE_applyWindow | ( | const uint8_t * | data_stream, |
| uint8_t | output_windows[25][32] | ||
| ) |
Builds padded/sliding windows from an input stream considering a stride size.
| [in] | data_stream | pointer to input data stream [ADCSAMPLESIZE] for time series. |
| [out] | output_windows | preallocated 2D-array [NUM_WINDOWS][WINDOW_SIZE]. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_zeroCrossingRate | ( | const uint8_t * | input_window, |
| float * | zcr_out | ||
| ) |
Measures of how often a signal crosses the zero axis, indicating the frequency or noisiness of a signal.
| [in] | input_window | input window uint8. |
| [out] | zcr_out | pointer to result float32. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_slopeChanges | ( | const uint8_t * | input_window, |
| float * | slope_changes | ||
| ) |
Counts the sign changes of signal differences.
| [in] | input_window | input window uint8. |
| [out] | slope_changes | pointer to result float32. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_fftPool | ( | const uint8_t * | input_window, |
| float * | fft_output_pool_mag | ||
| ) |
calculate FFT magnitudes and pooling (averaging) to produce NUM_FEAT_FFT features.
| [in] | input_window | input window uint8. |
| [out] | fft_output_pool_mag | preallocated array of NUM_FEAT_FFT float32. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_topFrequencies | ( | const uint8_t * | input_window, |
| float * | top_freqs | ||
| ) |
Extract the index of the dominant frequencies (Hz) per window.
| [in] | input_window | input window uint8. |
| [out] | top_freqs | preallocated array of length TOP_N_FREQ. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_spectralEntropy | ( | const uint8_t * | input_window, |
| float * | entropy_out | ||
| ) |
Calculates the Shannon spectral entropy. The Spectral Entropy acts as an indicator of how spread out the power is.
| [in] | input_window | input window uint8. |
| [out] | entropy_out | pointer to float32 result. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_kurtosis | ( | const uint8_t * | input_window, |
| float * | kurtosis_output | ||
| ) |
Calculates the fisher or excess kurtosis without bias for each segment of a given series. Kurtosis describes the "peakedness" of a probability distribution.
| [in] | input_window | input window uint8. |
| [out] | kurtosis_output | preallocated array of NUM_FEAT_KURTOSIS float32. |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| fe_status_t FE_concatenateFeatures | ( | const float * | fft_output_pool_mag, |
| uint32_t | window_index, | ||
| const float * | kurtosis_output, | ||
| const float * | zcr, | ||
| const float * | slope_changes, | ||
| const float * | top_dominant_freq, | ||
| const float * | power_spectrum, | ||
| float * | concatenated_features | ||
| ) |
Concatenate many feature arrays into a big feature vector. The offsets are determined by NUM_FEAT_X and NUM_WINDOWS macros.
| [in] | fft_output_pool_mag | pointer to FFT features (NUM_FEAT_FFT) |
| [in] | window_index | which window this belongs to (0 .. NUM_WINDOWS-1) |
| [in] | kurtosis_output | pointer to NUM_FEAT_KURTOSIS values |
| [in] | zcr | pointer to zcr value (scalar) |
| [in] | slope_changes | pointer to slope_changes value (scalar) |
| [in] | top_dominant_freq | pointer to TOP_N_FREQ values |
| [in] | power_spectrum | pointer to spectral entropy (scalar) |
| [out] | concatenated_features | preallocated feature vector of size NUM_TOTAL_FEATURES * NUM_WINDOWS |
| FE_OK | Process ended successfully. |
| FE_ERR_NULLPTR | The pointer to one of the function arguments has a NULL value. |
| FE_ERR_BAD_PARAM | One of the Feature Extraction configuration parameters is incorrect or not supported. |
| FE_ERR_DSP | DSP operation has failed. |
| uint32_t samplingfreq |