1 /****************************************************************************** 2 * @file support_functions.h 3 * @brief Public header file for CMSIS DSP Library 4 * @version V1.9.0 5 * @date 23 April 2021 6 * Target Processor: Cortex-M and Cortex-A cores 7 ******************************************************************************/ 8 /* 9 * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved. 10 * 11 * SPDX-License-Identifier: Apache-2.0 12 * 13 * Licensed under the Apache License, Version 2.0 (the License); you may 14 * not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, software 20 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the License for the specific language governing permissions and 23 * limitations under the License. 24 */ 25 26 27 #ifndef _SUPPORT_FUNCTIONS_H_ 28 #define _SUPPORT_FUNCTIONS_H_ 29 30 #include "arm_math_types.h" 31 #include "arm_math_memory.h" 32 33 #include "dsp/none.h" 34 #include "dsp/utils.h" 35 36 #ifdef __cplusplus 37 extern "C" 38 { 39 #endif 40 41 /** 42 * @defgroup groupSupport Support Functions 43 */ 44 45 46 /** 47 * @brief Converts the elements of the floating-point vector to Q31 vector. 48 * @param[in] pSrc points to the floating-point input vector 49 * @param[out] pDst points to the Q31 output vector 50 * @param[in] blockSize length of the input vector 51 */ 52 void arm_float_to_q31( 53 const float32_t * pSrc, 54 q31_t * pDst, 55 uint32_t blockSize); 56 57 58 /** 59 * @brief Converts the elements of the floating-point vector to Q15 vector. 60 * @param[in] pSrc points to the floating-point input vector 61 * @param[out] pDst points to the Q15 output vector 62 * @param[in] blockSize length of the input vector 63 */ 64 void arm_float_to_q15( 65 const float32_t * pSrc, 66 q15_t * pDst, 67 uint32_t blockSize); 68 69 70 /** 71 * @brief Converts the elements of the floating-point vector to Q7 vector. 72 * @param[in] pSrc points to the floating-point input vector 73 * @param[out] pDst points to the Q7 output vector 74 * @param[in] blockSize length of the input vector 75 */ 76 void arm_float_to_q7( 77 const float32_t * pSrc, 78 q7_t * pDst, 79 uint32_t blockSize); 80 81 82 /** 83 * @brief Converts the elements of the Q31 vector to floating-point vector. 84 * @param[in] pSrc is input pointer 85 * @param[out] pDst is output pointer 86 * @param[in] blockSize is the number of samples to process 87 */ 88 void arm_q31_to_float( 89 const q31_t * pSrc, 90 float32_t * pDst, 91 uint32_t blockSize); 92 93 94 /** 95 * @brief Converts the elements of the Q31 vector to Q15 vector. 96 * @param[in] pSrc is input pointer 97 * @param[out] pDst is output pointer 98 * @param[in] blockSize is the number of samples to process 99 */ 100 void arm_q31_to_q15( 101 const q31_t * pSrc, 102 q15_t * pDst, 103 uint32_t blockSize); 104 105 106 /** 107 * @brief Converts the elements of the Q31 vector to Q7 vector. 108 * @param[in] pSrc is input pointer 109 * @param[out] pDst is output pointer 110 * @param[in] blockSize is the number of samples to process 111 */ 112 void arm_q31_to_q7( 113 const q31_t * pSrc, 114 q7_t * pDst, 115 uint32_t blockSize); 116 117 118 /** 119 * @brief Converts the elements of the Q15 vector to floating-point vector. 120 * @param[in] pSrc is input pointer 121 * @param[out] pDst is output pointer 122 * @param[in] blockSize is the number of samples to process 123 */ 124 void arm_q15_to_float( 125 const q15_t * pSrc, 126 float32_t * pDst, 127 uint32_t blockSize); 128 129 130 /** 131 * @brief Converts the elements of the Q15 vector to Q31 vector. 132 * @param[in] pSrc is input pointer 133 * @param[out] pDst is output pointer 134 * @param[in] blockSize is the number of samples to process 135 */ 136 void arm_q15_to_q31( 137 const q15_t * pSrc, 138 q31_t * pDst, 139 uint32_t blockSize); 140 141 142 /** 143 * @brief Converts the elements of the Q15 vector to Q7 vector. 144 * @param[in] pSrc is input pointer 145 * @param[out] pDst is output pointer 146 * @param[in] blockSize is the number of samples to process 147 */ 148 void arm_q15_to_q7( 149 const q15_t * pSrc, 150 q7_t * pDst, 151 uint32_t blockSize); 152 153 154 /** 155 * @brief Converts the elements of the Q7 vector to floating-point vector. 156 * @param[in] pSrc is input pointer 157 * @param[out] pDst is output pointer 158 * @param[in] blockSize is the number of samples to process 159 */ 160 void arm_q7_to_float( 161 const q7_t * pSrc, 162 float32_t * pDst, 163 uint32_t blockSize); 164 165 166 /** 167 * @brief Converts the elements of the Q7 vector to Q31 vector. 168 * @param[in] pSrc input pointer 169 * @param[out] pDst output pointer 170 * @param[in] blockSize number of samples to process 171 */ 172 void arm_q7_to_q31( 173 const q7_t * pSrc, 174 q31_t * pDst, 175 uint32_t blockSize); 176 177 178 /** 179 * @brief Converts the elements of the Q7 vector to Q15 vector. 180 * @param[in] pSrc input pointer 181 * @param[out] pDst output pointer 182 * @param[in] blockSize number of samples to process 183 */ 184 void arm_q7_to_q15( 185 const q7_t * pSrc, 186 q15_t * pDst, 187 uint32_t blockSize); 188 189 190 191 192 193 /** 194 * @brief Struct for specifying sorting algorithm 195 */ 196 typedef enum 197 { 198 ARM_SORT_BITONIC = 0, 199 /**< Bitonic sort */ 200 ARM_SORT_BUBBLE = 1, 201 /**< Bubble sort */ 202 ARM_SORT_HEAP = 2, 203 /**< Heap sort */ 204 ARM_SORT_INSERTION = 3, 205 /**< Insertion sort */ 206 ARM_SORT_QUICK = 4, 207 /**< Quick sort */ 208 ARM_SORT_SELECTION = 5 209 /**< Selection sort */ 210 } arm_sort_alg; 211 212 /** 213 * @brief Struct for specifying sorting algorithm 214 */ 215 typedef enum 216 { 217 ARM_SORT_DESCENDING = 0, 218 /**< Descending order (9 to 0) */ 219 ARM_SORT_ASCENDING = 1 220 /**< Ascending order (0 to 9) */ 221 } arm_sort_dir; 222 223 /** 224 * @brief Instance structure for the sorting algorithms. 225 */ 226 typedef struct 227 { 228 arm_sort_alg alg; /**< Sorting algorithm selected */ 229 arm_sort_dir dir; /**< Sorting order (direction) */ 230 } arm_sort_instance_f32; 231 232 /** 233 * @param[in] S points to an instance of the sorting structure. 234 * @param[in] pSrc points to the block of input data. 235 * @param[out] pDst points to the block of output data. 236 * @param[in] blockSize number of samples to process. 237 */ 238 void arm_sort_f32( 239 const arm_sort_instance_f32 * S, 240 float32_t * pSrc, 241 float32_t * pDst, 242 uint32_t blockSize); 243 244 /** 245 * @param[in,out] S points to an instance of the sorting structure. 246 * @param[in] alg Selected algorithm. 247 * @param[in] dir Sorting order. 248 */ 249 void arm_sort_init_f32( 250 arm_sort_instance_f32 * S, 251 arm_sort_alg alg, 252 arm_sort_dir dir); 253 254 /** 255 * @brief Instance structure for the sorting algorithms. 256 */ 257 typedef struct 258 { 259 arm_sort_dir dir; /**< Sorting order (direction) */ 260 float32_t * buffer; /**< Working buffer */ 261 } arm_merge_sort_instance_f32; 262 263 /** 264 * @param[in] S points to an instance of the sorting structure. 265 * @param[in,out] pSrc points to the block of input data. 266 * @param[out] pDst points to the block of output data 267 * @param[in] blockSize number of samples to process. 268 */ 269 void arm_merge_sort_f32( 270 const arm_merge_sort_instance_f32 * S, 271 float32_t *pSrc, 272 float32_t *pDst, 273 uint32_t blockSize); 274 275 /** 276 * @param[in,out] S points to an instance of the sorting structure. 277 * @param[in] dir Sorting order. 278 * @param[in] buffer Working buffer. 279 */ 280 void arm_merge_sort_init_f32( 281 arm_merge_sort_instance_f32 * S, 282 arm_sort_dir dir, 283 float32_t * buffer); 284 285 286 287 /** 288 * @brief Copies the elements of a floating-point vector. 289 * @param[in] pSrc input pointer 290 * @param[out] pDst output pointer 291 * @param[in] blockSize number of samples to process 292 */ 293 void arm_copy_f32( 294 const float32_t * pSrc, 295 float32_t * pDst, 296 uint32_t blockSize); 297 298 299 /** 300 * @brief Copies the elements of a Q7 vector. 301 * @param[in] pSrc input pointer 302 * @param[out] pDst output pointer 303 * @param[in] blockSize number of samples to process 304 */ 305 void arm_copy_q7( 306 const q7_t * pSrc, 307 q7_t * pDst, 308 uint32_t blockSize); 309 310 311 /** 312 * @brief Copies the elements of a Q15 vector. 313 * @param[in] pSrc input pointer 314 * @param[out] pDst output pointer 315 * @param[in] blockSize number of samples to process 316 */ 317 void arm_copy_q15( 318 const q15_t * pSrc, 319 q15_t * pDst, 320 uint32_t blockSize); 321 322 323 /** 324 * @brief Copies the elements of a Q31 vector. 325 * @param[in] pSrc input pointer 326 * @param[out] pDst output pointer 327 * @param[in] blockSize number of samples to process 328 */ 329 void arm_copy_q31( 330 const q31_t * pSrc, 331 q31_t * pDst, 332 uint32_t blockSize); 333 334 335 /** 336 * @brief Fills a constant value into a floating-point vector. 337 * @param[in] value input value to be filled 338 * @param[out] pDst output pointer 339 * @param[in] blockSize number of samples to process 340 */ 341 void arm_fill_f32( 342 float32_t value, 343 float32_t * pDst, 344 uint32_t blockSize); 345 346 347 /** 348 * @brief Fills a constant value into a Q7 vector. 349 * @param[in] value input value to be filled 350 * @param[out] pDst output pointer 351 * @param[in] blockSize number of samples to process 352 */ 353 void arm_fill_q7( 354 q7_t value, 355 q7_t * pDst, 356 uint32_t blockSize); 357 358 359 /** 360 * @brief Fills a constant value into a Q15 vector. 361 * @param[in] value input value to be filled 362 * @param[out] pDst output pointer 363 * @param[in] blockSize number of samples to process 364 */ 365 void arm_fill_q15( 366 q15_t value, 367 q15_t * pDst, 368 uint32_t blockSize); 369 370 371 /** 372 * @brief Fills a constant value into a Q31 vector. 373 * @param[in] value input value to be filled 374 * @param[out] pDst output pointer 375 * @param[in] blockSize number of samples to process 376 */ 377 void arm_fill_q31( 378 q31_t value, 379 q31_t * pDst, 380 uint32_t blockSize); 381 382 383 384 385 386 387 388 /** 389 * @brief Weighted sum 390 * 391 * 392 * @param[in] *in Array of input values. 393 * @param[in] *weigths Weights 394 * @param[in] blockSize Number of samples in the input array. 395 * @return Weighted sum 396 * 397 */ 398 float32_t arm_weighted_sum_f32(const float32_t *in 399 , const float32_t *weigths 400 , uint32_t blockSize); 401 402 403 /** 404 * @brief Barycenter 405 * 406 * 407 * @param[in] in List of vectors 408 * @param[in] weights Weights of the vectors 409 * @param[out] out Barycenter 410 * @param[in] nbVectors Number of vectors 411 * @param[in] vecDim Dimension of space (vector dimension) 412 * @return None 413 * 414 */ 415 void arm_barycenter_f32(const float32_t *in 416 , const float32_t *weights 417 , float32_t *out 418 , uint32_t nbVectors 419 , uint32_t vecDim); 420 421 422 423 #ifdef __cplusplus 424 } 425 #endif 426 427 #endif /* ifndef _SUPPORT_FUNCTIONS_H_ */ 428