EDGEAI API
feature_extract.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025-2026, Texas Instruments Incorporated
3  *
4  * All rights reserved not granted herein.
5  * Limited License.
6  *
7  * Texas Instruments Incorporated grants a world-wide, royalty-free,
8  * non-exclusive license under copyrights and patents it now or hereafter
9  * owns or controls to make, have made, use, import, offer to sell and sell
10  * ("Utilize") this software subject to the terms herein. With respect to the
11  * foregoing patent license, such license is granted solely to the extent that
12  * any such patent is necessary to Utilize the software alone. The patent
13  * license shall not apply to any combinations which include this software,
14  * other than combinations with devices manufactured by or for TI ("TI
15  * Devices"). No hardware patent is licensed hereunder.
16  *
17  * Redistributions must preserve existing copyright notices and reproduce
18  * this license (including the above copyright notice and the disclaimer and
19  * (if applicable) source code license limitations below) in the documentation
20  * and/or other materials provided with the distribution.
21  *
22  * Redistribution and use in binary form, without modification, are permitted
23  * provided that the following conditions are met:
24  *
25  * * No reverse engineering, decompilation, or disassembly of this software
26  * is permitted with respect to any software provided in binary form.
27  * * Any redistribution and use are licensed by TI for use only with TI Devices.
28  * * Nothing shall obligate TI to provide you with source code for the software
29  * licensed and provided to you in object code.
30  *
31  * If software source code is provided to you, modification and redistribution
32  * of the source code are permitted provided that the following conditions are
33  * met:
34  *
35  * * Any redistribution and use of the source code, including any resulting
36  * derivative works, are licensed by TI for use only with TI Devices.
37  * * Any redistribution and use of any object code compiled from the source
38  * code and any resulting derivative works, are licensed by TI for use
39  * only with TI Devices.
40  *
41  * Neither the name of Texas Instruments Incorporated nor the names of its
42  * suppliers may be used to endorse or promote products derived from this
43  * software without specific prior written permission.
44  *
45  * DISCLAIMER.
46  *
47  * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
48  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50  * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
51  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
54  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
55  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
56  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57  */
58 /*!****************************************************************************
59 * @file feature_extract.h
60 * @brief <b>PRELIMINARY</b> Feature Extraction for EdgeAI
61 *
62 * <b>WARNING</b> These set of functions are <b>PRELIMINARY</b>, and subject to
63 * change in the next few months.
64 *
65 * To use the Feature Extraction library, include this header file in the
66 * application as follows:
67 
68 * @code
69 * #include <ti/ai/edge_ai/fe/feature_extract.h>
70 * @endcode
71 *
72 * @anchor ti_edgeai_feature_extract_Overview
73 * # Overview #
74 * This library will serve as a pre-processing stage where raw signal inputs
75 * will be fed to the feature extraction library and the resulting output will
76 * be fed into the pre-compiled NN model. The function that have been implemented
77 * so far are the following:
78 *
79 * - FE_applyWindow(): extracts windows of data based on a window size, stride size
80 * and an input stream.
81 *
82 * - FE_fftPool(): calculates the Real FFT magnitude for each window and average
83 * pool the resulting bins. The window undergoes a symmetrical modification first,
84 * doubling its size.
85 *
86 * - FE_kurtosis(): calculates the fisher or excess Kurtorsis for each segment of
87 * a given window, without bias (look for exact equation in the previous graph).
88 * Kurtosis describes the "peakedness" of a probability distribution.
89 *
90 * - FE_zeroCrossingRate(): calculates the zero crossing rate for each window. ZCR measures
91 * of how often a signal crosses the zero axis, indicating the frequency or noisiness
92 * of a signal.
93 *
94 * - FE_slopeChanges(): counts the sign changes of signal differences.
95 *
96 * - FE_topFrequencies(): calculates the top N dominant frequencies of a FFT result per window.
97 * The window doubles its size first, padded with zeros to the right.
98 *
99 * - FE_spectralEntropy(): calculates the Shannon spectral entropy of a FFT result per
100 * window. The window doubles its size first, padded with zeros to the right. The
101 * Spectral Entropy acts as an indicator of how spread out the power is across different
102 * frequencies.
103 *
104 * - FE_concatenateFeatures(): Concatenate many feature arrays into a big feature vector.
105 * The offsets are determined by NUM_FEAT_X and NUM_WINDOWS macros.
106 *
107 * <hr>
108 * # Usage
109 * To use the Feature Extraction Library call the previous APIs accordingly.
110 *
111 ******************************************************************************
112 */
113 
114 #ifndef ti_edgeai_feature_extract__include
115 #define ti_edgeai_feature_extract__include
116 
117 #ifdef __cplusplus
118 extern "C" {
119 #endif
120 
121 #include <stddef.h>
122 #include <stdint.h>
123 
124 #ifndef FE_PARAMETERS_IS_DEFINE
125 
126  /* Sampling */
127  #define ADCSAMPLESIZE 125
128  #define SAMPLING_FREQ 25
129 
130  /* Windowing */
131  #define PADDING_SIZE_LEFT 4
132  #define PADDING_SIZE_RIGHT 3
133  #define PADDED_INPUT_SIZE (ADCSAMPLESIZE + PADDING_SIZE_LEFT + PADDING_SIZE_RIGHT)
134  #define WINDOW_SIZE 32
135  #define WINDOW_STRIDE_SIZE 4
136  #define NUM_WINDOWS 25
137 
138  /* FFT */
139  #define FFT_SIZE 64
140  #define NUM_BINS (FFT_SIZE / 2)
141  #define POOLED_BINS (NUM_BINS / 2)
142 
143  /* Top Dominant Frequencies */
144  #define TOP_N_FREQ 2
145 
146  /* Kurtosis */
147  #define KURTOSIS_CHUNK_SIZE 8
148  #define KURTOSIS_STRIDE_SIZE 8
149 
150  /* Total Features */
151  #define NUM_FEAT_FFT 16
152  #define NUM_FEAT_TOPFREQ TOP_N_FREQ
153  #define NUM_FEAT_KURTOSIS 4
154  #define NUM_FEAT_ZCR 1
155  #define NUM_FEAT_SLOPE 1
156  #define NUM_FEAT_PW_SPEC 1
157  #define NUM_TOTAL_FEATURES 25
158 
159 #endif
160 
161 extern uint32_t samplingfreq;
162 
169 typedef enum
170 {
172  FE_OK = 0x00,
178  FE_ERR_DSP = 0x03,
179 } fe_status_t;
180 
195 fe_status_t FE_applyWindow(const uint8_t *data_stream, uint8_t output_windows[NUM_WINDOWS][WINDOW_SIZE]);
196 
212 fe_status_t FE_zeroCrossingRate(const uint8_t *input_window, float *zcr_out);
213 
226 fe_status_t FE_slopeChanges(const uint8_t *input_window, float *slope_changes);
227 
242 fe_status_t FE_fftPool(const uint8_t *input_window, float *fft_output_pool_mag);
243 
257 fe_status_t FE_topFrequencies(const uint8_t *input_window, float *top_freqs);
258 
273 fe_status_t FE_spectralEntropy(const uint8_t *input_window, float *entropy_out);
274 
289 fe_status_t FE_kurtosis(const uint8_t *input_window, float *kurtosis_output);
290 
312 fe_status_t FE_concatenateFeatures(const float *fft_output_pool_mag,
313  uint32_t window_index,
314  const float *kurtosis_output,
315  const float *zcr,
316  const float *slope_changes,
317  const float *top_dominant_freq,
318  const float *power_spectrum,
319  float *concatenated_features);
320 
321 #endif /* fe_feature_extract_Module__include */
322 
323 #ifdef __cplusplus
324 }
325 #endif
#define NUM_WINDOWS
Definition: feature_extract.h:136
fe_status_t FE_slopeChanges(const uint8_t *input_window, float *slope_changes)
Counts the sign changes of signal differences.
fe_status_t FE_topFrequencies(const uint8_t *input_window, float *top_freqs)
Extract the index of the dominant frequencies (Hz) per window.
Definition: feature_extract.h:176
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 ...
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.
fe_status_t
Specifies the FE status codes.
Definition: feature_extract.h:169
Definition: feature_extract.h:174
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...
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 sign...
uint32_t samplingfreq
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 a...
Definition: feature_extract.h:172
#define WINDOW_SIZE
Definition: feature_extract.h:134
Definition: feature_extract.h:178
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.
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale