support_functions.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /******************************************************************************
  2. * @file support_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.1
  5. * @date 18 August 2022
  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 64 bit floating-point vector to floating-point vector.
  40. * @param[in] pSrc points to the floating-point 64 input vector
  41. * @param[out] pDst points to the floating-point output vector
  42. * @param[in] blockSize length of the input vector
  43. */
  44. void arm_f64_to_float(
  45. const float64_t * pSrc,
  46. float32_t * pDst,
  47. uint32_t blockSize);
  48. /**
  49. * @brief Converts the elements of the 64 bit floating-point vector to Q31 vector.
  50. * @param[in] pSrc points to the floating-point 64 input vector
  51. * @param[out] pDst points to the Q31 output vector
  52. * @param[in] blockSize length of the input vector
  53. */
  54. void arm_f64_to_q31(
  55. const float64_t * pSrc,
  56. q31_t * pDst,
  57. uint32_t blockSize);
  58. /**
  59. * @brief Converts the elements of the 64 bit floating-point vector to Q15 vector.
  60. * @param[in] pSrc points to the floating-point 64 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_f64_to_q15(
  65. const float64_t * pSrc,
  66. q15_t * pDst,
  67. uint32_t blockSize);
  68. /**
  69. * @brief Converts the elements of the 64 bit floating-point vector to Q7 vector.
  70. * @param[in] pSrc points to the floating-point 64 input vector
  71. * @param[out] pDst points to the Q7 output vector
  72. * @param[in] blockSize length of the input vector
  73. */
  74. void arm_f64_to_q7(
  75. const float64_t * pSrc,
  76. q7_t * pDst,
  77. uint32_t blockSize);
  78. /**
  79. * @brief Converts the elements of the floating-point vector to 64 bit floating-point vector.
  80. * @param[in] pSrc points to the floating-point input vector
  81. * @param[out] pDst points to the 64 bit floating-point output vector
  82. * @param[in] blockSize length of the input vector
  83. */
  84. void arm_float_to_f64(
  85. const float32_t * pSrc,
  86. float64_t * pDst,
  87. uint32_t blockSize);
  88. /**
  89. * @brief Converts the elements of the floating-point vector to Q31 vector.
  90. * @param[in] pSrc points to the floating-point input vector
  91. * @param[out] pDst points to the Q31 output vector
  92. * @param[in] blockSize length of the input vector
  93. */
  94. void arm_float_to_q31(
  95. const float32_t * pSrc,
  96. q31_t * pDst,
  97. uint32_t blockSize);
  98. /**
  99. * @brief Converts the elements of the floating-point vector to Q15 vector.
  100. * @param[in] pSrc points to the floating-point input vector
  101. * @param[out] pDst points to the Q15 output vector
  102. * @param[in] blockSize length of the input vector
  103. */
  104. void arm_float_to_q15(
  105. const float32_t * pSrc,
  106. q15_t * pDst,
  107. uint32_t blockSize);
  108. /**
  109. * @brief Converts the elements of the floating-point vector to Q7 vector.
  110. * @param[in] pSrc points to the floating-point input vector
  111. * @param[out] pDst points to the Q7 output vector
  112. * @param[in] blockSize length of the input vector
  113. */
  114. void arm_float_to_q7(
  115. const float32_t * pSrc,
  116. q7_t * pDst,
  117. uint32_t blockSize);
  118. /**
  119. * @brief Converts the elements of the Q31 vector to 64 bit 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_q31_to_f64(
  125. const q31_t * pSrc,
  126. float64_t * pDst,
  127. uint32_t blockSize);
  128. /**
  129. * @brief Converts the elements of the Q31 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_q31_to_float(
  135. const q31_t * pSrc,
  136. float32_t * pDst,
  137. uint32_t blockSize);
  138. /**
  139. * @brief Converts the elements of the Q31 vector to Q15 vector.
  140. * @param[in] pSrc is input pointer
  141. * @param[out] pDst is output pointer
  142. * @param[in] blockSize is the number of samples to process
  143. */
  144. void arm_q31_to_q15(
  145. const q31_t * pSrc,
  146. q15_t * pDst,
  147. uint32_t blockSize);
  148. /**
  149. * @brief Converts the elements of the Q31 vector to Q7 vector.
  150. * @param[in] pSrc is input pointer
  151. * @param[out] pDst is output pointer
  152. * @param[in] blockSize is the number of samples to process
  153. */
  154. void arm_q31_to_q7(
  155. const q31_t * pSrc,
  156. q7_t * pDst,
  157. uint32_t blockSize);
  158. /**
  159. * @brief Converts the elements of the Q15 vector to 64 bit floating-point vector.
  160. * @param[in] pSrc is input pointer
  161. * @param[out] pDst is output pointer
  162. * @param[in] blockSize is the number of samples to process
  163. */
  164. void arm_q15_to_f64(
  165. const q15_t * pSrc,
  166. float64_t * pDst,
  167. uint32_t blockSize);
  168. /**
  169. * @brief Converts the elements of the Q15 vector to floating-point vector.
  170. * @param[in] pSrc is input pointer
  171. * @param[out] pDst is output pointer
  172. * @param[in] blockSize is the number of samples to process
  173. */
  174. void arm_q15_to_float(
  175. const q15_t * pSrc,
  176. float32_t * pDst,
  177. uint32_t blockSize);
  178. /**
  179. * @brief Converts the elements of the Q15 vector to Q31 vector.
  180. * @param[in] pSrc is input pointer
  181. * @param[out] pDst is output pointer
  182. * @param[in] blockSize is the number of samples to process
  183. */
  184. void arm_q15_to_q31(
  185. const q15_t * pSrc,
  186. q31_t * pDst,
  187. uint32_t blockSize);
  188. /**
  189. * @brief Converts the elements of the Q15 vector to Q7 vector.
  190. * @param[in] pSrc is input pointer
  191. * @param[out] pDst is output pointer
  192. * @param[in] blockSize is the number of samples to process
  193. */
  194. void arm_q15_to_q7(
  195. const q15_t * pSrc,
  196. q7_t * pDst,
  197. uint32_t blockSize);
  198. /**
  199. * @brief Converts the elements of the Q7 vector to 64 bit floating-point vector.
  200. * @param[in] pSrc is input pointer
  201. * @param[out] pDst is output pointer
  202. * @param[in] blockSize is the number of samples to process
  203. */
  204. void arm_q7_to_f64(
  205. const q7_t * pSrc,
  206. float64_t * pDst,
  207. uint32_t blockSize);
  208. /**
  209. * @brief Converts the elements of the Q7 vector to floating-point vector.
  210. * @param[in] pSrc is input pointer
  211. * @param[out] pDst is output pointer
  212. * @param[in] blockSize is the number of samples to process
  213. */
  214. void arm_q7_to_float(
  215. const q7_t * pSrc,
  216. float32_t * pDst,
  217. uint32_t blockSize);
  218. /**
  219. * @brief Converts the elements of the Q7 vector to Q31 vector.
  220. * @param[in] pSrc input pointer
  221. * @param[out] pDst output pointer
  222. * @param[in] blockSize number of samples to process
  223. */
  224. void arm_q7_to_q31(
  225. const q7_t * pSrc,
  226. q31_t * pDst,
  227. uint32_t blockSize);
  228. /**
  229. * @brief Converts the elements of the Q7 vector to Q15 vector.
  230. * @param[in] pSrc input pointer
  231. * @param[out] pDst output pointer
  232. * @param[in] blockSize number of samples to process
  233. */
  234. void arm_q7_to_q15(
  235. const q7_t * pSrc,
  236. q15_t * pDst,
  237. uint32_t blockSize);
  238. /**
  239. * @brief Struct for specifying sorting algorithm
  240. */
  241. typedef enum
  242. {
  243. ARM_SORT_BITONIC = 0,
  244. /**< Bitonic sort */
  245. ARM_SORT_BUBBLE = 1,
  246. /**< Bubble sort */
  247. ARM_SORT_HEAP = 2,
  248. /**< Heap sort */
  249. ARM_SORT_INSERTION = 3,
  250. /**< Insertion sort */
  251. ARM_SORT_QUICK = 4,
  252. /**< Quick sort */
  253. ARM_SORT_SELECTION = 5
  254. /**< Selection sort */
  255. } arm_sort_alg;
  256. /**
  257. * @brief Struct for specifying sorting algorithm
  258. */
  259. typedef enum
  260. {
  261. ARM_SORT_DESCENDING = 0,
  262. /**< Descending order (9 to 0) */
  263. ARM_SORT_ASCENDING = 1
  264. /**< Ascending order (0 to 9) */
  265. } arm_sort_dir;
  266. /**
  267. * @brief Instance structure for the sorting algorithms.
  268. */
  269. typedef struct
  270. {
  271. arm_sort_alg alg; /**< Sorting algorithm selected */
  272. arm_sort_dir dir; /**< Sorting order (direction) */
  273. } arm_sort_instance_f32;
  274. /**
  275. * @param[in] S points to an instance of the sorting structure.
  276. * @param[in] pSrc points to the block of input data.
  277. * @param[out] pDst points to the block of output data.
  278. * @param[in] blockSize number of samples to process.
  279. */
  280. void arm_sort_f32(
  281. const arm_sort_instance_f32 * S,
  282. float32_t * pSrc,
  283. float32_t * pDst,
  284. uint32_t blockSize);
  285. /**
  286. * @param[in,out] S points to an instance of the sorting structure.
  287. * @param[in] alg Selected algorithm.
  288. * @param[in] dir Sorting order.
  289. */
  290. void arm_sort_init_f32(
  291. arm_sort_instance_f32 * S,
  292. arm_sort_alg alg,
  293. arm_sort_dir dir);
  294. /**
  295. * @brief Instance structure for the sorting algorithms.
  296. */
  297. typedef struct
  298. {
  299. arm_sort_dir dir; /**< Sorting order (direction) */
  300. float32_t * buffer; /**< Working buffer */
  301. } arm_merge_sort_instance_f32;
  302. /**
  303. * @param[in] S points to an instance of the sorting structure.
  304. * @param[in,out] pSrc points to the block of input data.
  305. * @param[out] pDst points to the block of output data
  306. * @param[in] blockSize number of samples to process.
  307. */
  308. void arm_merge_sort_f32(
  309. const arm_merge_sort_instance_f32 * S,
  310. float32_t *pSrc,
  311. float32_t *pDst,
  312. uint32_t blockSize);
  313. /**
  314. * @param[in,out] S points to an instance of the sorting structure.
  315. * @param[in] dir Sorting order.
  316. * @param[in] buffer Working buffer.
  317. */
  318. void arm_merge_sort_init_f32(
  319. arm_merge_sort_instance_f32 * S,
  320. arm_sort_dir dir,
  321. float32_t * buffer);
  322. /**
  323. * @brief Copies the elements of a floating-point vector.
  324. * @param[in] pSrc input pointer
  325. * @param[out] pDst output pointer
  326. * @param[in] blockSize number of samples to process
  327. */
  328. void arm_copy_f32(
  329. const float32_t * pSrc,
  330. float32_t * pDst,
  331. uint32_t blockSize);
  332. /**
  333. * @brief Copies the elements of a floating-point vector.
  334. * @param[in] pSrc input pointer
  335. * @param[out] pDst output pointer
  336. * @param[in] blockSize number of samples to process
  337. */
  338. void arm_copy_f64(
  339. const float64_t * pSrc,
  340. float64_t * pDst,
  341. uint32_t blockSize);
  342. /**
  343. * @brief Copies the elements of a Q7 vector.
  344. * @param[in] pSrc input pointer
  345. * @param[out] pDst output pointer
  346. * @param[in] blockSize number of samples to process
  347. */
  348. void arm_copy_q7(
  349. const q7_t * pSrc,
  350. q7_t * pDst,
  351. uint32_t blockSize);
  352. /**
  353. * @brief Copies the elements of a Q15 vector.
  354. * @param[in] pSrc input pointer
  355. * @param[out] pDst output pointer
  356. * @param[in] blockSize number of samples to process
  357. */
  358. void arm_copy_q15(
  359. const q15_t * pSrc,
  360. q15_t * pDst,
  361. uint32_t blockSize);
  362. /**
  363. * @brief Copies the elements of a Q31 vector.
  364. * @param[in] pSrc input pointer
  365. * @param[out] pDst output pointer
  366. * @param[in] blockSize number of samples to process
  367. */
  368. void arm_copy_q31(
  369. const q31_t * pSrc,
  370. q31_t * pDst,
  371. uint32_t blockSize);
  372. /**
  373. * @brief Fills a constant value into a floating-point vector.
  374. * @param[in] value input value to be filled
  375. * @param[out] pDst output pointer
  376. * @param[in] blockSize number of samples to process
  377. */
  378. void arm_fill_f32(
  379. float32_t value,
  380. float32_t * pDst,
  381. uint32_t blockSize);
  382. /**
  383. * @brief Fills a constant value into a floating-point vector.
  384. * @param[in] value input value to be filled
  385. * @param[out] pDst output pointer
  386. * @param[in] blockSize number of samples to process
  387. */
  388. void arm_fill_f64(
  389. float64_t value,
  390. float64_t * pDst,
  391. uint32_t blockSize);
  392. /**
  393. * @brief Fills a constant value into a Q7 vector.
  394. * @param[in] value input value to be filled
  395. * @param[out] pDst output pointer
  396. * @param[in] blockSize number of samples to process
  397. */
  398. void arm_fill_q7(
  399. q7_t value,
  400. q7_t * pDst,
  401. uint32_t blockSize);
  402. /**
  403. * @brief Fills a constant value into a Q15 vector.
  404. * @param[in] value input value to be filled
  405. * @param[out] pDst output pointer
  406. * @param[in] blockSize number of samples to process
  407. */
  408. void arm_fill_q15(
  409. q15_t value,
  410. q15_t * pDst,
  411. uint32_t blockSize);
  412. /**
  413. * @brief Fills a constant value into a Q31 vector.
  414. * @param[in] value input value to be filled
  415. * @param[out] pDst output pointer
  416. * @param[in] blockSize number of samples to process
  417. */
  418. void arm_fill_q31(
  419. q31_t value,
  420. q31_t * pDst,
  421. uint32_t blockSize);
  422. /**
  423. * @brief Weighted sum
  424. *
  425. *
  426. * @param[in] *in Array of input values.
  427. * @param[in] *weigths Weights
  428. * @param[in] blockSize Number of samples in the input array.
  429. * @return Weighted sum
  430. *
  431. */
  432. float32_t arm_weighted_sum_f32(const float32_t *in
  433. , const float32_t *weigths
  434. , uint32_t blockSize);
  435. /**
  436. * @brief Barycenter
  437. *
  438. *
  439. * @param[in] in List of vectors
  440. * @param[in] weights Weights of the vectors
  441. * @param[out] out Barycenter
  442. * @param[in] nbVectors Number of vectors
  443. * @param[in] vecDim Dimension of space (vector dimension)
  444. *
  445. */
  446. void arm_barycenter_f32(const float32_t *in
  447. , const float32_t *weights
  448. , float32_t *out
  449. , uint32_t nbVectors
  450. , uint32_t vecDim);
  451. #ifdef __cplusplus
  452. }
  453. #endif
  454. #endif /* ifndef _SUPPORT_FUNCTIONS_H_ */