support_functions.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /******************************************************************************
  2. * @file support_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 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. #ifndef _SUPPORT_FUNCTIONS_H_
  26. #define _SUPPORT_FUNCTIONS_H_
  27. #include "arm_math_types.h"
  28. #include "arm_math_memory.h"
  29. #include "dsp/none.h"
  30. #include "dsp/utils.h"
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. /**
  36. * @defgroup groupSupport Support Functions
  37. */
  38. /**
  39. * @brief Converts the elements of the floating-point vector to Q31 vector.
  40. * @param[in] pSrc points to the floating-point input vector
  41. * @param[out] pDst points to the Q31 output vector
  42. * @param[in] blockSize length of the input vector
  43. */
  44. void arm_float_to_q31(
  45. const float32_t * pSrc,
  46. q31_t * pDst,
  47. uint32_t blockSize);
  48. /**
  49. * @brief Converts the elements of the floating-point vector to Q15 vector.
  50. * @param[in] pSrc points to the floating-point input vector
  51. * @param[out] pDst points to the Q15 output vector
  52. * @param[in] blockSize length of the input vector
  53. */
  54. void arm_float_to_q15(
  55. const float32_t * pSrc,
  56. q15_t * pDst,
  57. uint32_t blockSize);
  58. /**
  59. * @brief Converts the elements of the floating-point vector to Q7 vector.
  60. * @param[in] pSrc points to the floating-point input vector
  61. * @param[out] pDst points to the Q7 output vector
  62. * @param[in] blockSize length of the input vector
  63. */
  64. void arm_float_to_q7(
  65. const float32_t * pSrc,
  66. q7_t * pDst,
  67. uint32_t blockSize);
  68. /**
  69. * @brief Converts the elements of the Q31 vector to floating-point vector.
  70. * @param[in] pSrc is input pointer
  71. * @param[out] pDst is output pointer
  72. * @param[in] blockSize is the number of samples to process
  73. */
  74. void arm_q31_to_float(
  75. const q31_t * pSrc,
  76. float32_t * pDst,
  77. uint32_t blockSize);
  78. /**
  79. * @brief Converts the elements of the Q31 vector to Q15 vector.
  80. * @param[in] pSrc is input pointer
  81. * @param[out] pDst is output pointer
  82. * @param[in] blockSize is the number of samples to process
  83. */
  84. void arm_q31_to_q15(
  85. const q31_t * pSrc,
  86. q15_t * pDst,
  87. uint32_t blockSize);
  88. /**
  89. * @brief Converts the elements of the Q31 vector to Q7 vector.
  90. * @param[in] pSrc is input pointer
  91. * @param[out] pDst is output pointer
  92. * @param[in] blockSize is the number of samples to process
  93. */
  94. void arm_q31_to_q7(
  95. const q31_t * pSrc,
  96. q7_t * pDst,
  97. uint32_t blockSize);
  98. /**
  99. * @brief Converts the elements of the Q15 vector to floating-point vector.
  100. * @param[in] pSrc is input pointer
  101. * @param[out] pDst is output pointer
  102. * @param[in] blockSize is the number of samples to process
  103. */
  104. void arm_q15_to_float(
  105. const q15_t * pSrc,
  106. float32_t * pDst,
  107. uint32_t blockSize);
  108. /**
  109. * @brief Converts the elements of the Q15 vector to Q31 vector.
  110. * @param[in] pSrc is input pointer
  111. * @param[out] pDst is output pointer
  112. * @param[in] blockSize is the number of samples to process
  113. */
  114. void arm_q15_to_q31(
  115. const q15_t * pSrc,
  116. q31_t * pDst,
  117. uint32_t blockSize);
  118. /**
  119. * @brief Converts the elements of the Q15 vector to Q7 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_q7(
  125. const q15_t * pSrc,
  126. q7_t * pDst,
  127. uint32_t blockSize);
  128. /**
  129. * @brief Converts the elements of the Q7 vector to floating-point vector.
  130. * @param[in] pSrc is input pointer
  131. * @param[out] pDst is output pointer
  132. * @param[in] blockSize is the number of samples to process
  133. */
  134. void arm_q7_to_float(
  135. const q7_t * pSrc,
  136. float32_t * pDst,
  137. uint32_t blockSize);
  138. /**
  139. * @brief Converts the elements of the Q7 vector to Q31 vector.
  140. * @param[in] pSrc input pointer
  141. * @param[out] pDst output pointer
  142. * @param[in] blockSize number of samples to process
  143. */
  144. void arm_q7_to_q31(
  145. const q7_t * pSrc,
  146. q31_t * pDst,
  147. uint32_t blockSize);
  148. /**
  149. * @brief Converts the elements of the Q7 vector to Q15 vector.
  150. * @param[in] pSrc input pointer
  151. * @param[out] pDst output pointer
  152. * @param[in] blockSize number of samples to process
  153. */
  154. void arm_q7_to_q15(
  155. const q7_t * pSrc,
  156. q15_t * pDst,
  157. uint32_t blockSize);
  158. /**
  159. * @brief Struct for specifying sorting algorithm
  160. */
  161. typedef enum
  162. {
  163. ARM_SORT_BITONIC = 0,
  164. /**< Bitonic sort */
  165. ARM_SORT_BUBBLE = 1,
  166. /**< Bubble sort */
  167. ARM_SORT_HEAP = 2,
  168. /**< Heap sort */
  169. ARM_SORT_INSERTION = 3,
  170. /**< Insertion sort */
  171. ARM_SORT_QUICK = 4,
  172. /**< Quick sort */
  173. ARM_SORT_SELECTION = 5
  174. /**< Selection sort */
  175. } arm_sort_alg;
  176. /**
  177. * @brief Struct for specifying sorting algorithm
  178. */
  179. typedef enum
  180. {
  181. ARM_SORT_DESCENDING = 0,
  182. /**< Descending order (9 to 0) */
  183. ARM_SORT_ASCENDING = 1
  184. /**< Ascending order (0 to 9) */
  185. } arm_sort_dir;
  186. /**
  187. * @brief Instance structure for the sorting algorithms.
  188. */
  189. typedef struct
  190. {
  191. arm_sort_alg alg; /**< Sorting algorithm selected */
  192. arm_sort_dir dir; /**< Sorting order (direction) */
  193. } arm_sort_instance_f32;
  194. /**
  195. * @param[in] S points to an instance of the sorting structure.
  196. * @param[in] pSrc points to the block of input data.
  197. * @param[out] pDst points to the block of output data.
  198. * @param[in] blockSize number of samples to process.
  199. */
  200. void arm_sort_f32(
  201. const arm_sort_instance_f32 * S,
  202. float32_t * pSrc,
  203. float32_t * pDst,
  204. uint32_t blockSize);
  205. /**
  206. * @param[in,out] S points to an instance of the sorting structure.
  207. * @param[in] alg Selected algorithm.
  208. * @param[in] dir Sorting order.
  209. */
  210. void arm_sort_init_f32(
  211. arm_sort_instance_f32 * S,
  212. arm_sort_alg alg,
  213. arm_sort_dir dir);
  214. /**
  215. * @brief Instance structure for the sorting algorithms.
  216. */
  217. typedef struct
  218. {
  219. arm_sort_dir dir; /**< Sorting order (direction) */
  220. float32_t * buffer; /**< Working buffer */
  221. } arm_merge_sort_instance_f32;
  222. /**
  223. * @param[in] S points to an instance of the sorting structure.
  224. * @param[in,out] pSrc points to the block of input data.
  225. * @param[out] pDst points to the block of output data
  226. * @param[in] blockSize number of samples to process.
  227. */
  228. void arm_merge_sort_f32(
  229. const arm_merge_sort_instance_f32 * S,
  230. float32_t *pSrc,
  231. float32_t *pDst,
  232. uint32_t blockSize);
  233. /**
  234. * @param[in,out] S points to an instance of the sorting structure.
  235. * @param[in] dir Sorting order.
  236. * @param[in] buffer Working buffer.
  237. */
  238. void arm_merge_sort_init_f32(
  239. arm_merge_sort_instance_f32 * S,
  240. arm_sort_dir dir,
  241. float32_t * buffer);
  242. /**
  243. * @brief Copies the elements of a floating-point vector.
  244. * @param[in] pSrc input pointer
  245. * @param[out] pDst output pointer
  246. * @param[in] blockSize number of samples to process
  247. */
  248. void arm_copy_f32(
  249. const float32_t * pSrc,
  250. float32_t * pDst,
  251. uint32_t blockSize);
  252. /**
  253. * @brief Copies the elements of a floating-point vector.
  254. * @param[in] pSrc input pointer
  255. * @param[out] pDst output pointer
  256. * @param[in] blockSize number of samples to process
  257. */
  258. void arm_copy_f64(
  259. const float64_t * pSrc,
  260. float64_t * pDst,
  261. uint32_t blockSize);
  262. /**
  263. * @brief Copies the elements of a Q7 vector.
  264. * @param[in] pSrc input pointer
  265. * @param[out] pDst output pointer
  266. * @param[in] blockSize number of samples to process
  267. */
  268. void arm_copy_q7(
  269. const q7_t * pSrc,
  270. q7_t * pDst,
  271. uint32_t blockSize);
  272. /**
  273. * @brief Copies the elements of a Q15 vector.
  274. * @param[in] pSrc input pointer
  275. * @param[out] pDst output pointer
  276. * @param[in] blockSize number of samples to process
  277. */
  278. void arm_copy_q15(
  279. const q15_t * pSrc,
  280. q15_t * pDst,
  281. uint32_t blockSize);
  282. /**
  283. * @brief Copies the elements of a Q31 vector.
  284. * @param[in] pSrc input pointer
  285. * @param[out] pDst output pointer
  286. * @param[in] blockSize number of samples to process
  287. */
  288. void arm_copy_q31(
  289. const q31_t * pSrc,
  290. q31_t * pDst,
  291. uint32_t blockSize);
  292. /**
  293. * @brief Fills a constant value into a floating-point vector.
  294. * @param[in] value input value to be filled
  295. * @param[out] pDst output pointer
  296. * @param[in] blockSize number of samples to process
  297. */
  298. void arm_fill_f32(
  299. float32_t value,
  300. float32_t * pDst,
  301. uint32_t blockSize);
  302. /**
  303. * @brief Fills a constant value into a floating-point vector.
  304. * @param[in] value input value to be filled
  305. * @param[out] pDst output pointer
  306. * @param[in] blockSize number of samples to process
  307. */
  308. void arm_fill_f64(
  309. float64_t value,
  310. float64_t * pDst,
  311. uint32_t blockSize);
  312. /**
  313. * @brief Fills a constant value into a Q7 vector.
  314. * @param[in] value input value to be filled
  315. * @param[out] pDst output pointer
  316. * @param[in] blockSize number of samples to process
  317. */
  318. void arm_fill_q7(
  319. q7_t value,
  320. q7_t * pDst,
  321. uint32_t blockSize);
  322. /**
  323. * @brief Fills a constant value into a Q15 vector.
  324. * @param[in] value input value to be filled
  325. * @param[out] pDst output pointer
  326. * @param[in] blockSize number of samples to process
  327. */
  328. void arm_fill_q15(
  329. q15_t value,
  330. q15_t * pDst,
  331. uint32_t blockSize);
  332. /**
  333. * @brief Fills a constant value into a Q31 vector.
  334. * @param[in] value input value to be filled
  335. * @param[out] pDst output pointer
  336. * @param[in] blockSize number of samples to process
  337. */
  338. void arm_fill_q31(
  339. q31_t value,
  340. q31_t * pDst,
  341. uint32_t blockSize);
  342. /**
  343. * @brief Weighted sum
  344. *
  345. *
  346. * @param[in] *in Array of input values.
  347. * @param[in] *weigths Weights
  348. * @param[in] blockSize Number of samples in the input array.
  349. * @return Weighted sum
  350. *
  351. */
  352. float32_t arm_weighted_sum_f32(const float32_t *in
  353. , const float32_t *weigths
  354. , uint32_t blockSize);
  355. /**
  356. * @brief Barycenter
  357. *
  358. *
  359. * @param[in] in List of vectors
  360. * @param[in] weights Weights of the vectors
  361. * @param[out] out Barycenter
  362. * @param[in] nbVectors Number of vectors
  363. * @param[in] vecDim Dimension of space (vector dimension)
  364. * @return None
  365. *
  366. */
  367. void arm_barycenter_f32(const float32_t *in
  368. , const float32_t *weights
  369. , float32_t *out
  370. , uint32_t nbVectors
  371. , uint32_t vecDim);
  372. #ifdef __cplusplus
  373. }
  374. #endif
  375. #endif /* ifndef _SUPPORT_FUNCTIONS_H_ */