Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

8971 lines
307KB

  1. /******************************************************************************
  2. * @file arm_math.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.7.0
  5. * @date 18. March 2019
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2010-2019 Arm Limited or its affiliates. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. /**
  25. \mainpage CMSIS DSP Software Library
  26. *
  27. * Introduction
  28. * ------------
  29. *
  30. * This user manual describes the CMSIS DSP software library,
  31. * a suite of common signal processing functions for use on Cortex-M and Cortex-A processor
  32. * based devices.
  33. *
  34. * The library is divided into a number of functions each covering a specific category:
  35. * - Basic math functions
  36. * - Fast math functions
  37. * - Complex math functions
  38. * - Filtering functions
  39. * - Matrix functions
  40. * - Transform functions
  41. * - Motor control functions
  42. * - Statistical functions
  43. * - Support functions
  44. * - Interpolation functions
  45. * - Support Vector Machine functions (SVM)
  46. * - Bayes classifier functions
  47. * - Distance functions
  48. *
  49. * The library has generally separate functions for operating on 8-bit integers, 16-bit integers,
  50. * 32-bit integer and 32-bit floating-point values.
  51. *
  52. * Using the Library
  53. * ------------
  54. *
  55. * The library installer contains prebuilt versions of the libraries in the <code>Lib</code> folder.
  56. *
  57. * Here is the list of pre-built libraries :
  58. * - arm_cortexM7lfdp_math.lib (Cortex-M7, Little endian, Double Precision Floating Point Unit)
  59. * - arm_cortexM7bfdp_math.lib (Cortex-M7, Big endian, Double Precision Floating Point Unit)
  60. * - arm_cortexM7lfsp_math.lib (Cortex-M7, Little endian, Single Precision Floating Point Unit)
  61. * - arm_cortexM7bfsp_math.lib (Cortex-M7, Big endian and Single Precision Floating Point Unit on)
  62. * - arm_cortexM7l_math.lib (Cortex-M7, Little endian)
  63. * - arm_cortexM7b_math.lib (Cortex-M7, Big endian)
  64. * - arm_cortexM4lf_math.lib (Cortex-M4, Little endian, Floating Point Unit)
  65. * - arm_cortexM4bf_math.lib (Cortex-M4, Big endian, Floating Point Unit)
  66. * - arm_cortexM4l_math.lib (Cortex-M4, Little endian)
  67. * - arm_cortexM4b_math.lib (Cortex-M4, Big endian)
  68. * - arm_cortexM3l_math.lib (Cortex-M3, Little endian)
  69. * - arm_cortexM3b_math.lib (Cortex-M3, Big endian)
  70. * - arm_cortexM0l_math.lib (Cortex-M0 / Cortex-M0+, Little endian)
  71. * - arm_cortexM0b_math.lib (Cortex-M0 / Cortex-M0+, Big endian)
  72. * - arm_ARMv8MBLl_math.lib (Armv8-M Baseline, Little endian)
  73. * - arm_ARMv8MMLl_math.lib (Armv8-M Mainline, Little endian)
  74. * - arm_ARMv8MMLlfsp_math.lib (Armv8-M Mainline, Little endian, Single Precision Floating Point Unit)
  75. * - arm_ARMv8MMLld_math.lib (Armv8-M Mainline, Little endian, DSP instructions)
  76. * - arm_ARMv8MMLldfsp_math.lib (Armv8-M Mainline, Little endian, DSP instructions, Single Precision Floating Point Unit)
  77. *
  78. * The library functions are declared in the public file <code>arm_math.h</code> which is placed in the <code>Include</code> folder.
  79. * Simply include this file and link the appropriate library in the application and begin calling the library functions. The Library supports single
  80. * public header file <code> arm_math.h</code> for Cortex-M cores with little endian and big endian. Same header file will be used for floating point unit(FPU) variants.
  81. *
  82. *
  83. * Examples
  84. * --------
  85. *
  86. * The library ships with a number of examples which demonstrate how to use the library functions.
  87. *
  88. * Toolchain Support
  89. * ------------
  90. *
  91. * The library is now tested on Fast Models building with cmake.
  92. * Core M0, M7, A5 are tested.
  93. *
  94. *
  95. *
  96. * Building the Library
  97. * ------------
  98. *
  99. * The library installer contains a project file to rebuild libraries on MDK toolchain in the <code>CMSIS\\DSP\\Projects\\ARM</code> folder.
  100. * - arm_cortexM_math.uvprojx
  101. *
  102. *
  103. * The libraries can be built by opening the arm_cortexM_math.uvprojx project in MDK-ARM, selecting a specific target, and defining the optional preprocessor macros detailed above.
  104. *
  105. * There is also a work in progress cmake build. The README file is giving more details.
  106. *
  107. * Preprocessor Macros
  108. * ------------
  109. *
  110. * Each library project have different preprocessor macros.
  111. *
  112. * - ARM_MATH_BIG_ENDIAN:
  113. *
  114. * Define macro ARM_MATH_BIG_ENDIAN to build the library for big endian targets. By default library builds for little endian targets.
  115. *
  116. * - ARM_MATH_MATRIX_CHECK:
  117. *
  118. * Define macro ARM_MATH_MATRIX_CHECK for checking on the input and output sizes of matrices
  119. *
  120. * - ARM_MATH_ROUNDING:
  121. *
  122. * Define macro ARM_MATH_ROUNDING for rounding on support functions
  123. *
  124. * - ARM_MATH_LOOPUNROLL:
  125. *
  126. * Define macro ARM_MATH_LOOPUNROLL to enable manual loop unrolling in DSP functions
  127. *
  128. * - ARM_MATH_NEON:
  129. *
  130. * Define macro ARM_MATH_NEON to enable Neon versions of the DSP functions.
  131. * It is not enabled by default when Neon is available because performances are
  132. * dependent on the compiler and target architecture.
  133. *
  134. * - ARM_MATH_NEON_EXPERIMENTAL:
  135. *
  136. * Define macro ARM_MATH_NEON_EXPERIMENTAL to enable experimental Neon versions of
  137. * of some DSP functions. Experimental Neon versions currently do not have better
  138. * performances than the scalar versions.
  139. *
  140. * - ARM_MATH_HELIUM:
  141. *
  142. * It implies the flags ARM_MATH_MVEF and ARM_MATH_MVEI and ARM_MATH_FLOAT16.
  143. *
  144. * - ARM_MATH_MVEF:
  145. *
  146. * Select Helium versions of the f32 algorithms.
  147. * It implies ARM_MATH_FLOAT16 and ARM_MATH_MVEI.
  148. *
  149. * - ARM_MATH_MVEI:
  150. *
  151. * Select Helium versions of the int and fixed point algorithms.
  152. *
  153. * - ARM_MATH_FLOAT16:
  154. *
  155. * Float16 implementations of some algorithms (Requires MVE extension).
  156. *
  157. * <hr>
  158. * CMSIS-DSP in ARM::CMSIS Pack
  159. * -----------------------------
  160. *
  161. * The following files relevant to CMSIS-DSP are present in the <b>ARM::CMSIS</b> Pack directories:
  162. * |File/Folder |Content |
  163. * |---------------------------------|------------------------------------------------------------------------|
  164. * |\b CMSIS\\Documentation\\DSP | This documentation |
  165. * |\b CMSIS\\DSP\\DSP_Lib_TestSuite | DSP_Lib test suite |
  166. * |\b CMSIS\\DSP\\Examples | Example projects demonstrating the usage of the library functions |
  167. * |\b CMSIS\\DSP\\Include | DSP_Lib include files |
  168. * |\b CMSIS\\DSP\\Lib | DSP_Lib binaries |
  169. * |\b CMSIS\\DSP\\Projects | Projects to rebuild DSP_Lib binaries |
  170. * |\b CMSIS\\DSP\\Source | DSP_Lib source files |
  171. *
  172. * <hr>
  173. * Revision History of CMSIS-DSP
  174. * ------------
  175. * Please refer to \ref ChangeLog_pg.
  176. */
  177. /**
  178. * @defgroup groupMath Basic Math Functions
  179. */
  180. /**
  181. * @defgroup groupFastMath Fast Math Functions
  182. * This set of functions provides a fast approximation to sine, cosine, and square root.
  183. * As compared to most of the other functions in the CMSIS math library, the fast math functions
  184. * operate on individual values and not arrays.
  185. * There are separate functions for Q15, Q31, and floating-point data.
  186. *
  187. */
  188. /**
  189. * @defgroup groupCmplxMath Complex Math Functions
  190. * This set of functions operates on complex data vectors.
  191. * The data in the complex arrays is stored in an interleaved fashion
  192. * (real, imag, real, imag, ...).
  193. * In the API functions, the number of samples in a complex array refers
  194. * to the number of complex values; the array contains twice this number of
  195. * real values.
  196. */
  197. /**
  198. * @defgroup groupFilters Filtering Functions
  199. */
  200. /**
  201. * @defgroup groupMatrix Matrix Functions
  202. *
  203. * This set of functions provides basic matrix math operations.
  204. * The functions operate on matrix data structures. For example,
  205. * the type
  206. * definition for the floating-point matrix structure is shown
  207. * below:
  208. * <pre>
  209. * typedef struct
  210. * {
  211. * uint16_t numRows; // number of rows of the matrix.
  212. * uint16_t numCols; // number of columns of the matrix.
  213. * float32_t *pData; // points to the data of the matrix.
  214. * } arm_matrix_instance_f32;
  215. * </pre>
  216. * There are similar definitions for Q15 and Q31 data types.
  217. *
  218. * The structure specifies the size of the matrix and then points to
  219. * an array of data. The array is of size <code>numRows X numCols</code>
  220. * and the values are arranged in row order. That is, the
  221. * matrix element (i, j) is stored at:
  222. * <pre>
  223. * pData[i*numCols + j]
  224. * </pre>
  225. *
  226. * \par Init Functions
  227. * There is an associated initialization function for each type of matrix
  228. * data structure.
  229. * The initialization function sets the values of the internal structure fields.
  230. * Refer to \ref arm_mat_init_f32(), \ref arm_mat_init_q31() and \ref arm_mat_init_q15()
  231. * for floating-point, Q31 and Q15 types, respectively.
  232. *
  233. * \par
  234. * Use of the initialization function is optional. However, if initialization function is used
  235. * then the instance structure cannot be placed into a const data section.
  236. * To place the instance structure in a const data
  237. * section, manually initialize the data structure. For example:
  238. * <pre>
  239. * <code>arm_matrix_instance_f32 S = {nRows, nColumns, pData};</code>
  240. * <code>arm_matrix_instance_q31 S = {nRows, nColumns, pData};</code>
  241. * <code>arm_matrix_instance_q15 S = {nRows, nColumns, pData};</code>
  242. * </pre>
  243. * where <code>nRows</code> specifies the number of rows, <code>nColumns</code>
  244. * specifies the number of columns, and <code>pData</code> points to the
  245. * data array.
  246. *
  247. * \par Size Checking
  248. * By default all of the matrix functions perform size checking on the input and
  249. * output matrices. For example, the matrix addition function verifies that the
  250. * two input matrices and the output matrix all have the same number of rows and
  251. * columns. If the size check fails the functions return:
  252. * <pre>
  253. * ARM_MATH_SIZE_MISMATCH
  254. * </pre>
  255. * Otherwise the functions return
  256. * <pre>
  257. * ARM_MATH_SUCCESS
  258. * </pre>
  259. * There is some overhead associated with this matrix size checking.
  260. * The matrix size checking is enabled via the \#define
  261. * <pre>
  262. * ARM_MATH_MATRIX_CHECK
  263. * </pre>
  264. * within the library project settings. By default this macro is defined
  265. * and size checking is enabled. By changing the project settings and
  266. * undefining this macro size checking is eliminated and the functions
  267. * run a bit faster. With size checking disabled the functions always
  268. * return <code>ARM_MATH_SUCCESS</code>.
  269. */
  270. /**
  271. * @defgroup groupTransforms Transform Functions
  272. */
  273. /**
  274. * @defgroup groupController Controller Functions
  275. */
  276. /**
  277. * @defgroup groupStats Statistics Functions
  278. */
  279. /**
  280. * @defgroup groupSupport Support Functions
  281. */
  282. /**
  283. * @defgroup groupInterpolation Interpolation Functions
  284. * These functions perform 1- and 2-dimensional interpolation of data.
  285. * Linear interpolation is used for 1-dimensional data and
  286. * bilinear interpolation is used for 2-dimensional data.
  287. */
  288. /**
  289. * @defgroup groupExamples Examples
  290. */
  291. /**
  292. * @defgroup groupSVM SVM Functions
  293. * This set of functions is implementing SVM classification on 2 classes.
  294. * The training must be done from scikit-learn. The parameters can be easily
  295. * generated from the scikit-learn object. Some examples are given in
  296. * DSP/Testing/PatternGeneration/SVM.py
  297. *
  298. * If more than 2 classes are needed, the functions in this folder
  299. * will have to be used, as building blocks, to do multi-class classification.
  300. *
  301. * No multi-class classification is provided in this SVM folder.
  302. *
  303. */
  304. /**
  305. * @defgroup groupBayes Bayesian estimators
  306. *
  307. * Implement the naive gaussian Bayes estimator.
  308. * The training must be done from scikit-learn.
  309. *
  310. * The parameters can be easily
  311. * generated from the scikit-learn object. Some examples are given in
  312. * DSP/Testing/PatternGeneration/Bayes.py
  313. */
  314. /**
  315. * @defgroup groupDistance Distance functions
  316. *
  317. * Distance functions for use with clustering algorithms.
  318. * There are distance functions for float vectors and boolean vectors.
  319. *
  320. */
  321. #ifndef _ARM_MATH_H
  322. #define _ARM_MATH_H
  323. #ifdef __cplusplus
  324. extern "C"
  325. {
  326. #endif
  327. /* Compiler specific diagnostic adjustment */
  328. #if defined ( __CC_ARM )
  329. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  330. #elif defined ( __GNUC__ )
  331. #pragma GCC diagnostic push
  332. #pragma GCC diagnostic ignored "-Wsign-conversion"
  333. #pragma GCC diagnostic ignored "-Wconversion"
  334. #pragma GCC diagnostic ignored "-Wunused-parameter"
  335. #elif defined ( __ICCARM__ )
  336. #elif defined ( __TI_ARM__ )
  337. #elif defined ( __CSMC__ )
  338. #elif defined ( __TASKING__ )
  339. #elif defined ( _MSC_VER )
  340. #else
  341. #error Unknown compiler
  342. #endif
  343. /* Included for instrinsics definitions */
  344. #if defined (_MSC_VER )
  345. #include <stdint.h>
  346. #define __STATIC_FORCEINLINE static __forceinline
  347. #define __STATIC_INLINE static __inline
  348. #define __ALIGNED(x) __declspec(align(x))
  349. #elif defined (__GNUC_PYTHON__)
  350. #include <stdint.h>
  351. #define __ALIGNED(x) __attribute__((aligned(x)))
  352. #define __STATIC_FORCEINLINE static __attribute__((inline))
  353. #define __STATIC_INLINE static __attribute__((inline))
  354. #pragma GCC diagnostic ignored "-Wunused-function"
  355. #pragma GCC diagnostic ignored "-Wattributes"
  356. #else
  357. #include "cmsis_compiler.h"
  358. #endif
  359. #include <string.h>
  360. #include <math.h>
  361. #include <float.h>
  362. #include <limits.h>
  363. #define F64_MAX ((float64_t)DBL_MAX)
  364. #define F32_MAX ((float32_t)FLT_MAX)
  365. #if defined(ARM_MATH_FLOAT16)
  366. #define F16_MAX ((float16_t)FLT_MAX)
  367. #endif
  368. #define F64_MIN (-DBL_MAX)
  369. #define F32_MIN (-FLT_MAX)
  370. #if defined(ARM_MATH_FLOAT16)
  371. #define F16_MIN (-(float16_t)FLT_MAX)
  372. #endif
  373. #define F64_ABSMAX ((float64_t)DBL_MAX)
  374. #define F32_ABSMAX ((float32_t)FLT_MAX)
  375. #if defined(ARM_MATH_FLOAT16)
  376. #define F16_ABSMAX ((float16_t)FLT_MAX)
  377. #endif
  378. #define F64_ABSMIN ((float64_t)0.0)
  379. #define F32_ABSMIN ((float32_t)0.0)
  380. #if defined(ARM_MATH_FLOAT16)
  381. #define F16_ABSMIN ((float16_t)0.0)
  382. #endif
  383. #define Q31_MAX ((q31_t)(0x7FFFFFFFL))
  384. #define Q15_MAX ((q15_t)(0x7FFF))
  385. #define Q7_MAX ((q7_t)(0x7F))
  386. #define Q31_MIN ((q31_t)(0x80000000L))
  387. #define Q15_MIN ((q15_t)(0x8000))
  388. #define Q7_MIN ((q7_t)(0x80))
  389. #define Q31_ABSMAX ((q31_t)(0x7FFFFFFFL))
  390. #define Q15_ABSMAX ((q15_t)(0x7FFF))
  391. #define Q7_ABSMAX ((q7_t)(0x7F))
  392. #define Q31_ABSMIN ((q31_t)0)
  393. #define Q15_ABSMIN ((q15_t)0)
  394. #define Q7_ABSMIN ((q7_t)0)
  395. /* evaluate ARM DSP feature */
  396. #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
  397. #define ARM_MATH_DSP 1
  398. #endif
  399. #if defined(ARM_MATH_NEON)
  400. #include <arm_neon.h>
  401. #endif
  402. #if defined (ARM_MATH_HELIUM)
  403. #define ARM_MATH_MVEF
  404. #define ARM_MATH_FLOAT16
  405. #endif
  406. #if defined (ARM_MATH_MVEF)
  407. #define ARM_MATH_MVEI
  408. #define ARM_MATH_FLOAT16
  409. #endif
  410. #if defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI)
  411. #include <arm_mve.h>
  412. #endif
  413. /**
  414. * @brief Macros required for reciprocal calculation in Normalized LMS
  415. */
  416. #define DELTA_Q31 ((q31_t)(0x100))
  417. #define DELTA_Q15 ((q15_t)0x5)
  418. #define INDEX_MASK 0x0000003F
  419. #ifndef PI
  420. #define PI 3.14159265358979f
  421. #endif
  422. /**
  423. * @brief Macros required for SINE and COSINE Fast math approximations
  424. */
  425. #define FAST_MATH_TABLE_SIZE 512
  426. #define FAST_MATH_Q31_SHIFT (32 - 10)
  427. #define FAST_MATH_Q15_SHIFT (16 - 10)
  428. #define CONTROLLER_Q31_SHIFT (32 - 9)
  429. #define TABLE_SPACING_Q31 0x400000
  430. #define TABLE_SPACING_Q15 0x80
  431. /**
  432. * @brief Macros required for SINE and COSINE Controller functions
  433. */
  434. /* 1.31(q31) Fixed value of 2/360 */
  435. /* -1 to +1 is divided into 360 values so total spacing is (2/360) */
  436. #define INPUT_SPACING 0xB60B61
  437. /**
  438. * @brief Macros for complex numbers
  439. */
  440. /* Dimension C vector space */
  441. #define CMPLX_DIM 2
  442. /**
  443. * @brief Error status returned by some functions in the library.
  444. */
  445. typedef enum
  446. {
  447. ARM_MATH_SUCCESS = 0, /**< No error */
  448. ARM_MATH_ARGUMENT_ERROR = -1, /**< One or more arguments are incorrect */
  449. ARM_MATH_LENGTH_ERROR = -2, /**< Length of data buffer is incorrect */
  450. ARM_MATH_SIZE_MISMATCH = -3, /**< Size of matrices is not compatible with the operation */
  451. ARM_MATH_NANINF = -4, /**< Not-a-number (NaN) or infinity is generated */
  452. ARM_MATH_SINGULAR = -5, /**< Input matrix is singular and cannot be inverted */
  453. ARM_MATH_TEST_FAILURE = -6 /**< Test Failed */
  454. } arm_status;
  455. /**
  456. * @brief 8-bit fractional data type in 1.7 format.
  457. */
  458. typedef int8_t q7_t;
  459. /**
  460. * @brief 16-bit fractional data type in 1.15 format.
  461. */
  462. typedef int16_t q15_t;
  463. /**
  464. * @brief 32-bit fractional data type in 1.31 format.
  465. */
  466. typedef int32_t q31_t;
  467. /**
  468. * @brief 64-bit fractional data type in 1.63 format.
  469. */
  470. typedef int64_t q63_t;
  471. /**
  472. * @brief 32-bit floating-point type definition.
  473. */
  474. typedef float float32_t;
  475. /**
  476. * @brief 64-bit floating-point type definition.
  477. */
  478. typedef double float64_t;
  479. /**
  480. * @brief vector types
  481. */
  482. #if defined(ARM_MATH_NEON) || defined (ARM_MATH_MVEI)
  483. /**
  484. * @brief 64-bit fractional 128-bit vector data type in 1.63 format
  485. */
  486. typedef int64x2_t q63x2_t;
  487. /**
  488. * @brief 32-bit fractional 128-bit vector data type in 1.31 format.
  489. */
  490. typedef int32x4_t q31x4_t;
  491. /**
  492. * @brief 16-bit fractional 128-bit vector data type with 16-bit alignement in 1.15 format.
  493. */
  494. typedef __ALIGNED(2) int16x8_t q15x8_t;
  495. /**
  496. * @brief 8-bit fractional 128-bit vector data type with 8-bit alignement in 1.7 format.
  497. */
  498. typedef __ALIGNED(1) int8x16_t q7x16_t;
  499. /**
  500. * @brief 32-bit fractional 128-bit vector pair data type in 1.31 format.
  501. */
  502. typedef int32x4x2_t q31x4x2_t;
  503. /**
  504. * @brief 32-bit fractional 128-bit vector quadruplet data type in 1.31 format.
  505. */
  506. typedef int32x4x4_t q31x4x4_t;
  507. /**
  508. * @brief 16-bit fractional 128-bit vector pair data type in 1.15 format.
  509. */
  510. typedef int16x8x2_t q15x8x2_t;
  511. /**
  512. * @brief 16-bit fractional 128-bit vector quadruplet data type in 1.15 format.
  513. */
  514. typedef int16x8x4_t q15x8x4_t;
  515. /**
  516. * @brief 8-bit fractional 128-bit vector pair data type in 1.7 format.
  517. */
  518. typedef int8x16x2_t q7x16x2_t;
  519. /**
  520. * @brief 8-bit fractional 128-bit vector quadruplet data type in 1.7 format.
  521. */
  522. typedef int8x16x4_t q7x16x4_t;
  523. /**
  524. * @brief 32-bit fractional data type in 9.23 format.
  525. */
  526. typedef int32_t q23_t;
  527. /**
  528. * @brief 32-bit fractional 128-bit vector data type in 9.23 format.
  529. */
  530. typedef int32x4_t q23x4_t;
  531. /**
  532. * @brief 64-bit status 128-bit vector data type.
  533. */
  534. typedef int64x2_t status64x2_t;
  535. /**
  536. * @brief 32-bit status 128-bit vector data type.
  537. */
  538. typedef int32x4_t status32x4_t;
  539. /**
  540. * @brief 16-bit status 128-bit vector data type.
  541. */
  542. typedef int16x8_t status16x8_t;
  543. /**
  544. * @brief 8-bit status 128-bit vector data type.
  545. */
  546. typedef int8x16_t status8x16_t;
  547. #endif
  548. #if defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF) /* floating point vector*/
  549. /**
  550. * @brief 32-bit floating-point 128-bit vector type
  551. */
  552. typedef float32x4_t f32x4_t;
  553. #if defined(ARM_MATH_FLOAT16)
  554. /**
  555. * @brief 16-bit floating-point 128-bit vector data type
  556. */
  557. typedef __ALIGNED(2) float16x8_t f16x8_t;
  558. #endif
  559. /**
  560. * @brief 32-bit floating-point 128-bit vector pair data type
  561. */
  562. typedef float32x4x2_t f32x4x2_t;
  563. /**
  564. * @brief 32-bit floating-point 128-bit vector quadruplet data type
  565. */
  566. typedef float32x4x4_t f32x4x4_t;
  567. #if defined(ARM_MATH_FLOAT16)
  568. /**
  569. * @brief 16-bit floating-point 128-bit vector pair data type
  570. */
  571. typedef float16x8x2_t f16x8x2_t;
  572. /**
  573. * @brief 16-bit floating-point 128-bit vector quadruplet data type
  574. */
  575. typedef float16x8x4_t f16x8x4_t;
  576. #endif
  577. /**
  578. * @brief 32-bit ubiquitous 128-bit vector data type
  579. */
  580. typedef union _any32x4_t
  581. {
  582. float32x4_t f;
  583. int32x4_t i;
  584. } any32x4_t;
  585. #if defined(ARM_MATH_FLOAT16)
  586. /**
  587. * @brief 16-bit ubiquitous 128-bit vector data type
  588. */
  589. typedef union _any16x8_t
  590. {
  591. float16x8_t f;
  592. int16x8_t i;
  593. } any16x8_t;
  594. #endif
  595. #endif
  596. #if defined(ARM_MATH_NEON)
  597. /**
  598. * @brief 32-bit fractional 64-bit vector data type in 1.31 format.
  599. */
  600. typedef int32x2_t q31x2_t;
  601. /**
  602. * @brief 16-bit fractional 64-bit vector data type in 1.15 format.
  603. */
  604. typedef __ALIGNED(2) int16x4_t q15x4_t;
  605. /**
  606. * @brief 8-bit fractional 64-bit vector data type in 1.7 format.
  607. */
  608. typedef __ALIGNED(1) int8x8_t q7x8_t;
  609. /**
  610. * @brief 32-bit float 64-bit vector data type.
  611. */
  612. typedef float32x2_t f32x2_t;
  613. #if defined(ARM_MATH_FLOAT16)
  614. /**
  615. * @brief 16-bit float 64-bit vector data type.
  616. */
  617. typedef __ALIGNED(2) float16x4_t f16x4_t;
  618. #endif
  619. /**
  620. * @brief 32-bit floating-point 128-bit vector triplet data type
  621. */
  622. typedef float32x4x3_t f32x4x3_t;
  623. #if defined(ARM_MATH_FLOAT16)
  624. /**
  625. * @brief 16-bit floating-point 128-bit vector triplet data type
  626. */
  627. typedef float16x8x3_t f16x8x3_t;
  628. #endif
  629. /**
  630. * @brief 32-bit fractional 128-bit vector triplet data type in 1.31 format
  631. */
  632. typedef int32x4x3_t q31x4x3_t;
  633. /**
  634. * @brief 16-bit fractional 128-bit vector triplet data type in 1.15 format
  635. */
  636. typedef int16x8x3_t q15x8x3_t;
  637. /**
  638. * @brief 8-bit fractional 128-bit vector triplet data type in 1.7 format
  639. */
  640. typedef int8x16x3_t q7x16x3_t;
  641. /**
  642. * @brief 32-bit floating-point 64-bit vector pair data type
  643. */
  644. typedef float32x2x2_t f32x2x2_t;
  645. /**
  646. * @brief 32-bit floating-point 64-bit vector triplet data type
  647. */
  648. typedef float32x2x3_t f32x2x3_t;
  649. /**
  650. * @brief 32-bit floating-point 64-bit vector quadruplet data type
  651. */
  652. typedef float32x2x4_t f32x2x4_t;
  653. #if defined(ARM_MATH_FLOAT16)
  654. /**
  655. * @brief 16-bit floating-point 64-bit vector pair data type
  656. */
  657. typedef float16x4x2_t f16x4x2_t;
  658. /**
  659. * @brief 16-bit floating-point 64-bit vector triplet data type
  660. */
  661. typedef float16x4x3_t f16x4x3_t;
  662. /**
  663. * @brief 16-bit floating-point 64-bit vector quadruplet data type
  664. */
  665. typedef float16x4x4_t f16x4x4_t;
  666. #endif
  667. /**
  668. * @brief 32-bit fractional 64-bit vector pair data type in 1.31 format
  669. */
  670. typedef int32x2x2_t q31x2x2_t;
  671. /**
  672. * @brief 32-bit fractional 64-bit vector triplet data type in 1.31 format
  673. */
  674. typedef int32x2x3_t q31x2x3_t;
  675. /**
  676. * @brief 32-bit fractional 64-bit vector quadruplet data type in 1.31 format
  677. */
  678. typedef int32x4x3_t q31x2x4_t;
  679. /**
  680. * @brief 16-bit fractional 64-bit vector pair data type in 1.15 format
  681. */
  682. typedef int16x4x2_t q15x4x2_t;
  683. /**
  684. * @brief 16-bit fractional 64-bit vector triplet data type in 1.15 format
  685. */
  686. typedef int16x4x2_t q15x4x3_t;
  687. /**
  688. * @brief 16-bit fractional 64-bit vector quadruplet data type in 1.15 format
  689. */
  690. typedef int16x4x3_t q15x4x4_t;
  691. /**
  692. * @brief 8-bit fractional 64-bit vector pair data type in 1.7 format
  693. */
  694. typedef int8x8x2_t q7x8x2_t;
  695. /**
  696. * @brief 8-bit fractional 64-bit vector triplet data type in 1.7 format
  697. */
  698. typedef int8x8x3_t q7x8x3_t;
  699. /**
  700. * @brief 8-bit fractional 64-bit vector quadruplet data type in 1.7 format
  701. */
  702. typedef int8x8x4_t q7x8x4_t;
  703. /**
  704. * @brief 32-bit ubiquitous 64-bit vector data type
  705. */
  706. typedef union _any32x2_t
  707. {
  708. float32x2_t f;
  709. int32x2_t i;
  710. } any32x2_t;
  711. #if defined(ARM_MATH_FLOAT16)
  712. /**
  713. * @brief 16-bit ubiquitous 64-bit vector data type
  714. */
  715. typedef union _any16x4_t
  716. {
  717. float16x4_t f;
  718. int16x4_t i;
  719. } any16x4_t;
  720. #endif
  721. /**
  722. * @brief 32-bit status 64-bit vector data type.
  723. */
  724. typedef int32x4_t status32x2_t;
  725. /**
  726. * @brief 16-bit status 64-bit vector data type.
  727. */
  728. typedef int16x8_t status16x4_t;
  729. /**
  730. * @brief 8-bit status 64-bit vector data type.
  731. */
  732. typedef int8x16_t status8x8_t;
  733. #endif
  734. /**
  735. @brief definition to read/write two 16 bit values.
  736. @deprecated
  737. */
  738. #if defined ( __CC_ARM )
  739. #define __SIMD32_TYPE int32_t __packed
  740. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  741. #define __SIMD32_TYPE int32_t
  742. #elif defined ( __GNUC__ )
  743. #define __SIMD32_TYPE int32_t
  744. #elif defined ( __ICCARM__ )
  745. #define __SIMD32_TYPE int32_t __packed
  746. #elif defined ( __TI_ARM__ )
  747. #define __SIMD32_TYPE int32_t
  748. #elif defined ( __CSMC__ )
  749. #define __SIMD32_TYPE int32_t
  750. #elif defined ( __TASKING__ )
  751. #define __SIMD32_TYPE __un(aligned) int32_t
  752. #elif defined(_MSC_VER )
  753. #define __SIMD32_TYPE int32_t
  754. #else
  755. #error Unknown compiler
  756. #endif
  757. #define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr))
  758. #define __SIMD32_CONST(addr) ( (__SIMD32_TYPE * ) (addr))
  759. #define _SIMD32_OFFSET(addr) (*(__SIMD32_TYPE * ) (addr))
  760. #define __SIMD64(addr) (*( int64_t **) & (addr))
  761. #define STEP(x) (x) <= 0 ? 0 : 1
  762. #define SQ(x) ((x) * (x))
  763. /* SIMD replacement */
  764. /**
  765. @brief Read 2 Q15 from Q15 pointer.
  766. @param[in] pQ15 points to input value
  767. @return Q31 value
  768. */
  769. __STATIC_FORCEINLINE q31_t read_q15x2 (
  770. q15_t * pQ15)
  771. {
  772. q31_t val;
  773. #ifdef __ARM_FEATURE_UNALIGNED
  774. memcpy (&val, pQ15, 4);
  775. #else
  776. val = (pQ15[1] << 16) | (pQ15[0] & 0x0FFFF) ;
  777. #endif
  778. return (val);
  779. }
  780. /**
  781. @brief Read 2 Q15 from Q15 pointer and increment pointer afterwards.
  782. @param[in] pQ15 points to input value
  783. @return Q31 value
  784. */
  785. __STATIC_FORCEINLINE q31_t read_q15x2_ia (
  786. q15_t ** pQ15)
  787. {
  788. q31_t val;
  789. #ifdef __ARM_FEATURE_UNALIGNED
  790. memcpy (&val, *pQ15, 4);
  791. #else
  792. val = ((*pQ15)[1] << 16) | ((*pQ15)[0] & 0x0FFFF);
  793. #endif
  794. *pQ15 += 2;
  795. return (val);
  796. }
  797. /**
  798. @brief Read 2 Q15 from Q15 pointer and decrement pointer afterwards.
  799. @param[in] pQ15 points to input value
  800. @return Q31 value
  801. */
  802. __STATIC_FORCEINLINE q31_t read_q15x2_da (
  803. q15_t ** pQ15)
  804. {
  805. q31_t val;
  806. #ifdef __ARM_FEATURE_UNALIGNED
  807. memcpy (&val, *pQ15, 4);
  808. #else
  809. val = ((*pQ15)[1] << 16) | ((*pQ15)[0] & 0x0FFFF);
  810. #endif
  811. *pQ15 -= 2;
  812. return (val);
  813. }
  814. /**
  815. @brief Write 2 Q15 to Q15 pointer and increment pointer afterwards.
  816. @param[in] pQ15 points to input value
  817. @param[in] value Q31 value
  818. @return none
  819. */
  820. __STATIC_FORCEINLINE void write_q15x2_ia (
  821. q15_t ** pQ15,
  822. q31_t value)
  823. {
  824. q31_t val = value;
  825. #ifdef __ARM_FEATURE_UNALIGNED
  826. memcpy (*pQ15, &val, 4);
  827. #else
  828. (*pQ15)[0] = (val & 0x0FFFF);
  829. (*pQ15)[1] = (val >> 16) & 0x0FFFF;
  830. #endif
  831. *pQ15 += 2;
  832. }
  833. /**
  834. @brief Write 2 Q15 to Q15 pointer.
  835. @param[in] pQ15 points to input value
  836. @param[in] value Q31 value
  837. @return none
  838. */
  839. __STATIC_FORCEINLINE void write_q15x2 (
  840. q15_t * pQ15,
  841. q31_t value)
  842. {
  843. q31_t val = value;
  844. #ifdef __ARM_FEATURE_UNALIGNED
  845. memcpy (pQ15, &val, 4);
  846. #else
  847. pQ15[0] = val & 0x0FFFF;
  848. pQ15[1] = val >> 16;
  849. #endif
  850. }
  851. /**
  852. @brief Read 4 Q7 from Q7 pointer and increment pointer afterwards.
  853. @param[in] pQ7 points to input value
  854. @return Q31 value
  855. */
  856. __STATIC_FORCEINLINE q31_t read_q7x4_ia (
  857. q7_t ** pQ7)
  858. {
  859. q31_t val;
  860. #ifdef __ARM_FEATURE_UNALIGNED
  861. memcpy (&val, *pQ7, 4);
  862. #else
  863. val =(((*pQ7)[3] & 0x0FF) << 24) | (((*pQ7)[2] & 0x0FF) << 16) | (((*pQ7)[1] & 0x0FF) << 8) | ((*pQ7)[0] & 0x0FF);
  864. #endif
  865. *pQ7 += 4;
  866. return (val);
  867. }
  868. /**
  869. @brief Read 4 Q7 from Q7 pointer and decrement pointer afterwards.
  870. @param[in] pQ7 points to input value
  871. @return Q31 value
  872. */
  873. __STATIC_FORCEINLINE q31_t read_q7x4_da (
  874. q7_t ** pQ7)
  875. {
  876. q31_t val;
  877. #ifdef __ARM_FEATURE_UNALIGNED
  878. memcpy (&val, *pQ7, 4);
  879. #else
  880. val = ((((*pQ7)[3]) & 0x0FF) << 24) | ((((*pQ7)[2]) & 0x0FF) << 16) | ((((*pQ7)[1]) & 0x0FF) << 8) | ((*pQ7)[0] & 0x0FF);
  881. #endif
  882. *pQ7 -= 4;
  883. return (val);
  884. }
  885. /**
  886. @brief Write 4 Q7 to Q7 pointer and increment pointer afterwards.
  887. @param[in] pQ7 points to input value
  888. @param[in] value Q31 value
  889. @return none
  890. */
  891. __STATIC_FORCEINLINE void write_q7x4_ia (
  892. q7_t ** pQ7,
  893. q31_t value)
  894. {
  895. q31_t val = value;
  896. #ifdef __ARM_FEATURE_UNALIGNED
  897. memcpy (*pQ7, &val, 4);
  898. #else
  899. (*pQ7)[0] = val & 0x0FF;
  900. (*pQ7)[1] = (val >> 8) & 0x0FF;
  901. (*pQ7)[2] = (val >> 16) & 0x0FF;
  902. (*pQ7)[3] = (val >> 24) & 0x0FF;
  903. #endif
  904. *pQ7 += 4;
  905. }
  906. /*
  907. Normally those kind of definitions are in a compiler file
  908. in Core or Core_A.
  909. But for MSVC compiler it is a bit special. The goal is very specific
  910. to CMSIS-DSP and only to allow the use of this library from other
  911. systems like Python or Matlab.
  912. MSVC is not going to be used to cross-compile to ARM. So, having a MSVC
  913. compiler file in Core or Core_A would not make sense.
  914. */
  915. #if defined ( _MSC_VER ) || defined(__GNUC_PYTHON__)
  916. __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t data)
  917. {
  918. if (data == 0U) { return 32U; }
  919. uint32_t count = 0U;
  920. uint32_t mask = 0x80000000U;
  921. while ((data & mask) == 0U)
  922. {
  923. count += 1U;
  924. mask = mask >> 1U;
  925. }
  926. return count;
  927. }
  928. __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
  929. {
  930. if ((sat >= 1U) && (sat <= 32U))
  931. {
  932. const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
  933. const int32_t min = -1 - max ;
  934. if (val > max)
  935. {
  936. return max;
  937. }
  938. else if (val < min)
  939. {
  940. return min;
  941. }
  942. }
  943. return val;
  944. }
  945. __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
  946. {
  947. if (sat <= 31U)
  948. {
  949. const uint32_t max = ((1U << sat) - 1U);
  950. if (val > (int32_t)max)
  951. {
  952. return max;
  953. }
  954. else if (val < 0)
  955. {
  956. return 0U;
  957. }
  958. }
  959. return (uint32_t)val;
  960. }
  961. #endif
  962. #ifndef ARM_MATH_DSP
  963. /**
  964. * @brief definition to pack two 16 bit values.
  965. */
  966. #define __PKHBT(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0x0000FFFF) | \
  967. (((int32_t)(ARG2) << ARG3) & (int32_t)0xFFFF0000) )
  968. #define __PKHTB(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0xFFFF0000) | \
  969. (((int32_t)(ARG2) >> ARG3) & (int32_t)0x0000FFFF) )
  970. #endif
  971. /**
  972. * @brief definition to pack four 8 bit values.
  973. */
  974. #ifndef ARM_MATH_BIG_ENDIAN
  975. #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v0) << 0) & (int32_t)0x000000FF) | \
  976. (((int32_t)(v1) << 8) & (int32_t)0x0000FF00) | \
  977. (((int32_t)(v2) << 16) & (int32_t)0x00FF0000) | \
  978. (((int32_t)(v3) << 24) & (int32_t)0xFF000000) )
  979. #else
  980. #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v3) << 0) & (int32_t)0x000000FF) | \
  981. (((int32_t)(v2) << 8) & (int32_t)0x0000FF00) | \
  982. (((int32_t)(v1) << 16) & (int32_t)0x00FF0000) | \
  983. (((int32_t)(v0) << 24) & (int32_t)0xFF000000) )
  984. #endif
  985. /**
  986. * @brief Clips Q63 to Q31 values.
  987. */
  988. __STATIC_FORCEINLINE q31_t clip_q63_to_q31(
  989. q63_t x)
  990. {
  991. return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ?
  992. ((0x7FFFFFFF ^ ((q31_t) (x >> 63)))) : (q31_t) x;
  993. }
  994. /**
  995. * @brief Clips Q63 to Q15 values.
  996. */
  997. __STATIC_FORCEINLINE q15_t clip_q63_to_q15(
  998. q63_t x)
  999. {
  1000. return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ?
  1001. ((0x7FFF ^ ((q15_t) (x >> 63)))) : (q15_t) (x >> 15);
  1002. }
  1003. /**
  1004. * @brief Clips Q31 to Q7 values.
  1005. */
  1006. __STATIC_FORCEINLINE q7_t clip_q31_to_q7(
  1007. q31_t x)
  1008. {
  1009. return ((q31_t) (x >> 24) != ((q31_t) x >> 23)) ?
  1010. ((0x7F ^ ((q7_t) (x >> 31)))) : (q7_t) x;
  1011. }
  1012. /**
  1013. * @brief Clips Q31 to Q15 values.
  1014. */
  1015. __STATIC_FORCEINLINE q15_t clip_q31_to_q15(
  1016. q31_t x)
  1017. {
  1018. return ((q31_t) (x >> 16) != ((q31_t) x >> 15)) ?
  1019. ((0x7FFF ^ ((q15_t) (x >> 31)))) : (q15_t) x;
  1020. }
  1021. /**
  1022. * @brief Multiplies 32 X 64 and returns 32 bit result in 2.30 format.
  1023. */
  1024. __STATIC_FORCEINLINE q63_t mult32x64(
  1025. q63_t x,
  1026. q31_t y)
  1027. {
  1028. return ((((q63_t) (x & 0x00000000FFFFFFFF) * y) >> 32) +
  1029. (((q63_t) (x >> 32) * y) ) );
  1030. }
  1031. /**
  1032. * @brief Function to Calculates 1/in (reciprocal) value of Q31 Data type.
  1033. */
  1034. __STATIC_FORCEINLINE uint32_t arm_recip_q31(
  1035. q31_t in,
  1036. q31_t * dst,
  1037. const q31_t * pRecipTable)
  1038. {
  1039. q31_t out;
  1040. uint32_t tempVal;
  1041. uint32_t index, i;
  1042. uint32_t signBits;
  1043. if (in > 0)
  1044. {
  1045. signBits = ((uint32_t) (__CLZ( in) - 1));
  1046. }
  1047. else
  1048. {
  1049. signBits = ((uint32_t) (__CLZ(-in) - 1));
  1050. }
  1051. /* Convert input sample to 1.31 format */
  1052. in = (in << signBits);
  1053. /* calculation of index for initial approximated Val */
  1054. index = (uint32_t)(in >> 24);
  1055. index = (index & INDEX_MASK);
  1056. /* 1.31 with exp 1 */
  1057. out = pRecipTable[index];
  1058. /* calculation of reciprocal value */
  1059. /* running approximation for two iterations */
  1060. for (i = 0U; i < 2U; i++)
  1061. {
  1062. tempVal = (uint32_t) (((q63_t) in * out) >> 31);
  1063. tempVal = 0x7FFFFFFFu - tempVal;
  1064. /* 1.31 with exp 1 */
  1065. /* out = (q31_t) (((q63_t) out * tempVal) >> 30); */
  1066. out = clip_q63_to_q31(((q63_t) out * tempVal) >> 30);
  1067. }
  1068. /* write output */
  1069. *dst = out;
  1070. /* return num of signbits of out = 1/in value */
  1071. return (signBits + 1U);
  1072. }
  1073. /**
  1074. * @brief Function to Calculates 1/in (reciprocal) value of Q15 Data type.
  1075. */
  1076. __STATIC_FORCEINLINE uint32_t arm_recip_q15(
  1077. q15_t in,
  1078. q15_t * dst,
  1079. const q15_t * pRecipTable)
  1080. {
  1081. q15_t out = 0;
  1082. uint32_t tempVal = 0;
  1083. uint32_t index = 0, i = 0;
  1084. uint32_t signBits = 0;
  1085. if (in > 0)
  1086. {
  1087. signBits = ((uint32_t)(__CLZ( in) - 17));
  1088. }
  1089. else
  1090. {
  1091. signBits = ((uint32_t)(__CLZ(-in) - 17));
  1092. }
  1093. /* Convert input sample to 1.15 format */
  1094. in = (in << signBits);
  1095. /* calculation of index for initial approximated Val */
  1096. index = (uint32_t)(in >> 8);
  1097. index = (index & INDEX_MASK);
  1098. /* 1.15 with exp 1 */
  1099. out = pRecipTable[index];
  1100. /* calculation of reciprocal value */
  1101. /* running approximation for two iterations */
  1102. for (i = 0U; i < 2U; i++)
  1103. {
  1104. tempVal = (uint32_t) (((q31_t) in * out) >> 15);
  1105. tempVal = 0x7FFFu - tempVal;
  1106. /* 1.15 with exp 1 */
  1107. out = (q15_t) (((q31_t) out * tempVal) >> 14);
  1108. /* out = clip_q31_to_q15(((q31_t) out * tempVal) >> 14); */
  1109. }
  1110. /* write output */
  1111. *dst = out;
  1112. /* return num of signbits of out = 1/in value */
  1113. return (signBits + 1);
  1114. }
  1115. /**
  1116. * @brief Integer exponentiation
  1117. * @param[in] x value
  1118. * @param[in] nb integer exponent >= 1
  1119. * @return x^nb
  1120. *
  1121. */
  1122. __STATIC_INLINE float32_t arm_exponent_f32(float32_t x, int32_t nb)
  1123. {
  1124. float32_t r = x;
  1125. nb --;
  1126. while(nb > 0)
  1127. {
  1128. r = r * x;
  1129. nb--;
  1130. }
  1131. return(r);
  1132. }
  1133. /**
  1134. * @brief 64-bit to 32-bit unsigned normalization
  1135. * @param[in] in is input unsigned long long value
  1136. * @param[out] normalized is the 32-bit normalized value
  1137. * @param[out] norm is norm scale
  1138. */
  1139. __STATIC_INLINE void arm_norm_64_to_32u(uint64_t in, int32_t * normalized, int32_t *norm)
  1140. {
  1141. int32_t n1;
  1142. int32_t hi = (int32_t) (in >> 32);
  1143. int32_t lo = (int32_t) ((in << 32) >> 32);
  1144. n1 = __CLZ(hi) - 32;
  1145. if (!n1)
  1146. {
  1147. /*
  1148. * input fits in 32-bit
  1149. */
  1150. n1 = __CLZ(lo);
  1151. if (!n1)
  1152. {
  1153. /*
  1154. * MSB set, need to scale down by 1
  1155. */
  1156. *norm = -1;
  1157. *normalized = (((uint32_t) lo) >> 1);
  1158. } else
  1159. {
  1160. if (n1 == 32)
  1161. {
  1162. /*
  1163. * input is zero
  1164. */
  1165. *norm = 0;
  1166. *normalized = 0;
  1167. } else
  1168. {
  1169. /*
  1170. * 32-bit normalization
  1171. */
  1172. *norm = n1 - 1;
  1173. *normalized = lo << *norm;
  1174. }
  1175. }
  1176. } else
  1177. {
  1178. /*
  1179. * input fits in 64-bit
  1180. */
  1181. n1 = 1 - n1;
  1182. *norm = -n1;
  1183. /*
  1184. * 64 bit normalization
  1185. */
  1186. *normalized = (((uint32_t) lo) >> n1) | (hi << (32 - n1));
  1187. }
  1188. }
  1189. __STATIC_INLINE q31_t arm_div_q63_to_q31(q63_t num, q31_t den)
  1190. {
  1191. q31_t result;
  1192. uint64_t absNum;
  1193. int32_t normalized;
  1194. int32_t norm;
  1195. /*
  1196. * if sum fits in 32bits
  1197. * avoid costly 64-bit division
  1198. */
  1199. absNum = num > 0 ? num : -num;
  1200. arm_norm_64_to_32u(absNum, &normalized, &norm);
  1201. if (norm > 0)
  1202. /*
  1203. * 32-bit division
  1204. */
  1205. result = (q31_t) num / den;
  1206. else
  1207. /*
  1208. * 64-bit division
  1209. */
  1210. result = (q31_t) (num / den);
  1211. return result;
  1212. }
  1213. /*
  1214. * @brief C custom defined intrinsic functions
  1215. */
  1216. #if !defined (ARM_MATH_DSP)
  1217. /*
  1218. * @brief C custom defined QADD8
  1219. */
  1220. __STATIC_FORCEINLINE uint32_t __QADD8(
  1221. uint32_t x,
  1222. uint32_t y)
  1223. {
  1224. q31_t r, s, t, u;
  1225. r = __SSAT(((((q31_t)x << 24) >> 24) + (((q31_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
  1226. s = __SSAT(((((q31_t)x << 16) >> 24) + (((q31_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
  1227. t = __SSAT(((((q31_t)x << 8) >> 24) + (((q31_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
  1228. u = __SSAT(((((q31_t)x ) >> 24) + (((q31_t)y ) >> 24)), 8) & (int32_t)0x000000FF;
  1229. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r )));
  1230. }
  1231. /*
  1232. * @brief C custom defined QSUB8
  1233. */
  1234. __STATIC_FORCEINLINE uint32_t __QSUB8(
  1235. uint32_t x,
  1236. uint32_t y)
  1237. {
  1238. q31_t r, s, t, u;
  1239. r = __SSAT(((((q31_t)x << 24) >> 24) - (((q31_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
  1240. s = __SSAT(((((q31_t)x << 16) >> 24) - (((q31_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
  1241. t = __SSAT(((((q31_t)x << 8) >> 24) - (((q31_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
  1242. u = __SSAT(((((q31_t)x ) >> 24) - (((q31_t)y ) >> 24)), 8) & (int32_t)0x000000FF;
  1243. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r )));
  1244. }
  1245. /*
  1246. * @brief C custom defined QADD16
  1247. */
  1248. __STATIC_FORCEINLINE uint32_t __QADD16(
  1249. uint32_t x,
  1250. uint32_t y)
  1251. {
  1252. /* q31_t r, s; without initialisation 'arm_offset_q15 test' fails but 'intrinsic' tests pass! for armCC */
  1253. q31_t r = 0, s = 0;
  1254. r = __SSAT(((((q31_t)x << 16) >> 16) + (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1255. s = __SSAT(((((q31_t)x ) >> 16) + (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1256. return ((uint32_t)((s << 16) | (r )));
  1257. }
  1258. /*
  1259. * @brief C custom defined SHADD16
  1260. */
  1261. __STATIC_FORCEINLINE uint32_t __SHADD16(
  1262. uint32_t x,
  1263. uint32_t y)
  1264. {
  1265. q31_t r, s;
  1266. r = (((((q31_t)x << 16) >> 16) + (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1267. s = (((((q31_t)x ) >> 16) + (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1268. return ((uint32_t)((s << 16) | (r )));
  1269. }
  1270. /*
  1271. * @brief C custom defined QSUB16
  1272. */
  1273. __STATIC_FORCEINLINE uint32_t __QSUB16(
  1274. uint32_t x,
  1275. uint32_t y)
  1276. {
  1277. q31_t r, s;
  1278. r = __SSAT(((((q31_t)x << 16) >> 16) - (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1279. s = __SSAT(((((q31_t)x ) >> 16) - (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1280. return ((uint32_t)((s << 16) | (r )));
  1281. }
  1282. /*
  1283. * @brief C custom defined SHSUB16
  1284. */
  1285. __STATIC_FORCEINLINE uint32_t __SHSUB16(
  1286. uint32_t x,
  1287. uint32_t y)
  1288. {
  1289. q31_t r, s;
  1290. r = (((((q31_t)x << 16) >> 16) - (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1291. s = (((((q31_t)x ) >> 16) - (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1292. return ((uint32_t)((s << 16) | (r )));
  1293. }
  1294. /*
  1295. * @brief C custom defined QASX
  1296. */
  1297. __STATIC_FORCEINLINE uint32_t __QASX(
  1298. uint32_t x,
  1299. uint32_t y)
  1300. {
  1301. q31_t r, s;
  1302. r = __SSAT(((((q31_t)x << 16) >> 16) - (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1303. s = __SSAT(((((q31_t)x ) >> 16) + (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1304. return ((uint32_t)((s << 16) | (r )));
  1305. }
  1306. /*
  1307. * @brief C custom defined SHASX
  1308. */
  1309. __STATIC_FORCEINLINE uint32_t __SHASX(
  1310. uint32_t x,
  1311. uint32_t y)
  1312. {
  1313. q31_t r, s;
  1314. r = (((((q31_t)x << 16) >> 16) - (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1315. s = (((((q31_t)x ) >> 16) + (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1316. return ((uint32_t)((s << 16) | (r )));
  1317. }
  1318. /*
  1319. * @brief C custom defined QSAX
  1320. */
  1321. __STATIC_FORCEINLINE uint32_t __QSAX(
  1322. uint32_t x,
  1323. uint32_t y)
  1324. {
  1325. q31_t r, s;
  1326. r = __SSAT(((((q31_t)x << 16) >> 16) + (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1327. s = __SSAT(((((q31_t)x ) >> 16) - (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1328. return ((uint32_t)((s << 16) | (r )));
  1329. }
  1330. /*
  1331. * @brief C custom defined SHSAX
  1332. */
  1333. __STATIC_FORCEINLINE uint32_t __SHSAX(
  1334. uint32_t x,
  1335. uint32_t y)
  1336. {
  1337. q31_t r, s;
  1338. r = (((((q31_t)x << 16) >> 16) + (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1339. s = (((((q31_t)x ) >> 16) - (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1340. return ((uint32_t)((s << 16) | (r )));
  1341. }
  1342. /*
  1343. * @brief C custom defined SMUSDX
  1344. */
  1345. __STATIC_FORCEINLINE uint32_t __SMUSDX(
  1346. uint32_t x,
  1347. uint32_t y)
  1348. {
  1349. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) -
  1350. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) ));
  1351. }
  1352. /*
  1353. * @brief C custom defined SMUADX
  1354. */
  1355. __STATIC_FORCEINLINE uint32_t __SMUADX(
  1356. uint32_t x,
  1357. uint32_t y)
  1358. {
  1359. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) +
  1360. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) ));
  1361. }
  1362. /*
  1363. * @brief C custom defined QADD
  1364. */
  1365. __STATIC_FORCEINLINE int32_t __QADD(
  1366. int32_t x,
  1367. int32_t y)
  1368. {
  1369. return ((int32_t)(clip_q63_to_q31((q63_t)x + (q31_t)y)));
  1370. }
  1371. /*
  1372. * @brief C custom defined QSUB
  1373. */
  1374. __STATIC_FORCEINLINE int32_t __QSUB(
  1375. int32_t x,
  1376. int32_t y)
  1377. {
  1378. return ((int32_t)(clip_q63_to_q31((q63_t)x - (q31_t)y)));
  1379. }
  1380. /*
  1381. * @brief C custom defined SMLAD
  1382. */
  1383. __STATIC_FORCEINLINE uint32_t __SMLAD(
  1384. uint32_t x,
  1385. uint32_t y,
  1386. uint32_t sum)
  1387. {
  1388. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) +
  1389. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) +
  1390. ( ((q31_t)sum ) ) ));
  1391. }
  1392. /*
  1393. * @brief C custom defined SMLADX
  1394. */
  1395. __STATIC_FORCEINLINE uint32_t __SMLADX(
  1396. uint32_t x,
  1397. uint32_t y,
  1398. uint32_t sum)
  1399. {
  1400. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) +
  1401. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) +
  1402. ( ((q31_t)sum ) ) ));
  1403. }
  1404. /*
  1405. * @brief C custom defined SMLSDX
  1406. */
  1407. __STATIC_FORCEINLINE uint32_t __SMLSDX(
  1408. uint32_t x,
  1409. uint32_t y,
  1410. uint32_t sum)
  1411. {
  1412. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) -
  1413. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) +
  1414. ( ((q31_t)sum ) ) ));
  1415. }
  1416. /*
  1417. * @brief C custom defined SMLALD
  1418. */
  1419. __STATIC_FORCEINLINE uint64_t __SMLALD(
  1420. uint32_t x,
  1421. uint32_t y,
  1422. uint64_t sum)
  1423. {
  1424. /* return (sum + ((q15_t) (x >> 16) * (q15_t) (y >> 16)) + ((q15_t) x * (q15_t) y)); */
  1425. return ((uint64_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) +
  1426. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) +
  1427. ( ((q63_t)sum ) ) ));
  1428. }
  1429. /*
  1430. * @brief C custom defined SMLALDX
  1431. */
  1432. __STATIC_FORCEINLINE uint64_t __SMLALDX(
  1433. uint32_t x,
  1434. uint32_t y,
  1435. uint64_t sum)
  1436. {
  1437. /* return (sum + ((q15_t) (x >> 16) * (q15_t) y)) + ((q15_t) x * (q15_t) (y >> 16)); */
  1438. return ((uint64_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) +
  1439. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) +
  1440. ( ((q63_t)sum ) ) ));
  1441. }
  1442. /*
  1443. * @brief C custom defined SMUAD
  1444. */
  1445. __STATIC_FORCEINLINE uint32_t __SMUAD(
  1446. uint32_t x,
  1447. uint32_t y)
  1448. {
  1449. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) +
  1450. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) ));
  1451. }
  1452. /*
  1453. * @brief C custom defined SMUSD
  1454. */
  1455. __STATIC_FORCEINLINE uint32_t __SMUSD(
  1456. uint32_t x,
  1457. uint32_t y)
  1458. {
  1459. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) -
  1460. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) ));
  1461. }
  1462. /*
  1463. * @brief C custom defined SXTB16
  1464. */
  1465. __STATIC_FORCEINLINE uint32_t __SXTB16(
  1466. uint32_t x)
  1467. {
  1468. return ((uint32_t)(((((q31_t)x << 24) >> 24) & (q31_t)0x0000FFFF) |
  1469. ((((q31_t)x << 8) >> 8) & (q31_t)0xFFFF0000) ));
  1470. }
  1471. /*
  1472. * @brief C custom defined SMMLA
  1473. */
  1474. __STATIC_FORCEINLINE int32_t __SMMLA(
  1475. int32_t x,
  1476. int32_t y,
  1477. int32_t sum)
  1478. {
  1479. return (sum + (int32_t) (((int64_t) x * y) >> 32));
  1480. }
  1481. #endif /* !defined (ARM_MATH_DSP) */
  1482. /**
  1483. * @brief Instance structure for the Q7 FIR filter.
  1484. */
  1485. typedef struct
  1486. {
  1487. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1488. q7_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1489. const q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  1490. } arm_fir_instance_q7;
  1491. /**
  1492. * @brief Instance structure for the Q15 FIR filter.
  1493. */
  1494. typedef struct
  1495. {
  1496. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1497. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1498. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  1499. } arm_fir_instance_q15;
  1500. /**
  1501. * @brief Instance structure for the Q31 FIR filter.
  1502. */
  1503. typedef struct
  1504. {
  1505. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1506. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1507. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  1508. } arm_fir_instance_q31;
  1509. /**
  1510. * @brief Instance structure for the floating-point FIR filter.
  1511. */
  1512. typedef struct
  1513. {
  1514. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1515. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1516. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  1517. } arm_fir_instance_f32;
  1518. /**
  1519. * @brief Processing function for the Q7 FIR filter.
  1520. * @param[in] S points to an instance of the Q7 FIR filter structure.
  1521. * @param[in] pSrc points to the block of input data.
  1522. * @param[out] pDst points to the block of output data.
  1523. * @param[in] blockSize number of samples to process.
  1524. */
  1525. void arm_fir_q7(
  1526. const arm_fir_instance_q7 * S,
  1527. const q7_t * pSrc,
  1528. q7_t * pDst,
  1529. uint32_t blockSize);
  1530. /**
  1531. * @brief Initialization function for the Q7 FIR filter.
  1532. * @param[in,out] S points to an instance of the Q7 FIR structure.
  1533. * @param[in] numTaps Number of filter coefficients in the filter.
  1534. * @param[in] pCoeffs points to the filter coefficients.
  1535. * @param[in] pState points to the state buffer.
  1536. * @param[in] blockSize number of samples that are processed.
  1537. */
  1538. void arm_fir_init_q7(
  1539. arm_fir_instance_q7 * S,
  1540. uint16_t numTaps,
  1541. const q7_t * pCoeffs,
  1542. q7_t * pState,
  1543. uint32_t blockSize);
  1544. /**
  1545. * @brief Processing function for the Q15 FIR filter.
  1546. * @param[in] S points to an instance of the Q15 FIR structure.
  1547. * @param[in] pSrc points to the block of input data.
  1548. * @param[out] pDst points to the block of output data.
  1549. * @param[in] blockSize number of samples to process.
  1550. */
  1551. void arm_fir_q15(
  1552. const arm_fir_instance_q15 * S,
  1553. const q15_t * pSrc,
  1554. q15_t * pDst,
  1555. uint32_t blockSize);
  1556. /**
  1557. * @brief Processing function for the fast Q15 FIR filter (fast version).
  1558. * @param[in] S points to an instance of the Q15 FIR filter structure.
  1559. * @param[in] pSrc points to the block of input data.
  1560. * @param[out] pDst points to the block of output data.
  1561. * @param[in] blockSize number of samples to process.
  1562. */
  1563. void arm_fir_fast_q15(
  1564. const arm_fir_instance_q15 * S,
  1565. const q15_t * pSrc,
  1566. q15_t * pDst,
  1567. uint32_t blockSize);
  1568. /**
  1569. * @brief Initialization function for the Q15 FIR filter.
  1570. * @param[in,out] S points to an instance of the Q15 FIR filter structure.
  1571. * @param[in] numTaps Number of filter coefficients in the filter. Must be even and greater than or equal to 4.
  1572. * @param[in] pCoeffs points to the filter coefficients.
  1573. * @param[in] pState points to the state buffer.
  1574. * @param[in] blockSize number of samples that are processed at a time.
  1575. * @return The function returns either
  1576. * <code>ARM_MATH_SUCCESS</code> if initialization was successful or
  1577. * <code>ARM_MATH_ARGUMENT_ERROR</code> if <code>numTaps</code> is not a supported value.
  1578. */
  1579. arm_status arm_fir_init_q15(
  1580. arm_fir_instance_q15 * S,
  1581. uint16_t numTaps,
  1582. const q15_t * pCoeffs,
  1583. q15_t * pState,
  1584. uint32_t blockSize);
  1585. /**
  1586. * @brief Processing function for the Q31 FIR filter.
  1587. * @param[in] S points to an instance of the Q31 FIR filter structure.
  1588. * @param[in] pSrc points to the block of input data.
  1589. * @param[out] pDst points to the block of output data.
  1590. * @param[in] blockSize number of samples to process.
  1591. */
  1592. void arm_fir_q31(
  1593. const arm_fir_instance_q31 * S,
  1594. const q31_t * pSrc,
  1595. q31_t * pDst,
  1596. uint32_t blockSize);
  1597. /**
  1598. * @brief Processing function for the fast Q31 FIR filter (fast version).
  1599. * @param[in] S points to an instance of the Q31 FIR filter structure.
  1600. * @param[in] pSrc points to the block of input data.
  1601. * @param[out] pDst points to the block of output data.
  1602. * @param[in] blockSize number of samples to process.
  1603. */
  1604. void arm_fir_fast_q31(
  1605. const arm_fir_instance_q31 * S,
  1606. const q31_t * pSrc,
  1607. q31_t * pDst,
  1608. uint32_t blockSize);
  1609. /**
  1610. * @brief Initialization function for the Q31 FIR filter.
  1611. * @param[in,out] S points to an instance of the Q31 FIR structure.
  1612. * @param[in] numTaps Number of filter coefficients in the filter.
  1613. * @param[in] pCoeffs points to the filter coefficients.
  1614. * @param[in] pState points to the state buffer.
  1615. * @param[in] blockSize number of samples that are processed at a time.
  1616. */
  1617. void arm_fir_init_q31(
  1618. arm_fir_instance_q31 * S,
  1619. uint16_t numTaps,
  1620. const q31_t * pCoeffs,
  1621. q31_t * pState,
  1622. uint32_t blockSize);
  1623. /**
  1624. * @brief Processing function for the floating-point FIR filter.
  1625. * @param[in] S points to an instance of the floating-point FIR structure.
  1626. * @param[in] pSrc points to the block of input data.
  1627. * @param[out] pDst points to the block of output data.
  1628. * @param[in] blockSize number of samples to process.
  1629. */
  1630. void arm_fir_f32(
  1631. const arm_fir_instance_f32 * S,
  1632. const float32_t * pSrc,
  1633. float32_t * pDst,
  1634. uint32_t blockSize);
  1635. /**
  1636. * @brief Initialization function for the floating-point FIR filter.
  1637. * @param[in,out] S points to an instance of the floating-point FIR filter structure.
  1638. * @param[in] numTaps Number of filter coefficients in the filter.
  1639. * @param[in] pCoeffs points to the filter coefficients.
  1640. * @param[in] pState points to the state buffer.
  1641. * @param[in] blockSize number of samples that are processed at a time.
  1642. */
  1643. void arm_fir_init_f32(
  1644. arm_fir_instance_f32 * S,
  1645. uint16_t numTaps,
  1646. const float32_t * pCoeffs,
  1647. float32_t * pState,
  1648. uint32_t blockSize);
  1649. /**
  1650. * @brief Instance structure for the Q15 Biquad cascade filter.
  1651. */
  1652. typedef struct
  1653. {
  1654. int8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  1655. q15_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */
  1656. const q15_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */
  1657. int8_t postShift; /**< Additional shift, in bits, applied to each output sample. */
  1658. } arm_biquad_casd_df1_inst_q15;
  1659. /**
  1660. * @brief Instance structure for the Q31 Biquad cascade filter.
  1661. */
  1662. typedef struct
  1663. {
  1664. uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  1665. q31_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */
  1666. const q31_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */
  1667. uint8_t postShift; /**< Additional shift, in bits, applied to each output sample. */
  1668. } arm_biquad_casd_df1_inst_q31;
  1669. /**
  1670. * @brief Instance structure for the floating-point Biquad cascade filter.
  1671. */
  1672. typedef struct
  1673. {
  1674. uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  1675. float32_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */
  1676. const float32_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */
  1677. } arm_biquad_casd_df1_inst_f32;
  1678. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  1679. /**
  1680. * @brief Instance structure for the modified Biquad coefs required by vectorized code.
  1681. */
  1682. typedef struct
  1683. {
  1684. float32_t coeffs[8][4]; /**< Points to the array of modified coefficients. The array is of length 32. There is one per stage */
  1685. } arm_biquad_mod_coef_f32;
  1686. #endif
  1687. /**
  1688. * @brief Processing function for the Q15 Biquad cascade filter.
  1689. * @param[in] S points to an instance of the Q15 Biquad cascade structure.
  1690. * @param[in] pSrc points to the block of input data.
  1691. * @param[out] pDst points to the block of output data.
  1692. * @param[in] blockSize number of samples to process.
  1693. */
  1694. void arm_biquad_cascade_df1_q15(
  1695. const arm_biquad_casd_df1_inst_q15 * S,
  1696. const q15_t * pSrc,
  1697. q15_t * pDst,
  1698. uint32_t blockSize);
  1699. /**
  1700. * @brief Initialization function for the Q15 Biquad cascade filter.
  1701. * @param[in,out] S points to an instance of the Q15 Biquad cascade structure.
  1702. * @param[in] numStages number of 2nd order stages in the filter.
  1703. * @param[in] pCoeffs points to the filter coefficients.
  1704. * @param[in] pState points to the state buffer.
  1705. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format
  1706. */
  1707. void arm_biquad_cascade_df1_init_q15(
  1708. arm_biquad_casd_df1_inst_q15 * S,
  1709. uint8_t numStages,
  1710. const q15_t * pCoeffs,
  1711. q15_t * pState,
  1712. int8_t postShift);
  1713. /**
  1714. * @brief Fast but less precise processing function for the Q15 Biquad cascade filter for Cortex-M3 and Cortex-M4.
  1715. * @param[in] S points to an instance of the Q15 Biquad cascade structure.
  1716. * @param[in] pSrc points to the block of input data.
  1717. * @param[out] pDst points to the block of output data.
  1718. * @param[in] blockSize number of samples to process.
  1719. */
  1720. void arm_biquad_cascade_df1_fast_q15(
  1721. const arm_biquad_casd_df1_inst_q15 * S,
  1722. const q15_t * pSrc,
  1723. q15_t * pDst,
  1724. uint32_t blockSize);
  1725. /**
  1726. * @brief Processing function for the Q31 Biquad cascade filter
  1727. * @param[in] S points to an instance of the Q31 Biquad cascade structure.
  1728. * @param[in] pSrc points to the block of input data.
  1729. * @param[out] pDst points to the block of output data.
  1730. * @param[in] blockSize number of samples to process.
  1731. */
  1732. void arm_biquad_cascade_df1_q31(
  1733. const arm_biquad_casd_df1_inst_q31 * S,
  1734. const q31_t * pSrc,
  1735. q31_t * pDst,
  1736. uint32_t blockSize);
  1737. /**
  1738. * @brief Fast but less precise processing function for the Q31 Biquad cascade filter for Cortex-M3 and Cortex-M4.
  1739. * @param[in] S points to an instance of the Q31 Biquad cascade structure.
  1740. * @param[in] pSrc points to the block of input data.
  1741. * @param[out] pDst points to the block of output data.
  1742. * @param[in] blockSize number of samples to process.
  1743. */
  1744. void arm_biquad_cascade_df1_fast_q31(
  1745. const arm_biquad_casd_df1_inst_q31 * S,
  1746. const q31_t * pSrc,
  1747. q31_t * pDst,
  1748. uint32_t blockSize);
  1749. /**
  1750. * @brief Initialization function for the Q31 Biquad cascade filter.
  1751. * @param[in,out] S points to an instance of the Q31 Biquad cascade structure.
  1752. * @param[in] numStages number of 2nd order stages in the filter.
  1753. * @param[in] pCoeffs points to the filter coefficients.
  1754. * @param[in] pState points to the state buffer.
  1755. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format
  1756. */
  1757. void arm_biquad_cascade_df1_init_q31(
  1758. arm_biquad_casd_df1_inst_q31 * S,
  1759. uint8_t numStages,
  1760. const q31_t * pCoeffs,
  1761. q31_t * pState,
  1762. int8_t postShift);
  1763. /**
  1764. * @brief Processing function for the floating-point Biquad cascade filter.
  1765. * @param[in] S points to an instance of the floating-point Biquad cascade structure.
  1766. * @param[in] pSrc points to the block of input data.
  1767. * @param[out] pDst points to the block of output data.
  1768. * @param[in] blockSize number of samples to process.
  1769. */
  1770. void arm_biquad_cascade_df1_f32(
  1771. const arm_biquad_casd_df1_inst_f32 * S,
  1772. const float32_t * pSrc,
  1773. float32_t * pDst,
  1774. uint32_t blockSize);
  1775. /**
  1776. * @brief Initialization function for the floating-point Biquad cascade filter.
  1777. * @param[in,out] S points to an instance of the floating-point Biquad cascade structure.
  1778. * @param[in] numStages number of 2nd order stages in the filter.
  1779. * @param[in] pCoeffs points to the filter coefficients.
  1780. * @param[in] pCoeffsMod points to the modified filter coefficients (only MVE version).
  1781. * @param[in] pState points to the state buffer.
  1782. */
  1783. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  1784. void arm_biquad_cascade_df1_mve_init_f32(
  1785. arm_biquad_casd_df1_inst_f32 * S,
  1786. uint8_t numStages,
  1787. const float32_t * pCoeffs,
  1788. arm_biquad_mod_coef_f32 * pCoeffsMod,
  1789. float32_t * pState);
  1790. #endif
  1791. void arm_biquad_cascade_df1_init_f32(
  1792. arm_biquad_casd_df1_inst_f32 * S,
  1793. uint8_t numStages,
  1794. const float32_t * pCoeffs,
  1795. float32_t * pState);
  1796. /**
  1797. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  1798. * @param[in] pSrcA points to input vector A
  1799. * @param[in] pSrcB points to input vector B
  1800. * @param[out] pDst points to output vector
  1801. * @param[in] blockSize number of samples in each vector
  1802. * @return none
  1803. */
  1804. void arm_and_u16(
  1805. const uint16_t * pSrcA,
  1806. const uint16_t * pSrcB,
  1807. uint16_t * pDst,
  1808. uint32_t blockSize);
  1809. /**
  1810. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  1811. * @param[in] pSrcA points to input vector A
  1812. * @param[in] pSrcB points to input vector B
  1813. * @param[out] pDst points to output vector
  1814. * @param[in] blockSize number of samples in each vector
  1815. * @return none
  1816. */
  1817. void arm_and_u32(
  1818. const uint32_t * pSrcA,
  1819. const uint32_t * pSrcB,
  1820. uint32_t * pDst,
  1821. uint32_t blockSize);
  1822. /**
  1823. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  1824. * @param[in] pSrcA points to input vector A
  1825. * @param[in] pSrcB points to input vector B
  1826. * @param[out] pDst points to output vector
  1827. * @param[in] blockSize number of samples in each vector
  1828. * @return none
  1829. */
  1830. void arm_and_u8(
  1831. const uint8_t * pSrcA,
  1832. const uint8_t * pSrcB,
  1833. uint8_t * pDst,
  1834. uint32_t blockSize);
  1835. /**
  1836. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  1837. * @param[in] pSrcA points to input vector A
  1838. * @param[in] pSrcB points to input vector B
  1839. * @param[out] pDst points to output vector
  1840. * @param[in] blockSize number of samples in each vector
  1841. * @return none
  1842. */
  1843. void arm_or_u16(
  1844. const uint16_t * pSrcA,
  1845. const uint16_t * pSrcB,
  1846. uint16_t * pDst,
  1847. uint32_t blockSize);
  1848. /**
  1849. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  1850. * @param[in] pSrcA points to input vector A
  1851. * @param[in] pSrcB points to input vector B
  1852. * @param[out] pDst points to output vector
  1853. * @param[in] blockSize number of samples in each vector
  1854. * @return none
  1855. */
  1856. void arm_or_u32(
  1857. const uint32_t * pSrcA,
  1858. const uint32_t * pSrcB,
  1859. uint32_t * pDst,
  1860. uint32_t blockSize);
  1861. /**
  1862. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  1863. * @param[in] pSrcA points to input vector A
  1864. * @param[in] pSrcB points to input vector B
  1865. * @param[out] pDst points to output vector
  1866. * @param[in] blockSize number of samples in each vector
  1867. * @return none
  1868. */
  1869. void arm_or_u8(
  1870. const uint8_t * pSrcA,
  1871. const uint8_t * pSrcB,
  1872. uint8_t * pDst,
  1873. uint32_t blockSize);
  1874. /**
  1875. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  1876. * @param[in] pSrc points to input vector
  1877. * @param[out] pDst points to output vector
  1878. * @param[in] blockSize number of samples in each vector
  1879. * @return none
  1880. */
  1881. void arm_not_u16(
  1882. const uint16_t * pSrc,
  1883. uint16_t * pDst,
  1884. uint32_t blockSize);
  1885. /**
  1886. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  1887. * @param[in] pSrc points to input vector
  1888. * @param[out] pDst points to output vector
  1889. * @param[in] blockSize number of samples in each vector
  1890. * @return none
  1891. */
  1892. void arm_not_u32(
  1893. const uint32_t * pSrc,
  1894. uint32_t * pDst,
  1895. uint32_t blockSize);
  1896. /**
  1897. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  1898. * @param[in] pSrc points to input vector
  1899. * @param[out] pDst points to output vector
  1900. * @param[in] blockSize number of samples in each vector
  1901. * @return none
  1902. */
  1903. void arm_not_u8(
  1904. const uint8_t * pSrc,
  1905. uint8_t * pDst,
  1906. uint32_t blockSize);
  1907. /**
  1908. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  1909. * @param[in] pSrcA points to input vector A
  1910. * @param[in] pSrcB points to input vector B
  1911. * @param[out] pDst points to output vector
  1912. * @param[in] blockSize number of samples in each vector
  1913. * @return none
  1914. */
  1915. void arm_xor_u16(
  1916. const uint16_t * pSrcA,
  1917. const uint16_t * pSrcB,
  1918. uint16_t * pDst,
  1919. uint32_t blockSize);
  1920. /**
  1921. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  1922. * @param[in] pSrcA points to input vector A
  1923. * @param[in] pSrcB points to input vector B
  1924. * @param[out] pDst points to output vector
  1925. * @param[in] blockSize number of samples in each vector
  1926. * @return none
  1927. */
  1928. void arm_xor_u32(
  1929. const uint32_t * pSrcA,
  1930. const uint32_t * pSrcB,
  1931. uint32_t * pDst,
  1932. uint32_t blockSize);
  1933. /**
  1934. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  1935. * @param[in] pSrcA points to input vector A
  1936. * @param[in] pSrcB points to input vector B
  1937. * @param[out] pDst points to output vector
  1938. * @param[in] blockSize number of samples in each vector
  1939. * @return none
  1940. */
  1941. void arm_xor_u8(
  1942. const uint8_t * pSrcA,
  1943. const uint8_t * pSrcB,
  1944. uint8_t * pDst,
  1945. uint32_t blockSize);
  1946. /**
  1947. * @brief Struct for specifying sorting algorithm
  1948. */
  1949. typedef enum
  1950. {
  1951. ARM_SORT_BITONIC = 0,
  1952. /**< Bitonic sort */
  1953. ARM_SORT_BUBBLE = 1,
  1954. /**< Bubble sort */
  1955. ARM_SORT_HEAP = 2,
  1956. /**< Heap sort */
  1957. ARM_SORT_INSERTION = 3,
  1958. /**< Insertion sort */
  1959. ARM_SORT_QUICK = 4,
  1960. /**< Quick sort */
  1961. ARM_SORT_SELECTION = 5
  1962. /**< Selection sort */
  1963. } arm_sort_alg;
  1964. /**
  1965. * @brief Struct for specifying sorting algorithm
  1966. */
  1967. typedef enum
  1968. {
  1969. ARM_SORT_DESCENDING = 0,
  1970. /**< Descending order (9 to 0) */
  1971. ARM_SORT_ASCENDING = 1
  1972. /**< Ascending order (0 to 9) */
  1973. } arm_sort_dir;
  1974. /**
  1975. * @brief Instance structure for the sorting algorithms.
  1976. */
  1977. typedef struct
  1978. {
  1979. arm_sort_alg alg; /**< Sorting algorithm selected */
  1980. arm_sort_dir dir; /**< Sorting order (direction) */
  1981. } arm_sort_instance_f32;
  1982. /**
  1983. * @param[in] S points to an instance of the sorting structure.
  1984. * @param[in] pSrc points to the block of input data.
  1985. * @param[out] pDst points to the block of output data.
  1986. * @param[in] blockSize number of samples to process.
  1987. */
  1988. void arm_sort_f32(
  1989. const arm_sort_instance_f32 * S,
  1990. float32_t * pSrc,
  1991. float32_t * pDst,
  1992. uint32_t blockSize);
  1993. /**
  1994. * @param[in,out] S points to an instance of the sorting structure.
  1995. * @param[in] alg Selected algorithm.
  1996. * @param[in] dir Sorting order.
  1997. */
  1998. void arm_sort_init_f32(
  1999. arm_sort_instance_f32 * S,
  2000. arm_sort_alg alg,
  2001. arm_sort_dir dir);
  2002. /**
  2003. * @brief Instance structure for the sorting algorithms.
  2004. */
  2005. typedef struct
  2006. {
  2007. arm_sort_dir dir; /**< Sorting order (direction) */
  2008. float32_t * buffer; /**< Working buffer */
  2009. } arm_merge_sort_instance_f32;
  2010. /**
  2011. * @param[in] S points to an instance of the sorting structure.
  2012. * @param[in,out] pSrc points to the block of input data.
  2013. * @param[out] pDst points to the block of output data
  2014. * @param[in] blockSize number of samples to process.
  2015. */
  2016. void arm_merge_sort_f32(
  2017. const arm_merge_sort_instance_f32 * S,
  2018. float32_t *pSrc,
  2019. float32_t *pDst,
  2020. uint32_t blockSize);
  2021. /**
  2022. * @param[in,out] S points to an instance of the sorting structure.
  2023. * @param[in] dir Sorting order.
  2024. * @param[in] buffer Working buffer.
  2025. */
  2026. void arm_merge_sort_init_f32(
  2027. arm_merge_sort_instance_f32 * S,
  2028. arm_sort_dir dir,
  2029. float32_t * buffer);
  2030. /**
  2031. * @brief Struct for specifying cubic spline type
  2032. */
  2033. typedef enum
  2034. {
  2035. ARM_SPLINE_NATURAL = 0, /**< Natural spline */
  2036. ARM_SPLINE_PARABOLIC_RUNOUT = 1 /**< Parabolic runout spline */
  2037. } arm_spline_type;
  2038. /**
  2039. * @brief Instance structure for the floating-point cubic spline interpolation.
  2040. */
  2041. typedef struct
  2042. {
  2043. arm_spline_type type; /**< Type (boundary conditions) */
  2044. const float32_t * x; /**< x values */
  2045. const float32_t * y; /**< y values */
  2046. uint32_t n_x; /**< Number of known data points */
  2047. float32_t * coeffs; /**< Coefficients buffer (b,c, and d) */
  2048. } arm_spline_instance_f32;
  2049. /**
  2050. * @brief Processing function for the floating-point cubic spline interpolation.
  2051. * @param[in] S points to an instance of the floating-point spline structure.
  2052. * @param[in] xq points to the x values ot the interpolated data points.
  2053. * @param[out] pDst points to the block of output data.
  2054. * @param[in] blockSize number of samples of output data.
  2055. */
  2056. void arm_spline_f32(
  2057. arm_spline_instance_f32 * S,
  2058. const float32_t * xq,
  2059. float32_t * pDst,
  2060. uint32_t blockSize);
  2061. /**
  2062. * @brief Initialization function for the floating-point cubic spline interpolation.
  2063. * @param[in,out] S points to an instance of the floating-point spline structure.
  2064. * @param[in] type type of cubic spline interpolation (boundary conditions)
  2065. * @param[in] x points to the x values of the known data points.
  2066. * @param[in] y points to the y values of the known data points.
  2067. * @param[in] n number of known data points.
  2068. * @param[in] coeffs coefficients array for b, c, and d
  2069. * @param[in] tempBuffer buffer array for internal computations
  2070. */
  2071. void arm_spline_init_f32(
  2072. arm_spline_instance_f32 * S,
  2073. arm_spline_type type,
  2074. const float32_t * x,
  2075. const float32_t * y,
  2076. uint32_t n,
  2077. float32_t * coeffs,
  2078. float32_t * tempBuffer);
  2079. /**
  2080. * @brief Instance structure for the floating-point matrix structure.
  2081. */
  2082. typedef struct
  2083. {
  2084. uint16_t numRows; /**< number of rows of the matrix. */
  2085. uint16_t numCols; /**< number of columns of the matrix. */
  2086. float32_t *pData; /**< points to the data of the matrix. */
  2087. } arm_matrix_instance_f32;
  2088. /**
  2089. * @brief Instance structure for the floating-point matrix structure.
  2090. */
  2091. typedef struct
  2092. {
  2093. uint16_t numRows; /**< number of rows of the matrix. */
  2094. uint16_t numCols; /**< number of columns of the matrix. */
  2095. float64_t *pData; /**< points to the data of the matrix. */
  2096. } arm_matrix_instance_f64;
  2097. /**
  2098. * @brief Instance structure for the Q15 matrix structure.
  2099. */
  2100. typedef struct
  2101. {
  2102. uint16_t numRows; /**< number of rows of the matrix. */
  2103. uint16_t numCols; /**< number of columns of the matrix. */
  2104. q15_t *pData; /**< points to the data of the matrix. */
  2105. } arm_matrix_instance_q15;
  2106. /**
  2107. * @brief Instance structure for the Q31 matrix structure.
  2108. */
  2109. typedef struct
  2110. {
  2111. uint16_t numRows; /**< number of rows of the matrix. */
  2112. uint16_t numCols; /**< number of columns of the matrix. */
  2113. q31_t *pData; /**< points to the data of the matrix. */
  2114. } arm_matrix_instance_q31;
  2115. /**
  2116. * @brief Floating-point matrix addition.
  2117. * @param[in] pSrcA points to the first input matrix structure
  2118. * @param[in] pSrcB points to the second input matrix structure
  2119. * @param[out] pDst points to output matrix structure
  2120. * @return The function returns either
  2121. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2122. */
  2123. arm_status arm_mat_add_f32(
  2124. const arm_matrix_instance_f32 * pSrcA,
  2125. const arm_matrix_instance_f32 * pSrcB,
  2126. arm_matrix_instance_f32 * pDst);
  2127. /**
  2128. * @brief Q15 matrix addition.
  2129. * @param[in] pSrcA points to the first input matrix structure
  2130. * @param[in] pSrcB points to the second input matrix structure
  2131. * @param[out] pDst points to output matrix structure
  2132. * @return The function returns either
  2133. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2134. */
  2135. arm_status arm_mat_add_q15(
  2136. const arm_matrix_instance_q15 * pSrcA,
  2137. const arm_matrix_instance_q15 * pSrcB,
  2138. arm_matrix_instance_q15 * pDst);
  2139. /**
  2140. * @brief Q31 matrix addition.
  2141. * @param[in] pSrcA points to the first input matrix structure
  2142. * @param[in] pSrcB points to the second input matrix structure
  2143. * @param[out] pDst points to output matrix structure
  2144. * @return The function returns either
  2145. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2146. */
  2147. arm_status arm_mat_add_q31(
  2148. const arm_matrix_instance_q31 * pSrcA,
  2149. const arm_matrix_instance_q31 * pSrcB,
  2150. arm_matrix_instance_q31 * pDst);
  2151. /**
  2152. * @brief Floating-point, complex, matrix multiplication.
  2153. * @param[in] pSrcA points to the first input matrix structure
  2154. * @param[in] pSrcB points to the second input matrix structure
  2155. * @param[out] pDst points to output matrix structure
  2156. * @return The function returns either
  2157. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2158. */
  2159. arm_status arm_mat_cmplx_mult_f32(
  2160. const arm_matrix_instance_f32 * pSrcA,
  2161. const arm_matrix_instance_f32 * pSrcB,
  2162. arm_matrix_instance_f32 * pDst);
  2163. /**
  2164. * @brief Q15, complex, matrix multiplication.
  2165. * @param[in] pSrcA points to the first input matrix structure
  2166. * @param[in] pSrcB points to the second input matrix structure
  2167. * @param[out] pDst points to output matrix structure
  2168. * @return The function returns either
  2169. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2170. */
  2171. arm_status arm_mat_cmplx_mult_q15(
  2172. const arm_matrix_instance_q15 * pSrcA,
  2173. const arm_matrix_instance_q15 * pSrcB,
  2174. arm_matrix_instance_q15 * pDst,
  2175. q15_t * pScratch);
  2176. /**
  2177. * @brief Q31, complex, matrix multiplication.
  2178. * @param[in] pSrcA points to the first input matrix structure
  2179. * @param[in] pSrcB points to the second input matrix structure
  2180. * @param[out] pDst points to output matrix structure
  2181. * @return The function returns either
  2182. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2183. */
  2184. arm_status arm_mat_cmplx_mult_q31(
  2185. const arm_matrix_instance_q31 * pSrcA,
  2186. const arm_matrix_instance_q31 * pSrcB,
  2187. arm_matrix_instance_q31 * pDst);
  2188. /**
  2189. * @brief Floating-point matrix transpose.
  2190. * @param[in] pSrc points to the input matrix
  2191. * @param[out] pDst points to the output matrix
  2192. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  2193. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2194. */
  2195. arm_status arm_mat_trans_f32(
  2196. const arm_matrix_instance_f32 * pSrc,
  2197. arm_matrix_instance_f32 * pDst);
  2198. /**
  2199. * @brief Q15 matrix transpose.
  2200. * @param[in] pSrc points to the input matrix
  2201. * @param[out] pDst points to the output matrix
  2202. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  2203. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2204. */
  2205. arm_status arm_mat_trans_q15(
  2206. const arm_matrix_instance_q15 * pSrc,
  2207. arm_matrix_instance_q15 * pDst);
  2208. /**
  2209. * @brief Q31 matrix transpose.
  2210. * @param[in] pSrc points to the input matrix
  2211. * @param[out] pDst points to the output matrix
  2212. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  2213. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2214. */
  2215. arm_status arm_mat_trans_q31(
  2216. const arm_matrix_instance_q31 * pSrc,
  2217. arm_matrix_instance_q31 * pDst);
  2218. /**
  2219. * @brief Floating-point matrix multiplication
  2220. * @param[in] pSrcA points to the first input matrix structure
  2221. * @param[in] pSrcB points to the second input matrix structure
  2222. * @param[out] pDst points to output matrix structure
  2223. * @return The function returns either
  2224. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2225. */
  2226. arm_status arm_mat_mult_f32(
  2227. const arm_matrix_instance_f32 * pSrcA,
  2228. const arm_matrix_instance_f32 * pSrcB,
  2229. arm_matrix_instance_f32 * pDst);
  2230. /**
  2231. * @brief Q15 matrix multiplication
  2232. * @param[in] pSrcA points to the first input matrix structure
  2233. * @param[in] pSrcB points to the second input matrix structure
  2234. * @param[out] pDst points to output matrix structure
  2235. * @param[in] pState points to the array for storing intermediate results
  2236. * @return The function returns either
  2237. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2238. */
  2239. arm_status arm_mat_mult_q15(
  2240. const arm_matrix_instance_q15 * pSrcA,
  2241. const arm_matrix_instance_q15 * pSrcB,
  2242. arm_matrix_instance_q15 * pDst,
  2243. q15_t * pState);
  2244. /**
  2245. * @brief Q15 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  2246. * @param[in] pSrcA points to the first input matrix structure
  2247. * @param[in] pSrcB points to the second input matrix structure
  2248. * @param[out] pDst points to output matrix structure
  2249. * @param[in] pState points to the array for storing intermediate results
  2250. * @return The function returns either
  2251. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2252. */
  2253. arm_status arm_mat_mult_fast_q15(
  2254. const arm_matrix_instance_q15 * pSrcA,
  2255. const arm_matrix_instance_q15 * pSrcB,
  2256. arm_matrix_instance_q15 * pDst,
  2257. q15_t * pState);
  2258. /**
  2259. * @brief Q31 matrix multiplication
  2260. * @param[in] pSrcA points to the first input matrix structure
  2261. * @param[in] pSrcB points to the second input matrix structure
  2262. * @param[out] pDst points to output matrix structure
  2263. * @return The function returns either
  2264. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2265. */
  2266. arm_status arm_mat_mult_q31(
  2267. const arm_matrix_instance_q31 * pSrcA,
  2268. const arm_matrix_instance_q31 * pSrcB,
  2269. arm_matrix_instance_q31 * pDst);
  2270. /**
  2271. * @brief Q31 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  2272. * @param[in] pSrcA points to the first input matrix structure
  2273. * @param[in] pSrcB points to the second input matrix structure
  2274. * @param[out] pDst points to output matrix structure
  2275. * @return The function returns either
  2276. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2277. */
  2278. arm_status arm_mat_mult_fast_q31(
  2279. const arm_matrix_instance_q31 * pSrcA,
  2280. const arm_matrix_instance_q31 * pSrcB,
  2281. arm_matrix_instance_q31 * pDst);
  2282. /**
  2283. * @brief Floating-point matrix subtraction
  2284. * @param[in] pSrcA points to the first input matrix structure
  2285. * @param[in] pSrcB points to the second input matrix structure
  2286. * @param[out] pDst points to output matrix structure
  2287. * @return The function returns either
  2288. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2289. */
  2290. arm_status arm_mat_sub_f32(
  2291. const arm_matrix_instance_f32 * pSrcA,
  2292. const arm_matrix_instance_f32 * pSrcB,
  2293. arm_matrix_instance_f32 * pDst);
  2294. /**
  2295. * @brief Q15 matrix subtraction
  2296. * @param[in] pSrcA points to the first input matrix structure
  2297. * @param[in] pSrcB points to the second input matrix structure
  2298. * @param[out] pDst points to output matrix structure
  2299. * @return The function returns either
  2300. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2301. */
  2302. arm_status arm_mat_sub_q15(
  2303. const arm_matrix_instance_q15 * pSrcA,
  2304. const arm_matrix_instance_q15 * pSrcB,
  2305. arm_matrix_instance_q15 * pDst);
  2306. /**
  2307. * @brief Q31 matrix subtraction
  2308. * @param[in] pSrcA points to the first input matrix structure
  2309. * @param[in] pSrcB points to the second input matrix structure
  2310. * @param[out] pDst points to output matrix structure
  2311. * @return The function returns either
  2312. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2313. */
  2314. arm_status arm_mat_sub_q31(
  2315. const arm_matrix_instance_q31 * pSrcA,
  2316. const arm_matrix_instance_q31 * pSrcB,
  2317. arm_matrix_instance_q31 * pDst);
  2318. /**
  2319. * @brief Floating-point matrix scaling.
  2320. * @param[in] pSrc points to the input matrix
  2321. * @param[in] scale scale factor
  2322. * @param[out] pDst points to the output matrix
  2323. * @return The function returns either
  2324. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2325. */
  2326. arm_status arm_mat_scale_f32(
  2327. const arm_matrix_instance_f32 * pSrc,
  2328. float32_t scale,
  2329. arm_matrix_instance_f32 * pDst);
  2330. /**
  2331. * @brief Q15 matrix scaling.
  2332. * @param[in] pSrc points to input matrix
  2333. * @param[in] scaleFract fractional portion of the scale factor
  2334. * @param[in] shift number of bits to shift the result by
  2335. * @param[out] pDst points to output matrix
  2336. * @return The function returns either
  2337. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2338. */
  2339. arm_status arm_mat_scale_q15(
  2340. const arm_matrix_instance_q15 * pSrc,
  2341. q15_t scaleFract,
  2342. int32_t shift,
  2343. arm_matrix_instance_q15 * pDst);
  2344. /**
  2345. * @brief Q31 matrix scaling.
  2346. * @param[in] pSrc points to input matrix
  2347. * @param[in] scaleFract fractional portion of the scale factor
  2348. * @param[in] shift number of bits to shift the result by
  2349. * @param[out] pDst points to output matrix structure
  2350. * @return The function returns either
  2351. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2352. */
  2353. arm_status arm_mat_scale_q31(
  2354. const arm_matrix_instance_q31 * pSrc,
  2355. q31_t scaleFract,
  2356. int32_t shift,
  2357. arm_matrix_instance_q31 * pDst);
  2358. /**
  2359. * @brief Q31 matrix initialization.
  2360. * @param[in,out] S points to an instance of the floating-point matrix structure.
  2361. * @param[in] nRows number of rows in the matrix.
  2362. * @param[in] nColumns number of columns in the matrix.
  2363. * @param[in] pData points to the matrix data array.
  2364. */
  2365. void arm_mat_init_q31(
  2366. arm_matrix_instance_q31 * S,
  2367. uint16_t nRows,
  2368. uint16_t nColumns,
  2369. q31_t * pData);
  2370. /**
  2371. * @brief Q15 matrix initialization.
  2372. * @param[in,out] S points to an instance of the floating-point matrix structure.
  2373. * @param[in] nRows number of rows in the matrix.
  2374. * @param[in] nColumns number of columns in the matrix.
  2375. * @param[in] pData points to the matrix data array.
  2376. */
  2377. void arm_mat_init_q15(
  2378. arm_matrix_instance_q15 * S,
  2379. uint16_t nRows,
  2380. uint16_t nColumns,
  2381. q15_t * pData);
  2382. /**
  2383. * @brief Floating-point matrix initialization.
  2384. * @param[in,out] S points to an instance of the floating-point matrix structure.
  2385. * @param[in] nRows number of rows in the matrix.
  2386. * @param[in] nColumns number of columns in the matrix.
  2387. * @param[in] pData points to the matrix data array.
  2388. */
  2389. void arm_mat_init_f32(
  2390. arm_matrix_instance_f32 * S,
  2391. uint16_t nRows,
  2392. uint16_t nColumns,
  2393. float32_t * pData);
  2394. /**
  2395. * @brief Instance structure for the Q15 PID Control.
  2396. */
  2397. typedef struct
  2398. {
  2399. q15_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
  2400. #if !defined (ARM_MATH_DSP)
  2401. q15_t A1;
  2402. q15_t A2;
  2403. #else
  2404. q31_t A1; /**< The derived gain A1 = -Kp - 2Kd | Kd.*/
  2405. #endif
  2406. q15_t state[3]; /**< The state array of length 3. */
  2407. q15_t Kp; /**< The proportional gain. */
  2408. q15_t Ki; /**< The integral gain. */
  2409. q15_t Kd; /**< The derivative gain. */
  2410. } arm_pid_instance_q15;
  2411. /**
  2412. * @brief Instance structure for the Q31 PID Control.
  2413. */
  2414. typedef struct
  2415. {
  2416. q31_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
  2417. q31_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */
  2418. q31_t A2; /**< The derived gain, A2 = Kd . */
  2419. q31_t state[3]; /**< The state array of length 3. */
  2420. q31_t Kp; /**< The proportional gain. */
  2421. q31_t Ki; /**< The integral gain. */
  2422. q31_t Kd; /**< The derivative gain. */
  2423. } arm_pid_instance_q31;
  2424. /**
  2425. * @brief Instance structure for the floating-point PID Control.
  2426. */
  2427. typedef struct
  2428. {
  2429. float32_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
  2430. float32_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */
  2431. float32_t A2; /**< The derived gain, A2 = Kd . */
  2432. float32_t state[3]; /**< The state array of length 3. */
  2433. float32_t Kp; /**< The proportional gain. */
  2434. float32_t Ki; /**< The integral gain. */
  2435. float32_t Kd; /**< The derivative gain. */
  2436. } arm_pid_instance_f32;
  2437. /**
  2438. * @brief Initialization function for the floating-point PID Control.
  2439. * @param[in,out] S points to an instance of the PID structure.
  2440. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
  2441. */
  2442. void arm_pid_init_f32(
  2443. arm_pid_instance_f32 * S,
  2444. int32_t resetStateFlag);
  2445. /**
  2446. * @brief Reset function for the floating-point PID Control.
  2447. * @param[in,out] S is an instance of the floating-point PID Control structure
  2448. */
  2449. void arm_pid_reset_f32(
  2450. arm_pid_instance_f32 * S);
  2451. /**
  2452. * @brief Initialization function for the Q31 PID Control.
  2453. * @param[in,out] S points to an instance of the Q15 PID structure.
  2454. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
  2455. */
  2456. void arm_pid_init_q31(
  2457. arm_pid_instance_q31 * S,
  2458. int32_t resetStateFlag);
  2459. /**
  2460. * @brief Reset function for the Q31 PID Control.
  2461. * @param[in,out] S points to an instance of the Q31 PID Control structure
  2462. */
  2463. void arm_pid_reset_q31(
  2464. arm_pid_instance_q31 * S);
  2465. /**
  2466. * @brief Initialization function for the Q15 PID Control.
  2467. * @param[in,out] S points to an instance of the Q15 PID structure.
  2468. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
  2469. */
  2470. void arm_pid_init_q15(
  2471. arm_pid_instance_q15 * S,
  2472. int32_t resetStateFlag);
  2473. /**
  2474. * @brief Reset function for the Q15 PID Control.
  2475. * @param[in,out] S points to an instance of the q15 PID Control structure
  2476. */
  2477. void arm_pid_reset_q15(
  2478. arm_pid_instance_q15 * S);
  2479. /**
  2480. * @brief Instance structure for the floating-point Linear Interpolate function.
  2481. */
  2482. typedef struct
  2483. {
  2484. uint32_t nValues; /**< nValues */
  2485. float32_t x1; /**< x1 */
  2486. float32_t xSpacing; /**< xSpacing */
  2487. float32_t *pYData; /**< pointer to the table of Y values */
  2488. } arm_linear_interp_instance_f32;
  2489. /**
  2490. * @brief Instance structure for the floating-point bilinear interpolation function.
  2491. */
  2492. typedef struct
  2493. {
  2494. uint16_t numRows; /**< number of rows in the data table. */
  2495. uint16_t numCols; /**< number of columns in the data table. */
  2496. float32_t *pData; /**< points to the data table. */
  2497. } arm_bilinear_interp_instance_f32;
  2498. /**
  2499. * @brief Instance structure for the Q31 bilinear interpolation function.
  2500. */
  2501. typedef struct
  2502. {
  2503. uint16_t numRows; /**< number of rows in the data table. */
  2504. uint16_t numCols; /**< number of columns in the data table. */
  2505. q31_t *pData; /**< points to the data table. */
  2506. } arm_bilinear_interp_instance_q31;
  2507. /**
  2508. * @brief Instance structure for the Q15 bilinear interpolation function.
  2509. */
  2510. typedef struct
  2511. {
  2512. uint16_t numRows; /**< number of rows in the data table. */
  2513. uint16_t numCols; /**< number of columns in the data table. */
  2514. q15_t *pData; /**< points to the data table. */
  2515. } arm_bilinear_interp_instance_q15;
  2516. /**
  2517. * @brief Instance structure for the Q15 bilinear interpolation function.
  2518. */
  2519. typedef struct
  2520. {
  2521. uint16_t numRows; /**< number of rows in the data table. */
  2522. uint16_t numCols; /**< number of columns in the data table. */
  2523. q7_t *pData; /**< points to the data table. */
  2524. } arm_bilinear_interp_instance_q7;
  2525. /**
  2526. * @brief Q7 vector multiplication.
  2527. * @param[in] pSrcA points to the first input vector
  2528. * @param[in] pSrcB points to the second input vector
  2529. * @param[out] pDst points to the output vector
  2530. * @param[in] blockSize number of samples in each vector
  2531. */
  2532. void arm_mult_q7(
  2533. const q7_t * pSrcA,
  2534. const q7_t * pSrcB,
  2535. q7_t * pDst,
  2536. uint32_t blockSize);
  2537. /**
  2538. * @brief Q15 vector multiplication.
  2539. * @param[in] pSrcA points to the first input vector
  2540. * @param[in] pSrcB points to the second input vector
  2541. * @param[out] pDst points to the output vector
  2542. * @param[in] blockSize number of samples in each vector
  2543. */
  2544. void arm_mult_q15(
  2545. const q15_t * pSrcA,
  2546. const q15_t * pSrcB,
  2547. q15_t * pDst,
  2548. uint32_t blockSize);
  2549. /**
  2550. * @brief Q31 vector multiplication.
  2551. * @param[in] pSrcA points to the first input vector
  2552. * @param[in] pSrcB points to the second input vector
  2553. * @param[out] pDst points to the output vector
  2554. * @param[in] blockSize number of samples in each vector
  2555. */
  2556. void arm_mult_q31(
  2557. const q31_t * pSrcA,
  2558. const q31_t * pSrcB,
  2559. q31_t * pDst,
  2560. uint32_t blockSize);
  2561. /**
  2562. * @brief Floating-point vector multiplication.
  2563. * @param[in] pSrcA points to the first input vector
  2564. * @param[in] pSrcB points to the second input vector
  2565. * @param[out] pDst points to the output vector
  2566. * @param[in] blockSize number of samples in each vector
  2567. */
  2568. void arm_mult_f32(
  2569. const float32_t * pSrcA,
  2570. const float32_t * pSrcB,
  2571. float32_t * pDst,
  2572. uint32_t blockSize);
  2573. /**
  2574. * @brief Instance structure for the Q15 CFFT/CIFFT function.
  2575. */
  2576. typedef struct
  2577. {
  2578. uint16_t fftLen; /**< length of the FFT. */
  2579. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2580. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2581. const q15_t *pTwiddle; /**< points to the Sin twiddle factor table. */
  2582. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2583. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2584. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2585. } arm_cfft_radix2_instance_q15;
  2586. /* Deprecated */
  2587. arm_status arm_cfft_radix2_init_q15(
  2588. arm_cfft_radix2_instance_q15 * S,
  2589. uint16_t fftLen,
  2590. uint8_t ifftFlag,
  2591. uint8_t bitReverseFlag);
  2592. /* Deprecated */
  2593. void arm_cfft_radix2_q15(
  2594. const arm_cfft_radix2_instance_q15 * S,
  2595. q15_t * pSrc);
  2596. /**
  2597. * @brief Instance structure for the Q15 CFFT/CIFFT function.
  2598. */
  2599. typedef struct
  2600. {
  2601. uint16_t fftLen; /**< length of the FFT. */
  2602. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2603. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2604. const q15_t *pTwiddle; /**< points to the twiddle factor table. */
  2605. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2606. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2607. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2608. } arm_cfft_radix4_instance_q15;
  2609. /* Deprecated */
  2610. arm_status arm_cfft_radix4_init_q15(
  2611. arm_cfft_radix4_instance_q15 * S,
  2612. uint16_t fftLen,
  2613. uint8_t ifftFlag,
  2614. uint8_t bitReverseFlag);
  2615. /* Deprecated */
  2616. void arm_cfft_radix4_q15(
  2617. const arm_cfft_radix4_instance_q15 * S,
  2618. q15_t * pSrc);
  2619. /**
  2620. * @brief Instance structure for the Radix-2 Q31 CFFT/CIFFT function.
  2621. */
  2622. typedef struct
  2623. {
  2624. uint16_t fftLen; /**< length of the FFT. */
  2625. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2626. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2627. const q31_t *pTwiddle; /**< points to the Twiddle factor table. */
  2628. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2629. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2630. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2631. } arm_cfft_radix2_instance_q31;
  2632. /* Deprecated */
  2633. arm_status arm_cfft_radix2_init_q31(
  2634. arm_cfft_radix2_instance_q31 * S,
  2635. uint16_t fftLen,
  2636. uint8_t ifftFlag,
  2637. uint8_t bitReverseFlag);
  2638. /* Deprecated */
  2639. void arm_cfft_radix2_q31(
  2640. const arm_cfft_radix2_instance_q31 * S,
  2641. q31_t * pSrc);
  2642. /**
  2643. * @brief Instance structure for the Q31 CFFT/CIFFT function.
  2644. */
  2645. typedef struct
  2646. {
  2647. uint16_t fftLen; /**< length of the FFT. */
  2648. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2649. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2650. const q31_t *pTwiddle; /**< points to the twiddle factor table. */
  2651. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2652. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2653. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2654. } arm_cfft_radix4_instance_q31;
  2655. /* Deprecated */
  2656. void arm_cfft_radix4_q31(
  2657. const arm_cfft_radix4_instance_q31 * S,
  2658. q31_t * pSrc);
  2659. /* Deprecated */
  2660. arm_status arm_cfft_radix4_init_q31(
  2661. arm_cfft_radix4_instance_q31 * S,
  2662. uint16_t fftLen,
  2663. uint8_t ifftFlag,
  2664. uint8_t bitReverseFlag);
  2665. /**
  2666. * @brief Instance structure for the floating-point CFFT/CIFFT function.
  2667. */
  2668. typedef struct
  2669. {
  2670. uint16_t fftLen; /**< length of the FFT. */
  2671. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2672. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2673. const float32_t *pTwiddle; /**< points to the Twiddle factor table. */
  2674. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2675. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2676. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2677. float32_t onebyfftLen; /**< value of 1/fftLen. */
  2678. } arm_cfft_radix2_instance_f32;
  2679. /* Deprecated */
  2680. arm_status arm_cfft_radix2_init_f32(
  2681. arm_cfft_radix2_instance_f32 * S,
  2682. uint16_t fftLen,
  2683. uint8_t ifftFlag,
  2684. uint8_t bitReverseFlag);
  2685. /* Deprecated */
  2686. void arm_cfft_radix2_f32(
  2687. const arm_cfft_radix2_instance_f32 * S,
  2688. float32_t * pSrc);
  2689. /**
  2690. * @brief Instance structure for the floating-point CFFT/CIFFT function.
  2691. */
  2692. typedef struct
  2693. {
  2694. uint16_t fftLen; /**< length of the FFT. */
  2695. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2696. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2697. const float32_t *pTwiddle; /**< points to the Twiddle factor table. */
  2698. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2699. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2700. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2701. float32_t onebyfftLen; /**< value of 1/fftLen. */
  2702. } arm_cfft_radix4_instance_f32;
  2703. /* Deprecated */
  2704. arm_status arm_cfft_radix4_init_f32(
  2705. arm_cfft_radix4_instance_f32 * S,
  2706. uint16_t fftLen,
  2707. uint8_t ifftFlag,
  2708. uint8_t bitReverseFlag);
  2709. /* Deprecated */
  2710. void arm_cfft_radix4_f32(
  2711. const arm_cfft_radix4_instance_f32 * S,
  2712. float32_t * pSrc);
  2713. /**
  2714. * @brief Instance structure for the fixed-point CFFT/CIFFT function.
  2715. */
  2716. typedef struct
  2717. {
  2718. uint16_t fftLen; /**< length of the FFT. */
  2719. const q15_t *pTwiddle; /**< points to the Twiddle factor table. */
  2720. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2721. uint16_t bitRevLength; /**< bit reversal table length. */
  2722. #if defined(ARM_MATH_MVEI)
  2723. const uint32_t *rearranged_twiddle_tab_stride1_arr; /**< Per stage reordered twiddle pointer (offset 1) */ \
  2724. const uint32_t *rearranged_twiddle_tab_stride2_arr; /**< Per stage reordered twiddle pointer (offset 2) */ \
  2725. const uint32_t *rearranged_twiddle_tab_stride3_arr; /**< Per stage reordered twiddle pointer (offset 3) */ \
  2726. const q15_t *rearranged_twiddle_stride1; /**< reordered twiddle offset 1 storage */ \
  2727. const q15_t *rearranged_twiddle_stride2; /**< reordered twiddle offset 2 storage */ \
  2728. const q15_t *rearranged_twiddle_stride3;
  2729. #endif
  2730. } arm_cfft_instance_q15;
  2731. arm_status arm_cfft_init_q15(
  2732. arm_cfft_instance_q15 * S,
  2733. uint16_t fftLen);
  2734. void arm_cfft_q15(
  2735. const arm_cfft_instance_q15 * S,
  2736. q15_t * p1,
  2737. uint8_t ifftFlag,
  2738. uint8_t bitReverseFlag);
  2739. /**
  2740. * @brief Instance structure for the fixed-point CFFT/CIFFT function.
  2741. */
  2742. typedef struct
  2743. {
  2744. uint16_t fftLen; /**< length of the FFT. */
  2745. const q31_t *pTwiddle; /**< points to the Twiddle factor table. */
  2746. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2747. uint16_t bitRevLength; /**< bit reversal table length. */
  2748. #if defined(ARM_MATH_MVEI)
  2749. const uint32_t *rearranged_twiddle_tab_stride1_arr; /**< Per stage reordered twiddle pointer (offset 1) */ \
  2750. const uint32_t *rearranged_twiddle_tab_stride2_arr; /**< Per stage reordered twiddle pointer (offset 2) */ \
  2751. const uint32_t *rearranged_twiddle_tab_stride3_arr; /**< Per stage reordered twiddle pointer (offset 3) */ \
  2752. const q31_t *rearranged_twiddle_stride1; /**< reordered twiddle offset 1 storage */ \
  2753. const q31_t *rearranged_twiddle_stride2; /**< reordered twiddle offset 2 storage */ \
  2754. const q31_t *rearranged_twiddle_stride3;
  2755. #endif
  2756. } arm_cfft_instance_q31;
  2757. arm_status arm_cfft_init_q31(
  2758. arm_cfft_instance_q31 * S,
  2759. uint16_t fftLen);
  2760. void arm_cfft_q31(
  2761. const arm_cfft_instance_q31 * S,
  2762. q31_t * p1,
  2763. uint8_t ifftFlag,
  2764. uint8_t bitReverseFlag);
  2765. /**
  2766. * @brief Instance structure for the floating-point CFFT/CIFFT function.
  2767. */
  2768. typedef struct
  2769. {
  2770. uint16_t fftLen; /**< length of the FFT. */
  2771. const float32_t *pTwiddle; /**< points to the Twiddle factor table. */
  2772. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2773. uint16_t bitRevLength; /**< bit reversal table length. */
  2774. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  2775. const uint32_t *rearranged_twiddle_tab_stride1_arr; /**< Per stage reordered twiddle pointer (offset 1) */ \
  2776. const uint32_t *rearranged_twiddle_tab_stride2_arr; /**< Per stage reordered twiddle pointer (offset 2) */ \
  2777. const uint32_t *rearranged_twiddle_tab_stride3_arr; /**< Per stage reordered twiddle pointer (offset 3) */ \
  2778. const float32_t *rearranged_twiddle_stride1; /**< reordered twiddle offset 1 storage */ \
  2779. const float32_t *rearranged_twiddle_stride2; /**< reordered twiddle offset 2 storage */ \
  2780. const float32_t *rearranged_twiddle_stride3;
  2781. #endif
  2782. } arm_cfft_instance_f32;
  2783. arm_status arm_cfft_init_f32(
  2784. arm_cfft_instance_f32 * S,
  2785. uint16_t fftLen);
  2786. void arm_cfft_f32(
  2787. const arm_cfft_instance_f32 * S,
  2788. float32_t * p1,
  2789. uint8_t ifftFlag,
  2790. uint8_t bitReverseFlag);
  2791. /**
  2792. * @brief Instance structure for the Double Precision Floating-point CFFT/CIFFT function.
  2793. */
  2794. typedef struct
  2795. {
  2796. uint16_t fftLen; /**< length of the FFT. */
  2797. const float64_t *pTwiddle; /**< points to the Twiddle factor table. */
  2798. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2799. uint16_t bitRevLength; /**< bit reversal table length. */
  2800. } arm_cfft_instance_f64;
  2801. void arm_cfft_f64(
  2802. const arm_cfft_instance_f64 * S,
  2803. float64_t * p1,
  2804. uint8_t ifftFlag,
  2805. uint8_t bitReverseFlag);
  2806. /**
  2807. * @brief Instance structure for the Q15 RFFT/RIFFT function.
  2808. */
  2809. typedef struct
  2810. {
  2811. uint32_t fftLenReal; /**< length of the real FFT. */
  2812. uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */
  2813. uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */
  2814. uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2815. const q15_t *pTwiddleAReal; /**< points to the real twiddle factor table. */
  2816. const q15_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */
  2817. #if defined(ARM_MATH_MVEI)
  2818. arm_cfft_instance_q15 cfftInst;
  2819. #else
  2820. const arm_cfft_instance_q15 *pCfft; /**< points to the complex FFT instance. */
  2821. #endif
  2822. } arm_rfft_instance_q15;
  2823. arm_status arm_rfft_init_q15(
  2824. arm_rfft_instance_q15 * S,
  2825. uint32_t fftLenReal,
  2826. uint32_t ifftFlagR,
  2827. uint32_t bitReverseFlag);
  2828. void arm_rfft_q15(
  2829. const arm_rfft_instance_q15 * S,
  2830. q15_t * pSrc,
  2831. q15_t * pDst);
  2832. /**
  2833. * @brief Instance structure for the Q31 RFFT/RIFFT function.
  2834. */
  2835. typedef struct
  2836. {
  2837. uint32_t fftLenReal; /**< length of the real FFT. */
  2838. uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */
  2839. uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */
  2840. uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2841. const q31_t *pTwiddleAReal; /**< points to the real twiddle factor table. */
  2842. const q31_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */
  2843. #if defined(ARM_MATH_MVEI)
  2844. arm_cfft_instance_q31 cfftInst;
  2845. #else
  2846. const arm_cfft_instance_q31 *pCfft; /**< points to the complex FFT instance. */
  2847. #endif
  2848. } arm_rfft_instance_q31;
  2849. arm_status arm_rfft_init_q31(
  2850. arm_rfft_instance_q31 * S,
  2851. uint32_t fftLenReal,
  2852. uint32_t ifftFlagR,
  2853. uint32_t bitReverseFlag);
  2854. void arm_rfft_q31(
  2855. const arm_rfft_instance_q31 * S,
  2856. q31_t * pSrc,
  2857. q31_t * pDst);
  2858. /**
  2859. * @brief Instance structure for the floating-point RFFT/RIFFT function.
  2860. */
  2861. typedef struct
  2862. {
  2863. uint32_t fftLenReal; /**< length of the real FFT. */
  2864. uint16_t fftLenBy2; /**< length of the complex FFT. */
  2865. uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */
  2866. uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */
  2867. uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2868. const float32_t *pTwiddleAReal; /**< points to the real twiddle factor table. */
  2869. const float32_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */
  2870. arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */
  2871. } arm_rfft_instance_f32;
  2872. arm_status arm_rfft_init_f32(
  2873. arm_rfft_instance_f32 * S,
  2874. arm_cfft_radix4_instance_f32 * S_CFFT,
  2875. uint32_t fftLenReal,
  2876. uint32_t ifftFlagR,
  2877. uint32_t bitReverseFlag);
  2878. void arm_rfft_f32(
  2879. const arm_rfft_instance_f32 * S,
  2880. float32_t * pSrc,
  2881. float32_t * pDst);
  2882. /**
  2883. * @brief Instance structure for the Double Precision Floating-point RFFT/RIFFT function.
  2884. */
  2885. typedef struct
  2886. {
  2887. arm_cfft_instance_f64 Sint; /**< Internal CFFT structure. */
  2888. uint16_t fftLenRFFT; /**< length of the real sequence */
  2889. const float64_t * pTwiddleRFFT; /**< Twiddle factors real stage */
  2890. } arm_rfft_fast_instance_f64 ;
  2891. arm_status arm_rfft_fast_init_f64 (
  2892. arm_rfft_fast_instance_f64 * S,
  2893. uint16_t fftLen);
  2894. void arm_rfft_fast_f64(
  2895. arm_rfft_fast_instance_f64 * S,
  2896. float64_t * p, float64_t * pOut,
  2897. uint8_t ifftFlag);
  2898. /**
  2899. * @brief Instance structure for the floating-point RFFT/RIFFT function.
  2900. */
  2901. typedef struct
  2902. {
  2903. arm_cfft_instance_f32 Sint; /**< Internal CFFT structure. */
  2904. uint16_t fftLenRFFT; /**< length of the real sequence */
  2905. const float32_t * pTwiddleRFFT; /**< Twiddle factors real stage */
  2906. } arm_rfft_fast_instance_f32 ;
  2907. arm_status arm_rfft_fast_init_f32 (
  2908. arm_rfft_fast_instance_f32 * S,
  2909. uint16_t fftLen);
  2910. void arm_rfft_fast_f32(
  2911. const arm_rfft_fast_instance_f32 * S,
  2912. float32_t * p, float32_t * pOut,
  2913. uint8_t ifftFlag);
  2914. /**
  2915. * @brief Instance structure for the floating-point DCT4/IDCT4 function.
  2916. */
  2917. typedef struct
  2918. {
  2919. uint16_t N; /**< length of the DCT4. */
  2920. uint16_t Nby2; /**< half of the length of the DCT4. */
  2921. float32_t normalize; /**< normalizing factor. */
  2922. const float32_t *pTwiddle; /**< points to the twiddle factor table. */
  2923. const float32_t *pCosFactor; /**< points to the cosFactor table. */
  2924. arm_rfft_instance_f32 *pRfft; /**< points to the real FFT instance. */
  2925. arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */
  2926. } arm_dct4_instance_f32;
  2927. /**
  2928. * @brief Initialization function for the floating-point DCT4/IDCT4.
  2929. * @param[in,out] S points to an instance of floating-point DCT4/IDCT4 structure.
  2930. * @param[in] S_RFFT points to an instance of floating-point RFFT/RIFFT structure.
  2931. * @param[in] S_CFFT points to an instance of floating-point CFFT/CIFFT structure.
  2932. * @param[in] N length of the DCT4.
  2933. * @param[in] Nby2 half of the length of the DCT4.
  2934. * @param[in] normalize normalizing factor.
  2935. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported transform length.
  2936. */
  2937. arm_status arm_dct4_init_f32(
  2938. arm_dct4_instance_f32 * S,
  2939. arm_rfft_instance_f32 * S_RFFT,
  2940. arm_cfft_radix4_instance_f32 * S_CFFT,
  2941. uint16_t N,
  2942. uint16_t Nby2,
  2943. float32_t normalize);
  2944. /**
  2945. * @brief Processing function for the floating-point DCT4/IDCT4.
  2946. * @param[in] S points to an instance of the floating-point DCT4/IDCT4 structure.
  2947. * @param[in] pState points to state buffer.
  2948. * @param[in,out] pInlineBuffer points to the in-place input and output buffer.
  2949. */
  2950. void arm_dct4_f32(
  2951. const arm_dct4_instance_f32 * S,
  2952. float32_t * pState,
  2953. float32_t * pInlineBuffer);
  2954. /**
  2955. * @brief Instance structure for the Q31 DCT4/IDCT4 function.
  2956. */
  2957. typedef struct
  2958. {
  2959. uint16_t N; /**< length of the DCT4. */
  2960. uint16_t Nby2; /**< half of the length of the DCT4. */
  2961. q31_t normalize; /**< normalizing factor. */
  2962. const q31_t *pTwiddle; /**< points to the twiddle factor table. */
  2963. const q31_t *pCosFactor; /**< points to the cosFactor table. */
  2964. arm_rfft_instance_q31 *pRfft; /**< points to the real FFT instance. */
  2965. arm_cfft_radix4_instance_q31 *pCfft; /**< points to the complex FFT instance. */
  2966. } arm_dct4_instance_q31;
  2967. /**
  2968. * @brief Initialization function for the Q31 DCT4/IDCT4.
  2969. * @param[in,out] S points to an instance of Q31 DCT4/IDCT4 structure.
  2970. * @param[in] S_RFFT points to an instance of Q31 RFFT/RIFFT structure
  2971. * @param[in] S_CFFT points to an instance of Q31 CFFT/CIFFT structure
  2972. * @param[in] N length of the DCT4.
  2973. * @param[in] Nby2 half of the length of the DCT4.
  2974. * @param[in] normalize normalizing factor.
  2975. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length.
  2976. */
  2977. arm_status arm_dct4_init_q31(
  2978. arm_dct4_instance_q31 * S,
  2979. arm_rfft_instance_q31 * S_RFFT,
  2980. arm_cfft_radix4_instance_q31 * S_CFFT,
  2981. uint16_t N,
  2982. uint16_t Nby2,
  2983. q31_t normalize);
  2984. /**
  2985. * @brief Processing function for the Q31 DCT4/IDCT4.
  2986. * @param[in] S points to an instance of the Q31 DCT4 structure.
  2987. * @param[in] pState points to state buffer.
  2988. * @param[in,out] pInlineBuffer points to the in-place input and output buffer.
  2989. */
  2990. void arm_dct4_q31(
  2991. const arm_dct4_instance_q31 * S,
  2992. q31_t * pState,
  2993. q31_t * pInlineBuffer);
  2994. /**
  2995. * @brief Instance structure for the Q15 DCT4/IDCT4 function.
  2996. */
  2997. typedef struct
  2998. {
  2999. uint16_t N; /**< length of the DCT4. */
  3000. uint16_t Nby2; /**< half of the length of the DCT4. */
  3001. q15_t normalize; /**< normalizing factor. */
  3002. const q15_t *pTwiddle; /**< points to the twiddle factor table. */
  3003. const q15_t *pCosFactor; /**< points to the cosFactor table. */
  3004. arm_rfft_instance_q15 *pRfft; /**< points to the real FFT instance. */
  3005. arm_cfft_radix4_instance_q15 *pCfft; /**< points to the complex FFT instance. */
  3006. } arm_dct4_instance_q15;
  3007. /**
  3008. * @brief Initialization function for the Q15 DCT4/IDCT4.
  3009. * @param[in,out] S points to an instance of Q15 DCT4/IDCT4 structure.
  3010. * @param[in] S_RFFT points to an instance of Q15 RFFT/RIFFT structure.
  3011. * @param[in] S_CFFT points to an instance of Q15 CFFT/CIFFT structure.
  3012. * @param[in] N length of the DCT4.
  3013. * @param[in] Nby2 half of the length of the DCT4.
  3014. * @param[in] normalize normalizing factor.
  3015. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length.
  3016. */
  3017. arm_status arm_dct4_init_q15(
  3018. arm_dct4_instance_q15 * S,
  3019. arm_rfft_instance_q15 * S_RFFT,
  3020. arm_cfft_radix4_instance_q15 * S_CFFT,
  3021. uint16_t N,
  3022. uint16_t Nby2,
  3023. q15_t normalize);
  3024. /**
  3025. * @brief Processing function for the Q15 DCT4/IDCT4.
  3026. * @param[in] S points to an instance of the Q15 DCT4 structure.
  3027. * @param[in] pState points to state buffer.
  3028. * @param[in,out] pInlineBuffer points to the in-place input and output buffer.
  3029. */
  3030. void arm_dct4_q15(
  3031. const arm_dct4_instance_q15 * S,
  3032. q15_t * pState,
  3033. q15_t * pInlineBuffer);
  3034. /**
  3035. * @brief Floating-point vector addition.
  3036. * @param[in] pSrcA points to the first input vector
  3037. * @param[in] pSrcB points to the second input vector
  3038. * @param[out] pDst points to the output vector
  3039. * @param[in] blockSize number of samples in each vector
  3040. */
  3041. void arm_add_f32(
  3042. const float32_t * pSrcA,
  3043. const float32_t * pSrcB,
  3044. float32_t * pDst,
  3045. uint32_t blockSize);
  3046. /**
  3047. * @brief Q7 vector addition.
  3048. * @param[in] pSrcA points to the first input vector
  3049. * @param[in] pSrcB points to the second input vector
  3050. * @param[out] pDst points to the output vector
  3051. * @param[in] blockSize number of samples in each vector
  3052. */
  3053. void arm_add_q7(
  3054. const q7_t * pSrcA,
  3055. const q7_t * pSrcB,
  3056. q7_t * pDst,
  3057. uint32_t blockSize);
  3058. /**
  3059. * @brief Q15 vector addition.
  3060. * @param[in] pSrcA points to the first input vector
  3061. * @param[in] pSrcB points to the second input vector
  3062. * @param[out] pDst points to the output vector
  3063. * @param[in] blockSize number of samples in each vector
  3064. */
  3065. void arm_add_q15(
  3066. const q15_t * pSrcA,
  3067. const q15_t * pSrcB,
  3068. q15_t * pDst,
  3069. uint32_t blockSize);
  3070. /**
  3071. * @brief Q31 vector addition.
  3072. * @param[in] pSrcA points to the first input vector
  3073. * @param[in] pSrcB points to the second input vector
  3074. * @param[out] pDst points to the output vector
  3075. * @param[in] blockSize number of samples in each vector
  3076. */
  3077. void arm_add_q31(
  3078. const q31_t * pSrcA,
  3079. const q31_t * pSrcB,
  3080. q31_t * pDst,
  3081. uint32_t blockSize);
  3082. /**
  3083. * @brief Floating-point vector subtraction.
  3084. * @param[in] pSrcA points to the first input vector
  3085. * @param[in] pSrcB points to the second input vector
  3086. * @param[out] pDst points to the output vector
  3087. * @param[in] blockSize number of samples in each vector
  3088. */
  3089. void arm_sub_f32(
  3090. const float32_t * pSrcA,
  3091. const float32_t * pSrcB,
  3092. float32_t * pDst,
  3093. uint32_t blockSize);
  3094. /**
  3095. * @brief Q7 vector subtraction.
  3096. * @param[in] pSrcA points to the first input vector
  3097. * @param[in] pSrcB points to the second input vector
  3098. * @param[out] pDst points to the output vector
  3099. * @param[in] blockSize number of samples in each vector
  3100. */
  3101. void arm_sub_q7(
  3102. const q7_t * pSrcA,
  3103. const q7_t * pSrcB,
  3104. q7_t * pDst,
  3105. uint32_t blockSize);
  3106. /**
  3107. * @brief Q15 vector subtraction.
  3108. * @param[in] pSrcA points to the first input vector
  3109. * @param[in] pSrcB points to the second input vector
  3110. * @param[out] pDst points to the output vector
  3111. * @param[in] blockSize number of samples in each vector
  3112. */
  3113. void arm_sub_q15(
  3114. const q15_t * pSrcA,
  3115. const q15_t * pSrcB,
  3116. q15_t * pDst,
  3117. uint32_t blockSize);
  3118. /**
  3119. * @brief Q31 vector subtraction.
  3120. * @param[in] pSrcA points to the first input vector
  3121. * @param[in] pSrcB points to the second input vector
  3122. * @param[out] pDst points to the output vector
  3123. * @param[in] blockSize number of samples in each vector
  3124. */
  3125. void arm_sub_q31(
  3126. const q31_t * pSrcA,
  3127. const q31_t * pSrcB,
  3128. q31_t * pDst,
  3129. uint32_t blockSize);
  3130. /**
  3131. * @brief Multiplies a floating-point vector by a scalar.
  3132. * @param[in] pSrc points to the input vector
  3133. * @param[in] scale scale factor to be applied
  3134. * @param[out] pDst points to the output vector
  3135. * @param[in] blockSize number of samples in the vector
  3136. */
  3137. void arm_scale_f32(
  3138. const float32_t * pSrc,
  3139. float32_t scale,
  3140. float32_t * pDst,
  3141. uint32_t blockSize);
  3142. /**
  3143. * @brief Multiplies a Q7 vector by a scalar.
  3144. * @param[in] pSrc points to the input vector
  3145. * @param[in] scaleFract fractional portion of the scale value
  3146. * @param[in] shift number of bits to shift the result by
  3147. * @param[out] pDst points to the output vector
  3148. * @param[in] blockSize number of samples in the vector
  3149. */
  3150. void arm_scale_q7(
  3151. const q7_t * pSrc,
  3152. q7_t scaleFract,
  3153. int8_t shift,
  3154. q7_t * pDst,
  3155. uint32_t blockSize);
  3156. /**
  3157. * @brief Multiplies a Q15 vector by a scalar.
  3158. * @param[in] pSrc points to the input vector
  3159. * @param[in] scaleFract fractional portion of the scale value
  3160. * @param[in] shift number of bits to shift the result by
  3161. * @param[out] pDst points to the output vector
  3162. * @param[in] blockSize number of samples in the vector
  3163. */
  3164. void arm_scale_q15(
  3165. const q15_t * pSrc,
  3166. q15_t scaleFract,
  3167. int8_t shift,
  3168. q15_t * pDst,
  3169. uint32_t blockSize);
  3170. /**
  3171. * @brief Multiplies a Q31 vector by a scalar.
  3172. * @param[in] pSrc points to the input vector
  3173. * @param[in] scaleFract fractional portion of the scale value
  3174. * @param[in] shift number of bits to shift the result by
  3175. * @param[out] pDst points to the output vector
  3176. * @param[in] blockSize number of samples in the vector
  3177. */
  3178. void arm_scale_q31(
  3179. const q31_t * pSrc,
  3180. q31_t scaleFract,
  3181. int8_t shift,
  3182. q31_t * pDst,
  3183. uint32_t blockSize);
  3184. /**
  3185. * @brief Q7 vector absolute value.
  3186. * @param[in] pSrc points to the input buffer
  3187. * @param[out] pDst points to the output buffer
  3188. * @param[in] blockSize number of samples in each vector
  3189. */
  3190. void arm_abs_q7(
  3191. const q7_t * pSrc,
  3192. q7_t * pDst,
  3193. uint32_t blockSize);
  3194. /**
  3195. * @brief Floating-point vector absolute value.
  3196. * @param[in] pSrc points to the input buffer
  3197. * @param[out] pDst points to the output buffer
  3198. * @param[in] blockSize number of samples in each vector
  3199. */
  3200. void arm_abs_f32(
  3201. const float32_t * pSrc,
  3202. float32_t * pDst,
  3203. uint32_t blockSize);
  3204. /**
  3205. * @brief Q15 vector absolute value.
  3206. * @param[in] pSrc points to the input buffer
  3207. * @param[out] pDst points to the output buffer
  3208. * @param[in] blockSize number of samples in each vector
  3209. */
  3210. void arm_abs_q15(
  3211. const q15_t * pSrc,
  3212. q15_t * pDst,
  3213. uint32_t blockSize);
  3214. /**
  3215. * @brief Q31 vector absolute value.
  3216. * @param[in] pSrc points to the input buffer
  3217. * @param[out] pDst points to the output buffer
  3218. * @param[in] blockSize number of samples in each vector
  3219. */
  3220. void arm_abs_q31(
  3221. const q31_t * pSrc,
  3222. q31_t * pDst,
  3223. uint32_t blockSize);
  3224. /**
  3225. * @brief Dot product of floating-point vectors.
  3226. * @param[in] pSrcA points to the first input vector
  3227. * @param[in] pSrcB points to the second input vector
  3228. * @param[in] blockSize number of samples in each vector
  3229. * @param[out] result output result returned here
  3230. */
  3231. void arm_dot_prod_f32(
  3232. const float32_t * pSrcA,
  3233. const float32_t * pSrcB,
  3234. uint32_t blockSize,
  3235. float32_t * result);
  3236. /**
  3237. * @brief Dot product of Q7 vectors.
  3238. * @param[in] pSrcA points to the first input vector
  3239. * @param[in] pSrcB points to the second input vector
  3240. * @param[in] blockSize number of samples in each vector
  3241. * @param[out] result output result returned here
  3242. */
  3243. void arm_dot_prod_q7(
  3244. const q7_t * pSrcA,
  3245. const q7_t * pSrcB,
  3246. uint32_t blockSize,
  3247. q31_t * result);
  3248. /**
  3249. * @brief Dot product of Q15 vectors.
  3250. * @param[in] pSrcA points to the first input vector
  3251. * @param[in] pSrcB points to the second input vector
  3252. * @param[in] blockSize number of samples in each vector
  3253. * @param[out] result output result returned here
  3254. */
  3255. void arm_dot_prod_q15(
  3256. const q15_t * pSrcA,
  3257. const q15_t * pSrcB,
  3258. uint32_t blockSize,
  3259. q63_t * result);
  3260. /**
  3261. * @brief Dot product of Q31 vectors.
  3262. * @param[in] pSrcA points to the first input vector
  3263. * @param[in] pSrcB points to the second input vector
  3264. * @param[in] blockSize number of samples in each vector
  3265. * @param[out] result output result returned here
  3266. */
  3267. void arm_dot_prod_q31(
  3268. const q31_t * pSrcA,
  3269. const q31_t * pSrcB,
  3270. uint32_t blockSize,
  3271. q63_t * result);
  3272. /**
  3273. * @brief Shifts the elements of a Q7 vector a specified number of bits.
  3274. * @param[in] pSrc points to the input vector
  3275. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  3276. * @param[out] pDst points to the output vector
  3277. * @param[in] blockSize number of samples in the vector
  3278. */
  3279. void arm_shift_q7(
  3280. const q7_t * pSrc,
  3281. int8_t shiftBits,
  3282. q7_t * pDst,
  3283. uint32_t blockSize);
  3284. /**
  3285. * @brief Shifts the elements of a Q15 vector a specified number of bits.
  3286. * @param[in] pSrc points to the input vector
  3287. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  3288. * @param[out] pDst points to the output vector
  3289. * @param[in] blockSize number of samples in the vector
  3290. */
  3291. void arm_shift_q15(
  3292. const q15_t * pSrc,
  3293. int8_t shiftBits,
  3294. q15_t * pDst,
  3295. uint32_t blockSize);
  3296. /**
  3297. * @brief Shifts the elements of a Q31 vector a specified number of bits.
  3298. * @param[in] pSrc points to the input vector
  3299. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  3300. * @param[out] pDst points to the output vector
  3301. * @param[in] blockSize number of samples in the vector
  3302. */
  3303. void arm_shift_q31(
  3304. const q31_t * pSrc,
  3305. int8_t shiftBits,
  3306. q31_t * pDst,
  3307. uint32_t blockSize);
  3308. /**
  3309. * @brief Adds a constant offset to a floating-point vector.
  3310. * @param[in] pSrc points to the input vector
  3311. * @param[in] offset is the offset to be added
  3312. * @param[out] pDst points to the output vector
  3313. * @param[in] blockSize number of samples in the vector
  3314. */
  3315. void arm_offset_f32(
  3316. const float32_t * pSrc,
  3317. float32_t offset,
  3318. float32_t * pDst,
  3319. uint32_t blockSize);
  3320. /**
  3321. * @brief Adds a constant offset to a Q7 vector.
  3322. * @param[in] pSrc points to the input vector
  3323. * @param[in] offset is the offset to be added
  3324. * @param[out] pDst points to the output vector
  3325. * @param[in] blockSize number of samples in the vector
  3326. */
  3327. void arm_offset_q7(
  3328. const q7_t * pSrc,
  3329. q7_t offset,
  3330. q7_t * pDst,
  3331. uint32_t blockSize);
  3332. /**
  3333. * @brief Adds a constant offset to a Q15 vector.
  3334. * @param[in] pSrc points to the input vector
  3335. * @param[in] offset is the offset to be added
  3336. * @param[out] pDst points to the output vector
  3337. * @param[in] blockSize number of samples in the vector
  3338. */
  3339. void arm_offset_q15(
  3340. const q15_t * pSrc,
  3341. q15_t offset,
  3342. q15_t * pDst,
  3343. uint32_t blockSize);
  3344. /**
  3345. * @brief Adds a constant offset to a Q31 vector.
  3346. * @param[in] pSrc points to the input vector
  3347. * @param[in] offset is the offset to be added
  3348. * @param[out] pDst points to the output vector
  3349. * @param[in] blockSize number of samples in the vector
  3350. */
  3351. void arm_offset_q31(
  3352. const q31_t * pSrc,
  3353. q31_t offset,
  3354. q31_t * pDst,
  3355. uint32_t blockSize);
  3356. /**
  3357. * @brief Negates the elements of a floating-point vector.
  3358. * @param[in] pSrc points to the input vector
  3359. * @param[out] pDst points to the output vector
  3360. * @param[in] blockSize number of samples in the vector
  3361. */
  3362. void arm_negate_f32(
  3363. const float32_t * pSrc,
  3364. float32_t * pDst,
  3365. uint32_t blockSize);
  3366. /**
  3367. * @brief Negates the elements of a Q7 vector.
  3368. * @param[in] pSrc points to the input vector
  3369. * @param[out] pDst points to the output vector
  3370. * @param[in] blockSize number of samples in the vector
  3371. */
  3372. void arm_negate_q7(
  3373. const q7_t * pSrc,
  3374. q7_t * pDst,
  3375. uint32_t blockSize);
  3376. /**
  3377. * @brief Negates the elements of a Q15 vector.
  3378. * @param[in] pSrc points to the input vector
  3379. * @param[out] pDst points to the output vector
  3380. * @param[in] blockSize number of samples in the vector
  3381. */
  3382. void arm_negate_q15(
  3383. const q15_t * pSrc,
  3384. q15_t * pDst,
  3385. uint32_t blockSize);
  3386. /**
  3387. * @brief Negates the elements of a Q31 vector.
  3388. * @param[in] pSrc points to the input vector
  3389. * @param[out] pDst points to the output vector
  3390. * @param[in] blockSize number of samples in the vector
  3391. */
  3392. void arm_negate_q31(
  3393. const q31_t * pSrc,
  3394. q31_t * pDst,
  3395. uint32_t blockSize);
  3396. /**
  3397. * @brief Copies the elements of a floating-point vector.
  3398. * @param[in] pSrc input pointer
  3399. * @param[out] pDst output pointer
  3400. * @param[in] blockSize number of samples to process
  3401. */
  3402. void arm_copy_f32(
  3403. const float32_t * pSrc,
  3404. float32_t * pDst,
  3405. uint32_t blockSize);
  3406. /**
  3407. * @brief Copies the elements of a Q7 vector.
  3408. * @param[in] pSrc input pointer
  3409. * @param[out] pDst output pointer
  3410. * @param[in] blockSize number of samples to process
  3411. */
  3412. void arm_copy_q7(
  3413. const q7_t * pSrc,
  3414. q7_t * pDst,
  3415. uint32_t blockSize);
  3416. /**
  3417. * @brief Copies the elements of a Q15 vector.
  3418. * @param[in] pSrc input pointer
  3419. * @param[out] pDst output pointer
  3420. * @param[in] blockSize number of samples to process
  3421. */
  3422. void arm_copy_q15(
  3423. const q15_t * pSrc,
  3424. q15_t * pDst,
  3425. uint32_t blockSize);
  3426. /**
  3427. * @brief Copies the elements of a Q31 vector.
  3428. * @param[in] pSrc input pointer
  3429. * @param[out] pDst output pointer
  3430. * @param[in] blockSize number of samples to process
  3431. */
  3432. void arm_copy_q31(
  3433. const q31_t * pSrc,
  3434. q31_t * pDst,
  3435. uint32_t blockSize);
  3436. /**
  3437. * @brief Fills a constant value into a floating-point vector.
  3438. * @param[in] value input value to be filled
  3439. * @param[out] pDst output pointer
  3440. * @param[in] blockSize number of samples to process
  3441. */
  3442. void arm_fill_f32(
  3443. float32_t value,
  3444. float32_t * pDst,
  3445. uint32_t blockSize);
  3446. /**
  3447. * @brief Fills a constant value into a Q7 vector.
  3448. * @param[in] value input value to be filled
  3449. * @param[out] pDst output pointer
  3450. * @param[in] blockSize number of samples to process
  3451. */
  3452. void arm_fill_q7(
  3453. q7_t value,
  3454. q7_t * pDst,
  3455. uint32_t blockSize);
  3456. /**
  3457. * @brief Fills a constant value into a Q15 vector.
  3458. * @param[in] value input value to be filled
  3459. * @param[out] pDst output pointer
  3460. * @param[in] blockSize number of samples to process
  3461. */
  3462. void arm_fill_q15(
  3463. q15_t value,
  3464. q15_t * pDst,
  3465. uint32_t blockSize);
  3466. /**
  3467. * @brief Fills a constant value into a Q31 vector.
  3468. * @param[in] value input value to be filled
  3469. * @param[out] pDst output pointer
  3470. * @param[in] blockSize number of samples to process
  3471. */
  3472. void arm_fill_q31(
  3473. q31_t value,
  3474. q31_t * pDst,
  3475. uint32_t blockSize);
  3476. /**
  3477. * @brief Convolution of floating-point sequences.
  3478. * @param[in] pSrcA points to the first input sequence.
  3479. * @param[in] srcALen length of the first input sequence.
  3480. * @param[in] pSrcB points to the second input sequence.
  3481. * @param[in] srcBLen length of the second input sequence.
  3482. * @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1.
  3483. */
  3484. void arm_conv_f32(
  3485. const float32_t * pSrcA,
  3486. uint32_t srcALen,
  3487. const float32_t * pSrcB,
  3488. uint32_t srcBLen,
  3489. float32_t * pDst);
  3490. /**
  3491. * @brief Convolution of Q15 sequences.
  3492. * @param[in] pSrcA points to the first input sequence.
  3493. * @param[in] srcALen length of the first input sequence.
  3494. * @param[in] pSrcB points to the second input sequence.
  3495. * @param[in] srcBLen length of the second input sequence.
  3496. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3497. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3498. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3499. */
  3500. void arm_conv_opt_q15(
  3501. const q15_t * pSrcA,
  3502. uint32_t srcALen,
  3503. const q15_t * pSrcB,
  3504. uint32_t srcBLen,
  3505. q15_t * pDst,
  3506. q15_t * pScratch1,
  3507. q15_t * pScratch2);
  3508. /**
  3509. * @brief Convolution of Q15 sequences.
  3510. * @param[in] pSrcA points to the first input sequence.
  3511. * @param[in] srcALen length of the first input sequence.
  3512. * @param[in] pSrcB points to the second input sequence.
  3513. * @param[in] srcBLen length of the second input sequence.
  3514. * @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1.
  3515. */
  3516. void arm_conv_q15(
  3517. const q15_t * pSrcA,
  3518. uint32_t srcALen,
  3519. const q15_t * pSrcB,
  3520. uint32_t srcBLen,
  3521. q15_t * pDst);
  3522. /**
  3523. * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3524. * @param[in] pSrcA points to the first input sequence.
  3525. * @param[in] srcALen length of the first input sequence.
  3526. * @param[in] pSrcB points to the second input sequence.
  3527. * @param[in] srcBLen length of the second input sequence.
  3528. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3529. */
  3530. void arm_conv_fast_q15(
  3531. const q15_t * pSrcA,
  3532. uint32_t srcALen,
  3533. const q15_t * pSrcB,
  3534. uint32_t srcBLen,
  3535. q15_t * pDst);
  3536. /**
  3537. * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3538. * @param[in] pSrcA points to the first input sequence.
  3539. * @param[in] srcALen length of the first input sequence.
  3540. * @param[in] pSrcB points to the second input sequence.
  3541. * @param[in] srcBLen length of the second input sequence.
  3542. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3543. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3544. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3545. */
  3546. void arm_conv_fast_opt_q15(
  3547. const q15_t * pSrcA,
  3548. uint32_t srcALen,
  3549. const q15_t * pSrcB,
  3550. uint32_t srcBLen,
  3551. q15_t * pDst,
  3552. q15_t * pScratch1,
  3553. q15_t * pScratch2);
  3554. /**
  3555. * @brief Convolution of Q31 sequences.
  3556. * @param[in] pSrcA points to the first input sequence.
  3557. * @param[in] srcALen length of the first input sequence.
  3558. * @param[in] pSrcB points to the second input sequence.
  3559. * @param[in] srcBLen length of the second input sequence.
  3560. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3561. */
  3562. void arm_conv_q31(
  3563. const q31_t * pSrcA,
  3564. uint32_t srcALen,
  3565. const q31_t * pSrcB,
  3566. uint32_t srcBLen,
  3567. q31_t * pDst);
  3568. /**
  3569. * @brief Convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4
  3570. * @param[in] pSrcA points to the first input sequence.
  3571. * @param[in] srcALen length of the first input sequence.
  3572. * @param[in] pSrcB points to the second input sequence.
  3573. * @param[in] srcBLen length of the second input sequence.
  3574. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3575. */
  3576. void arm_conv_fast_q31(
  3577. const q31_t * pSrcA,
  3578. uint32_t srcALen,
  3579. const q31_t * pSrcB,
  3580. uint32_t srcBLen,
  3581. q31_t * pDst);
  3582. /**
  3583. * @brief Convolution of Q7 sequences.
  3584. * @param[in] pSrcA points to the first input sequence.
  3585. * @param[in] srcALen length of the first input sequence.
  3586. * @param[in] pSrcB points to the second input sequence.
  3587. * @param[in] srcBLen length of the second input sequence.
  3588. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3589. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3590. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen).
  3591. */
  3592. void arm_conv_opt_q7(
  3593. const q7_t * pSrcA,
  3594. uint32_t srcALen,
  3595. const q7_t * pSrcB,
  3596. uint32_t srcBLen,
  3597. q7_t * pDst,
  3598. q15_t * pScratch1,
  3599. q15_t * pScratch2);
  3600. /**
  3601. * @brief Convolution of Q7 sequences.
  3602. * @param[in] pSrcA points to the first input sequence.
  3603. * @param[in] srcALen length of the first input sequence.
  3604. * @param[in] pSrcB points to the second input sequence.
  3605. * @param[in] srcBLen length of the second input sequence.
  3606. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3607. */
  3608. void arm_conv_q7(
  3609. const q7_t * pSrcA,
  3610. uint32_t srcALen,
  3611. const q7_t * pSrcB,
  3612. uint32_t srcBLen,
  3613. q7_t * pDst);
  3614. /**
  3615. * @brief Partial convolution of floating-point sequences.
  3616. * @param[in] pSrcA points to the first input sequence.
  3617. * @param[in] srcALen length of the first input sequence.
  3618. * @param[in] pSrcB points to the second input sequence.
  3619. * @param[in] srcBLen length of the second input sequence.
  3620. * @param[out] pDst points to the block of output data
  3621. * @param[in] firstIndex is the first output sample to start with.
  3622. * @param[in] numPoints is the number of output points to be computed.
  3623. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3624. */
  3625. arm_status arm_conv_partial_f32(
  3626. const float32_t * pSrcA,
  3627. uint32_t srcALen,
  3628. const float32_t * pSrcB,
  3629. uint32_t srcBLen,
  3630. float32_t * pDst,
  3631. uint32_t firstIndex,
  3632. uint32_t numPoints);
  3633. /**
  3634. * @brief Partial convolution of Q15 sequences.
  3635. * @param[in] pSrcA points to the first input sequence.
  3636. * @param[in] srcALen length of the first input sequence.
  3637. * @param[in] pSrcB points to the second input sequence.
  3638. * @param[in] srcBLen length of the second input sequence.
  3639. * @param[out] pDst points to the block of output data
  3640. * @param[in] firstIndex is the first output sample to start with.
  3641. * @param[in] numPoints is the number of output points to be computed.
  3642. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3643. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3644. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3645. */
  3646. arm_status arm_conv_partial_opt_q15(
  3647. const q15_t * pSrcA,
  3648. uint32_t srcALen,
  3649. const q15_t * pSrcB,
  3650. uint32_t srcBLen,
  3651. q15_t * pDst,
  3652. uint32_t firstIndex,
  3653. uint32_t numPoints,
  3654. q15_t * pScratch1,
  3655. q15_t * pScratch2);
  3656. /**
  3657. * @brief Partial convolution of Q15 sequences.
  3658. * @param[in] pSrcA points to the first input sequence.
  3659. * @param[in] srcALen length of the first input sequence.
  3660. * @param[in] pSrcB points to the second input sequence.
  3661. * @param[in] srcBLen length of the second input sequence.
  3662. * @param[out] pDst points to the block of output data
  3663. * @param[in] firstIndex is the first output sample to start with.
  3664. * @param[in] numPoints is the number of output points to be computed.
  3665. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3666. */
  3667. arm_status arm_conv_partial_q15(
  3668. const q15_t * pSrcA,
  3669. uint32_t srcALen,
  3670. const q15_t * pSrcB,
  3671. uint32_t srcBLen,
  3672. q15_t * pDst,
  3673. uint32_t firstIndex,
  3674. uint32_t numPoints);
  3675. /**
  3676. * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3677. * @param[in] pSrcA points to the first input sequence.
  3678. * @param[in] srcALen length of the first input sequence.
  3679. * @param[in] pSrcB points to the second input sequence.
  3680. * @param[in] srcBLen length of the second input sequence.
  3681. * @param[out] pDst points to the block of output data
  3682. * @param[in] firstIndex is the first output sample to start with.
  3683. * @param[in] numPoints is the number of output points to be computed.
  3684. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3685. */
  3686. arm_status arm_conv_partial_fast_q15(
  3687. const q15_t * pSrcA,
  3688. uint32_t srcALen,
  3689. const q15_t * pSrcB,
  3690. uint32_t srcBLen,
  3691. q15_t * pDst,
  3692. uint32_t firstIndex,
  3693. uint32_t numPoints);
  3694. /**
  3695. * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3696. * @param[in] pSrcA points to the first input sequence.
  3697. * @param[in] srcALen length of the first input sequence.
  3698. * @param[in] pSrcB points to the second input sequence.
  3699. * @param[in] srcBLen length of the second input sequence.
  3700. * @param[out] pDst points to the block of output data
  3701. * @param[in] firstIndex is the first output sample to start with.
  3702. * @param[in] numPoints is the number of output points to be computed.
  3703. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3704. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3705. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3706. */
  3707. arm_status arm_conv_partial_fast_opt_q15(
  3708. const q15_t * pSrcA,
  3709. uint32_t srcALen,
  3710. const q15_t * pSrcB,
  3711. uint32_t srcBLen,
  3712. q15_t * pDst,
  3713. uint32_t firstIndex,
  3714. uint32_t numPoints,
  3715. q15_t * pScratch1,
  3716. q15_t * pScratch2);
  3717. /**
  3718. * @brief Partial convolution of Q31 sequences.
  3719. * @param[in] pSrcA points to the first input sequence.
  3720. * @param[in] srcALen length of the first input sequence.
  3721. * @param[in] pSrcB points to the second input sequence.
  3722. * @param[in] srcBLen length of the second input sequence.
  3723. * @param[out] pDst points to the block of output data
  3724. * @param[in] firstIndex is the first output sample to start with.
  3725. * @param[in] numPoints is the number of output points to be computed.
  3726. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3727. */
  3728. arm_status arm_conv_partial_q31(
  3729. const q31_t * pSrcA,
  3730. uint32_t srcALen,
  3731. const q31_t * pSrcB,
  3732. uint32_t srcBLen,
  3733. q31_t * pDst,
  3734. uint32_t firstIndex,
  3735. uint32_t numPoints);
  3736. /**
  3737. * @brief Partial convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4
  3738. * @param[in] pSrcA points to the first input sequence.
  3739. * @param[in] srcALen length of the first input sequence.
  3740. * @param[in] pSrcB points to the second input sequence.
  3741. * @param[in] srcBLen length of the second input sequence.
  3742. * @param[out] pDst points to the block of output data
  3743. * @param[in] firstIndex is the first output sample to start with.
  3744. * @param[in] numPoints is the number of output points to be computed.
  3745. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3746. */
  3747. arm_status arm_conv_partial_fast_q31(
  3748. const q31_t * pSrcA,
  3749. uint32_t srcALen,
  3750. const q31_t * pSrcB,
  3751. uint32_t srcBLen,
  3752. q31_t * pDst,
  3753. uint32_t firstIndex,
  3754. uint32_t numPoints);
  3755. /**
  3756. * @brief Partial convolution of Q7 sequences
  3757. * @param[in] pSrcA points to the first input sequence.
  3758. * @param[in] srcALen length of the first input sequence.
  3759. * @param[in] pSrcB points to the second input sequence.
  3760. * @param[in] srcBLen length of the second input sequence.
  3761. * @param[out] pDst points to the block of output data
  3762. * @param[in] firstIndex is the first output sample to start with.
  3763. * @param[in] numPoints is the number of output points to be computed.
  3764. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3765. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen).
  3766. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3767. */
  3768. arm_status arm_conv_partial_opt_q7(
  3769. const q7_t * pSrcA,
  3770. uint32_t srcALen,
  3771. const q7_t * pSrcB,
  3772. uint32_t srcBLen,
  3773. q7_t * pDst,
  3774. uint32_t firstIndex,
  3775. uint32_t numPoints,
  3776. q15_t * pScratch1,
  3777. q15_t * pScratch2);
  3778. /**
  3779. * @brief Partial convolution of Q7 sequences.
  3780. * @param[in] pSrcA points to the first input sequence.
  3781. * @param[in] srcALen length of the first input sequence.
  3782. * @param[in] pSrcB points to the second input sequence.
  3783. * @param[in] srcBLen length of the second input sequence.
  3784. * @param[out] pDst points to the block of output data
  3785. * @param[in] firstIndex is the first output sample to start with.
  3786. * @param[in] numPoints is the number of output points to be computed.
  3787. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3788. */
  3789. arm_status arm_conv_partial_q7(
  3790. const q7_t * pSrcA,
  3791. uint32_t srcALen,
  3792. const q7_t * pSrcB,
  3793. uint32_t srcBLen,
  3794. q7_t * pDst,
  3795. uint32_t firstIndex,
  3796. uint32_t numPoints);
  3797. /**
  3798. * @brief Instance structure for the Q15 FIR decimator.
  3799. */
  3800. typedef struct
  3801. {
  3802. uint8_t M; /**< decimation factor. */
  3803. uint16_t numTaps; /**< number of coefficients in the filter. */
  3804. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  3805. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  3806. } arm_fir_decimate_instance_q15;
  3807. /**
  3808. * @brief Instance structure for the Q31 FIR decimator.
  3809. */
  3810. typedef struct
  3811. {
  3812. uint8_t M; /**< decimation factor. */
  3813. uint16_t numTaps; /**< number of coefficients in the filter. */
  3814. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  3815. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  3816. } arm_fir_decimate_instance_q31;
  3817. /**
  3818. @brief Instance structure for floating-point FIR decimator.
  3819. */
  3820. typedef struct
  3821. {
  3822. uint8_t M; /**< decimation factor. */
  3823. uint16_t numTaps; /**< number of coefficients in the filter. */
  3824. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  3825. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  3826. } arm_fir_decimate_instance_f32;
  3827. /**
  3828. @brief Processing function for floating-point FIR decimator.
  3829. @param[in] S points to an instance of the floating-point FIR decimator structure
  3830. @param[in] pSrc points to the block of input data
  3831. @param[out] pDst points to the block of output data
  3832. @param[in] blockSize number of samples to process
  3833. */
  3834. void arm_fir_decimate_f32(
  3835. const arm_fir_decimate_instance_f32 * S,
  3836. const float32_t * pSrc,
  3837. float32_t * pDst,
  3838. uint32_t blockSize);
  3839. /**
  3840. @brief Initialization function for the floating-point FIR decimator.
  3841. @param[in,out] S points to an instance of the floating-point FIR decimator structure
  3842. @param[in] numTaps number of coefficients in the filter
  3843. @param[in] M decimation factor
  3844. @param[in] pCoeffs points to the filter coefficients
  3845. @param[in] pState points to the state buffer
  3846. @param[in] blockSize number of input samples to process per call
  3847. @return execution status
  3848. - \ref ARM_MATH_SUCCESS : Operation successful
  3849. - \ref ARM_MATH_LENGTH_ERROR : <code>blockSize</code> is not a multiple of <code>M</code>
  3850. */
  3851. arm_status arm_fir_decimate_init_f32(
  3852. arm_fir_decimate_instance_f32 * S,
  3853. uint16_t numTaps,
  3854. uint8_t M,
  3855. const float32_t * pCoeffs,
  3856. float32_t * pState,
  3857. uint32_t blockSize);
  3858. /**
  3859. * @brief Processing function for the Q15 FIR decimator.
  3860. * @param[in] S points to an instance of the Q15 FIR decimator structure.
  3861. * @param[in] pSrc points to the block of input data.
  3862. * @param[out] pDst points to the block of output data
  3863. * @param[in] blockSize number of input samples to process per call.
  3864. */
  3865. void arm_fir_decimate_q15(
  3866. const arm_fir_decimate_instance_q15 * S,
  3867. const q15_t * pSrc,
  3868. q15_t * pDst,
  3869. uint32_t blockSize);
  3870. /**
  3871. * @brief Processing function for the Q15 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4.
  3872. * @param[in] S points to an instance of the Q15 FIR decimator structure.
  3873. * @param[in] pSrc points to the block of input data.
  3874. * @param[out] pDst points to the block of output data
  3875. * @param[in] blockSize number of input samples to process per call.
  3876. */
  3877. void arm_fir_decimate_fast_q15(
  3878. const arm_fir_decimate_instance_q15 * S,
  3879. const q15_t * pSrc,
  3880. q15_t * pDst,
  3881. uint32_t blockSize);
  3882. /**
  3883. * @brief Initialization function for the Q15 FIR decimator.
  3884. * @param[in,out] S points to an instance of the Q15 FIR decimator structure.
  3885. * @param[in] numTaps number of coefficients in the filter.
  3886. * @param[in] M decimation factor.
  3887. * @param[in] pCoeffs points to the filter coefficients.
  3888. * @param[in] pState points to the state buffer.
  3889. * @param[in] blockSize number of input samples to process per call.
  3890. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  3891. * <code>blockSize</code> is not a multiple of <code>M</code>.
  3892. */
  3893. arm_status arm_fir_decimate_init_q15(
  3894. arm_fir_decimate_instance_q15 * S,
  3895. uint16_t numTaps,
  3896. uint8_t M,
  3897. const q15_t * pCoeffs,
  3898. q15_t * pState,
  3899. uint32_t blockSize);
  3900. /**
  3901. * @brief Processing function for the Q31 FIR decimator.
  3902. * @param[in] S points to an instance of the Q31 FIR decimator structure.
  3903. * @param[in] pSrc points to the block of input data.
  3904. * @param[out] pDst points to the block of output data
  3905. * @param[in] blockSize number of input samples to process per call.
  3906. */
  3907. void arm_fir_decimate_q31(
  3908. const arm_fir_decimate_instance_q31 * S,
  3909. const q31_t * pSrc,
  3910. q31_t * pDst,
  3911. uint32_t blockSize);
  3912. /**
  3913. * @brief Processing function for the Q31 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4.
  3914. * @param[in] S points to an instance of the Q31 FIR decimator structure.
  3915. * @param[in] pSrc points to the block of input data.
  3916. * @param[out] pDst points to the block of output data
  3917. * @param[in] blockSize number of input samples to process per call.
  3918. */
  3919. void arm_fir_decimate_fast_q31(
  3920. const arm_fir_decimate_instance_q31 * S,
  3921. const q31_t * pSrc,
  3922. q31_t * pDst,
  3923. uint32_t blockSize);
  3924. /**
  3925. * @brief Initialization function for the Q31 FIR decimator.
  3926. * @param[in,out] S points to an instance of the Q31 FIR decimator structure.
  3927. * @param[in] numTaps number of coefficients in the filter.
  3928. * @param[in] M decimation factor.
  3929. * @param[in] pCoeffs points to the filter coefficients.
  3930. * @param[in] pState points to the state buffer.
  3931. * @param[in] blockSize number of input samples to process per call.
  3932. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  3933. * <code>blockSize</code> is not a multiple of <code>M</code>.
  3934. */
  3935. arm_status arm_fir_decimate_init_q31(
  3936. arm_fir_decimate_instance_q31 * S,
  3937. uint16_t numTaps,
  3938. uint8_t M,
  3939. const q31_t * pCoeffs,
  3940. q31_t * pState,
  3941. uint32_t blockSize);
  3942. /**
  3943. * @brief Instance structure for the Q15 FIR interpolator.
  3944. */
  3945. typedef struct
  3946. {
  3947. uint8_t L; /**< upsample factor. */
  3948. uint16_t phaseLength; /**< length of each polyphase filter component. */
  3949. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */
  3950. q15_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */
  3951. } arm_fir_interpolate_instance_q15;
  3952. /**
  3953. * @brief Instance structure for the Q31 FIR interpolator.
  3954. */
  3955. typedef struct
  3956. {
  3957. uint8_t L; /**< upsample factor. */
  3958. uint16_t phaseLength; /**< length of each polyphase filter component. */
  3959. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */
  3960. q31_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */
  3961. } arm_fir_interpolate_instance_q31;
  3962. /**
  3963. * @brief Instance structure for the floating-point FIR interpolator.
  3964. */
  3965. typedef struct
  3966. {
  3967. uint8_t L; /**< upsample factor. */
  3968. uint16_t phaseLength; /**< length of each polyphase filter component. */
  3969. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */
  3970. float32_t *pState; /**< points to the state variable array. The array is of length phaseLength+numTaps-1. */
  3971. } arm_fir_interpolate_instance_f32;
  3972. /**
  3973. * @brief Processing function for the Q15 FIR interpolator.
  3974. * @param[in] S points to an instance of the Q15 FIR interpolator structure.
  3975. * @param[in] pSrc points to the block of input data.
  3976. * @param[out] pDst points to the block of output data.
  3977. * @param[in] blockSize number of input samples to process per call.
  3978. */
  3979. void arm_fir_interpolate_q15(
  3980. const arm_fir_interpolate_instance_q15 * S,
  3981. const q15_t * pSrc,
  3982. q15_t * pDst,
  3983. uint32_t blockSize);
  3984. /**
  3985. * @brief Initialization function for the Q15 FIR interpolator.
  3986. * @param[in,out] S points to an instance of the Q15 FIR interpolator structure.
  3987. * @param[in] L upsample factor.
  3988. * @param[in] numTaps number of filter coefficients in the filter.
  3989. * @param[in] pCoeffs points to the filter coefficient buffer.
  3990. * @param[in] pState points to the state buffer.
  3991. * @param[in] blockSize number of input samples to process per call.
  3992. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  3993. * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>.
  3994. */
  3995. arm_status arm_fir_interpolate_init_q15(
  3996. arm_fir_interpolate_instance_q15 * S,
  3997. uint8_t L,
  3998. uint16_t numTaps,
  3999. const q15_t * pCoeffs,
  4000. q15_t * pState,
  4001. uint32_t blockSize);
  4002. /**
  4003. * @brief Processing function for the Q31 FIR interpolator.
  4004. * @param[in] S points to an instance of the Q15 FIR interpolator structure.
  4005. * @param[in] pSrc points to the block of input data.
  4006. * @param[out] pDst points to the block of output data.
  4007. * @param[in] blockSize number of input samples to process per call.
  4008. */
  4009. void arm_fir_interpolate_q31(
  4010. const arm_fir_interpolate_instance_q31 * S,
  4011. const q31_t * pSrc,
  4012. q31_t * pDst,
  4013. uint32_t blockSize);
  4014. /**
  4015. * @brief Initialization function for the Q31 FIR interpolator.
  4016. * @param[in,out] S points to an instance of the Q31 FIR interpolator structure.
  4017. * @param[in] L upsample factor.
  4018. * @param[in] numTaps number of filter coefficients in the filter.
  4019. * @param[in] pCoeffs points to the filter coefficient buffer.
  4020. * @param[in] pState points to the state buffer.
  4021. * @param[in] blockSize number of input samples to process per call.
  4022. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  4023. * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>.
  4024. */
  4025. arm_status arm_fir_interpolate_init_q31(
  4026. arm_fir_interpolate_instance_q31 * S,
  4027. uint8_t L,
  4028. uint16_t numTaps,
  4029. const q31_t * pCoeffs,
  4030. q31_t * pState,
  4031. uint32_t blockSize);
  4032. /**
  4033. * @brief Processing function for the floating-point FIR interpolator.
  4034. * @param[in] S points to an instance of the floating-point FIR interpolator structure.
  4035. * @param[in] pSrc points to the block of input data.
  4036. * @param[out] pDst points to the block of output data.
  4037. * @param[in] blockSize number of input samples to process per call.
  4038. */
  4039. void arm_fir_interpolate_f32(
  4040. const arm_fir_interpolate_instance_f32 * S,
  4041. const float32_t * pSrc,
  4042. float32_t * pDst,
  4043. uint32_t blockSize);
  4044. /**
  4045. * @brief Initialization function for the floating-point FIR interpolator.
  4046. * @param[in,out] S points to an instance of the floating-point FIR interpolator structure.
  4047. * @param[in] L upsample factor.
  4048. * @param[in] numTaps number of filter coefficients in the filter.
  4049. * @param[in] pCoeffs points to the filter coefficient buffer.
  4050. * @param[in] pState points to the state buffer.
  4051. * @param[in] blockSize number of input samples to process per call.
  4052. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  4053. * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>.
  4054. */
  4055. arm_status arm_fir_interpolate_init_f32(
  4056. arm_fir_interpolate_instance_f32 * S,
  4057. uint8_t L,
  4058. uint16_t numTaps,
  4059. const float32_t * pCoeffs,
  4060. float32_t * pState,
  4061. uint32_t blockSize);
  4062. /**
  4063. * @brief Instance structure for the high precision Q31 Biquad cascade filter.
  4064. */
  4065. typedef struct
  4066. {
  4067. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4068. q63_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */
  4069. const q31_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4070. uint8_t postShift; /**< additional shift, in bits, applied to each output sample. */
  4071. } arm_biquad_cas_df1_32x64_ins_q31;
  4072. /**
  4073. * @param[in] S points to an instance of the high precision Q31 Biquad cascade filter structure.
  4074. * @param[in] pSrc points to the block of input data.
  4075. * @param[out] pDst points to the block of output data
  4076. * @param[in] blockSize number of samples to process.
  4077. */
  4078. void arm_biquad_cas_df1_32x64_q31(
  4079. const arm_biquad_cas_df1_32x64_ins_q31 * S,
  4080. const q31_t * pSrc,
  4081. q31_t * pDst,
  4082. uint32_t blockSize);
  4083. /**
  4084. * @param[in,out] S points to an instance of the high precision Q31 Biquad cascade filter structure.
  4085. * @param[in] numStages number of 2nd order stages in the filter.
  4086. * @param[in] pCoeffs points to the filter coefficients.
  4087. * @param[in] pState points to the state buffer.
  4088. * @param[in] postShift shift to be applied to the output. Varies according to the coefficients format
  4089. */
  4090. void arm_biquad_cas_df1_32x64_init_q31(
  4091. arm_biquad_cas_df1_32x64_ins_q31 * S,
  4092. uint8_t numStages,
  4093. const q31_t * pCoeffs,
  4094. q63_t * pState,
  4095. uint8_t postShift);
  4096. /**
  4097. * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter.
  4098. */
  4099. typedef struct
  4100. {
  4101. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4102. float32_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */
  4103. const float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4104. } arm_biquad_cascade_df2T_instance_f32;
  4105. /**
  4106. * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter.
  4107. */
  4108. typedef struct
  4109. {
  4110. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4111. float32_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */
  4112. const float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4113. } arm_biquad_cascade_stereo_df2T_instance_f32;
  4114. /**
  4115. * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter.
  4116. */
  4117. typedef struct
  4118. {
  4119. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4120. float64_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */
  4121. const float64_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4122. } arm_biquad_cascade_df2T_instance_f64;
  4123. /**
  4124. * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter.
  4125. * @param[in] S points to an instance of the filter data structure.
  4126. * @param[in] pSrc points to the block of input data.
  4127. * @param[out] pDst points to the block of output data
  4128. * @param[in] blockSize number of samples to process.
  4129. */
  4130. void arm_biquad_cascade_df2T_f32(
  4131. const arm_biquad_cascade_df2T_instance_f32 * S,
  4132. const float32_t * pSrc,
  4133. float32_t * pDst,
  4134. uint32_t blockSize);
  4135. /**
  4136. * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. 2 channels
  4137. * @param[in] S points to an instance of the filter data structure.
  4138. * @param[in] pSrc points to the block of input data.
  4139. * @param[out] pDst points to the block of output data
  4140. * @param[in] blockSize number of samples to process.
  4141. */
  4142. void arm_biquad_cascade_stereo_df2T_f32(
  4143. const arm_biquad_cascade_stereo_df2T_instance_f32 * S,
  4144. const float32_t * pSrc,
  4145. float32_t * pDst,
  4146. uint32_t blockSize);
  4147. /**
  4148. * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter.
  4149. * @param[in] S points to an instance of the filter data structure.
  4150. * @param[in] pSrc points to the block of input data.
  4151. * @param[out] pDst points to the block of output data
  4152. * @param[in] blockSize number of samples to process.
  4153. */
  4154. void arm_biquad_cascade_df2T_f64(
  4155. const arm_biquad_cascade_df2T_instance_f64 * S,
  4156. const float64_t * pSrc,
  4157. float64_t * pDst,
  4158. uint32_t blockSize);
  4159. #if defined(ARM_MATH_NEON)
  4160. void arm_biquad_cascade_df2T_compute_coefs_f32(
  4161. arm_biquad_cascade_df2T_instance_f32 * S,
  4162. uint8_t numStages,
  4163. float32_t * pCoeffs);
  4164. #endif
  4165. /**
  4166. * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter.
  4167. * @param[in,out] S points to an instance of the filter data structure.
  4168. * @param[in] numStages number of 2nd order stages in the filter.
  4169. * @param[in] pCoeffs points to the filter coefficients.
  4170. * @param[in] pState points to the state buffer.
  4171. */
  4172. void arm_biquad_cascade_df2T_init_f32(
  4173. arm_biquad_cascade_df2T_instance_f32 * S,
  4174. uint8_t numStages,
  4175. const float32_t * pCoeffs,
  4176. float32_t * pState);
  4177. /**
  4178. * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter.
  4179. * @param[in,out] S points to an instance of the filter data structure.
  4180. * @param[in] numStages number of 2nd order stages in the filter.
  4181. * @param[in] pCoeffs points to the filter coefficients.
  4182. * @param[in] pState points to the state buffer.
  4183. */
  4184. void arm_biquad_cascade_stereo_df2T_init_f32(
  4185. arm_biquad_cascade_stereo_df2T_instance_f32 * S,
  4186. uint8_t numStages,
  4187. const float32_t * pCoeffs,
  4188. float32_t * pState);
  4189. /**
  4190. * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter.
  4191. * @param[in,out] S points to an instance of the filter data structure.
  4192. * @param[in] numStages number of 2nd order stages in the filter.
  4193. * @param[in] pCoeffs points to the filter coefficients.
  4194. * @param[in] pState points to the state buffer.
  4195. */
  4196. void arm_biquad_cascade_df2T_init_f64(
  4197. arm_biquad_cascade_df2T_instance_f64 * S,
  4198. uint8_t numStages,
  4199. const float64_t * pCoeffs,
  4200. float64_t * pState);
  4201. /**
  4202. * @brief Instance structure for the Q15 FIR lattice filter.
  4203. */
  4204. typedef struct
  4205. {
  4206. uint16_t numStages; /**< number of filter stages. */
  4207. q15_t *pState; /**< points to the state variable array. The array is of length numStages. */
  4208. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */
  4209. } arm_fir_lattice_instance_q15;
  4210. /**
  4211. * @brief Instance structure for the Q31 FIR lattice filter.
  4212. */
  4213. typedef struct
  4214. {
  4215. uint16_t numStages; /**< number of filter stages. */
  4216. q31_t *pState; /**< points to the state variable array. The array is of length numStages. */
  4217. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */
  4218. } arm_fir_lattice_instance_q31;
  4219. /**
  4220. * @brief Instance structure for the floating-point FIR lattice filter.
  4221. */
  4222. typedef struct
  4223. {
  4224. uint16_t numStages; /**< number of filter stages. */
  4225. float32_t *pState; /**< points to the state variable array. The array is of length numStages. */
  4226. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */
  4227. } arm_fir_lattice_instance_f32;
  4228. /**
  4229. * @brief Initialization function for the Q15 FIR lattice filter.
  4230. * @param[in] S points to an instance of the Q15 FIR lattice structure.
  4231. * @param[in] numStages number of filter stages.
  4232. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages.
  4233. * @param[in] pState points to the state buffer. The array is of length numStages.
  4234. */
  4235. void arm_fir_lattice_init_q15(
  4236. arm_fir_lattice_instance_q15 * S,
  4237. uint16_t numStages,
  4238. const q15_t * pCoeffs,
  4239. q15_t * pState);
  4240. /**
  4241. * @brief Processing function for the Q15 FIR lattice filter.
  4242. * @param[in] S points to an instance of the Q15 FIR lattice structure.
  4243. * @param[in] pSrc points to the block of input data.
  4244. * @param[out] pDst points to the block of output data.
  4245. * @param[in] blockSize number of samples to process.
  4246. */
  4247. void arm_fir_lattice_q15(
  4248. const arm_fir_lattice_instance_q15 * S,
  4249. const q15_t * pSrc,
  4250. q15_t * pDst,
  4251. uint32_t blockSize);
  4252. /**
  4253. * @brief Initialization function for the Q31 FIR lattice filter.
  4254. * @param[in] S points to an instance of the Q31 FIR lattice structure.
  4255. * @param[in] numStages number of filter stages.
  4256. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages.
  4257. * @param[in] pState points to the state buffer. The array is of length numStages.
  4258. */
  4259. void arm_fir_lattice_init_q31(
  4260. arm_fir_lattice_instance_q31 * S,
  4261. uint16_t numStages,
  4262. const q31_t * pCoeffs,
  4263. q31_t * pState);
  4264. /**
  4265. * @brief Processing function for the Q31 FIR lattice filter.
  4266. * @param[in] S points to an instance of the Q31 FIR lattice structure.
  4267. * @param[in] pSrc points to the block of input data.
  4268. * @param[out] pDst points to the block of output data
  4269. * @param[in] blockSize number of samples to process.
  4270. */
  4271. void arm_fir_lattice_q31(
  4272. const arm_fir_lattice_instance_q31 * S,
  4273. const q31_t * pSrc,
  4274. q31_t * pDst,
  4275. uint32_t blockSize);
  4276. /**
  4277. * @brief Initialization function for the floating-point FIR lattice filter.
  4278. * @param[in] S points to an instance of the floating-point FIR lattice structure.
  4279. * @param[in] numStages number of filter stages.
  4280. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages.
  4281. * @param[in] pState points to the state buffer. The array is of length numStages.
  4282. */
  4283. void arm_fir_lattice_init_f32(
  4284. arm_fir_lattice_instance_f32 * S,
  4285. uint16_t numStages,
  4286. const float32_t * pCoeffs,
  4287. float32_t * pState);
  4288. /**
  4289. * @brief Processing function for the floating-point FIR lattice filter.
  4290. * @param[in] S points to an instance of the floating-point FIR lattice structure.
  4291. * @param[in] pSrc points to the block of input data.
  4292. * @param[out] pDst points to the block of output data
  4293. * @param[in] blockSize number of samples to process.
  4294. */
  4295. void arm_fir_lattice_f32(
  4296. const arm_fir_lattice_instance_f32 * S,
  4297. const float32_t * pSrc,
  4298. float32_t * pDst,
  4299. uint32_t blockSize);
  4300. /**
  4301. * @brief Instance structure for the Q15 IIR lattice filter.
  4302. */
  4303. typedef struct
  4304. {
  4305. uint16_t numStages; /**< number of stages in the filter. */
  4306. q15_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */
  4307. q15_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */
  4308. q15_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */
  4309. } arm_iir_lattice_instance_q15;
  4310. /**
  4311. * @brief Instance structure for the Q31 IIR lattice filter.
  4312. */
  4313. typedef struct
  4314. {
  4315. uint16_t numStages; /**< number of stages in the filter. */
  4316. q31_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */
  4317. q31_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */
  4318. q31_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */
  4319. } arm_iir_lattice_instance_q31;
  4320. /**
  4321. * @brief Instance structure for the floating-point IIR lattice filter.
  4322. */
  4323. typedef struct
  4324. {
  4325. uint16_t numStages; /**< number of stages in the filter. */
  4326. float32_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */
  4327. float32_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */
  4328. float32_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */
  4329. } arm_iir_lattice_instance_f32;
  4330. /**
  4331. * @brief Processing function for the floating-point IIR lattice filter.
  4332. * @param[in] S points to an instance of the floating-point IIR lattice structure.
  4333. * @param[in] pSrc points to the block of input data.
  4334. * @param[out] pDst points to the block of output data.
  4335. * @param[in] blockSize number of samples to process.
  4336. */
  4337. void arm_iir_lattice_f32(
  4338. const arm_iir_lattice_instance_f32 * S,
  4339. const float32_t * pSrc,
  4340. float32_t * pDst,
  4341. uint32_t blockSize);
  4342. /**
  4343. * @brief Initialization function for the floating-point IIR lattice filter.
  4344. * @param[in] S points to an instance of the floating-point IIR lattice structure.
  4345. * @param[in] numStages number of stages in the filter.
  4346. * @param[in] pkCoeffs points to the reflection coefficient buffer. The array is of length numStages.
  4347. * @param[in] pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1.
  4348. * @param[in] pState points to the state buffer. The array is of length numStages+blockSize-1.
  4349. * @param[in] blockSize number of samples to process.
  4350. */
  4351. void arm_iir_lattice_init_f32(
  4352. arm_iir_lattice_instance_f32 * S,
  4353. uint16_t numStages,
  4354. float32_t * pkCoeffs,
  4355. float32_t * pvCoeffs,
  4356. float32_t * pState,
  4357. uint32_t blockSize);
  4358. /**
  4359. * @brief Processing function for the Q31 IIR lattice filter.
  4360. * @param[in] S points to an instance of the Q31 IIR lattice structure.
  4361. * @param[in] pSrc points to the block of input data.
  4362. * @param[out] pDst points to the block of output data.
  4363. * @param[in] blockSize number of samples to process.
  4364. */
  4365. void arm_iir_lattice_q31(
  4366. const arm_iir_lattice_instance_q31 * S,
  4367. const q31_t * pSrc,
  4368. q31_t * pDst,
  4369. uint32_t blockSize);
  4370. /**
  4371. * @brief Initialization function for the Q31 IIR lattice filter.
  4372. * @param[in] S points to an instance of the Q31 IIR lattice structure.
  4373. * @param[in] numStages number of stages in the filter.
  4374. * @param[in] pkCoeffs points to the reflection coefficient buffer. The array is of length numStages.
  4375. * @param[in] pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1.
  4376. * @param[in] pState points to the state buffer. The array is of length numStages+blockSize.
  4377. * @param[in] blockSize number of samples to process.
  4378. */
  4379. void arm_iir_lattice_init_q31(
  4380. arm_iir_lattice_instance_q31 * S,
  4381. uint16_t numStages,
  4382. q31_t * pkCoeffs,
  4383. q31_t * pvCoeffs,
  4384. q31_t * pState,
  4385. uint32_t blockSize);
  4386. /**
  4387. * @brief Processing function for the Q15 IIR lattice filter.
  4388. * @param[in] S points to an instance of the Q15 IIR lattice structure.
  4389. * @param[in] pSrc points to the block of input data.
  4390. * @param[out] pDst points to the block of output data.
  4391. * @param[in] blockSize number of samples to process.
  4392. */
  4393. void arm_iir_lattice_q15(
  4394. const arm_iir_lattice_instance_q15 * S,
  4395. const q15_t * pSrc,
  4396. q15_t * pDst,
  4397. uint32_t blockSize);
  4398. /**
  4399. * @brief Initialization function for the Q15 IIR lattice filter.
  4400. * @param[in] S points to an instance of the fixed-point Q15 IIR lattice structure.
  4401. * @param[in] numStages number of stages in the filter.
  4402. * @param[in] pkCoeffs points to reflection coefficient buffer. The array is of length numStages.
  4403. * @param[in] pvCoeffs points to ladder coefficient buffer. The array is of length numStages+1.
  4404. * @param[in] pState points to state buffer. The array is of length numStages+blockSize.
  4405. * @param[in] blockSize number of samples to process per call.
  4406. */
  4407. void arm_iir_lattice_init_q15(
  4408. arm_iir_lattice_instance_q15 * S,
  4409. uint16_t numStages,
  4410. q15_t * pkCoeffs,
  4411. q15_t * pvCoeffs,
  4412. q15_t * pState,
  4413. uint32_t blockSize);
  4414. /**
  4415. * @brief Instance structure for the floating-point LMS filter.
  4416. */
  4417. typedef struct
  4418. {
  4419. uint16_t numTaps; /**< number of coefficients in the filter. */
  4420. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4421. float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4422. float32_t mu; /**< step size that controls filter coefficient updates. */
  4423. } arm_lms_instance_f32;
  4424. /**
  4425. * @brief Processing function for floating-point LMS filter.
  4426. * @param[in] S points to an instance of the floating-point LMS filter structure.
  4427. * @param[in] pSrc points to the block of input data.
  4428. * @param[in] pRef points to the block of reference data.
  4429. * @param[out] pOut points to the block of output data.
  4430. * @param[out] pErr points to the block of error data.
  4431. * @param[in] blockSize number of samples to process.
  4432. */
  4433. void arm_lms_f32(
  4434. const arm_lms_instance_f32 * S,
  4435. const float32_t * pSrc,
  4436. float32_t * pRef,
  4437. float32_t * pOut,
  4438. float32_t * pErr,
  4439. uint32_t blockSize);
  4440. /**
  4441. * @brief Initialization function for floating-point LMS filter.
  4442. * @param[in] S points to an instance of the floating-point LMS filter structure.
  4443. * @param[in] numTaps number of filter coefficients.
  4444. * @param[in] pCoeffs points to the coefficient buffer.
  4445. * @param[in] pState points to state buffer.
  4446. * @param[in] mu step size that controls filter coefficient updates.
  4447. * @param[in] blockSize number of samples to process.
  4448. */
  4449. void arm_lms_init_f32(
  4450. arm_lms_instance_f32 * S,
  4451. uint16_t numTaps,
  4452. float32_t * pCoeffs,
  4453. float32_t * pState,
  4454. float32_t mu,
  4455. uint32_t blockSize);
  4456. /**
  4457. * @brief Instance structure for the Q15 LMS filter.
  4458. */
  4459. typedef struct
  4460. {
  4461. uint16_t numTaps; /**< number of coefficients in the filter. */
  4462. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4463. q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4464. q15_t mu; /**< step size that controls filter coefficient updates. */
  4465. uint32_t postShift; /**< bit shift applied to coefficients. */
  4466. } arm_lms_instance_q15;
  4467. /**
  4468. * @brief Initialization function for the Q15 LMS filter.
  4469. * @param[in] S points to an instance of the Q15 LMS filter structure.
  4470. * @param[in] numTaps number of filter coefficients.
  4471. * @param[in] pCoeffs points to the coefficient buffer.
  4472. * @param[in] pState points to the state buffer.
  4473. * @param[in] mu step size that controls filter coefficient updates.
  4474. * @param[in] blockSize number of samples to process.
  4475. * @param[in] postShift bit shift applied to coefficients.
  4476. */
  4477. void arm_lms_init_q15(
  4478. arm_lms_instance_q15 * S,
  4479. uint16_t numTaps,
  4480. q15_t * pCoeffs,
  4481. q15_t * pState,
  4482. q15_t mu,
  4483. uint32_t blockSize,
  4484. uint32_t postShift);
  4485. /**
  4486. * @brief Processing function for Q15 LMS filter.
  4487. * @param[in] S points to an instance of the Q15 LMS filter structure.
  4488. * @param[in] pSrc points to the block of input data.
  4489. * @param[in] pRef points to the block of reference data.
  4490. * @param[out] pOut points to the block of output data.
  4491. * @param[out] pErr points to the block of error data.
  4492. * @param[in] blockSize number of samples to process.
  4493. */
  4494. void arm_lms_q15(
  4495. const arm_lms_instance_q15 * S,
  4496. const q15_t * pSrc,
  4497. q15_t * pRef,
  4498. q15_t * pOut,
  4499. q15_t * pErr,
  4500. uint32_t blockSize);
  4501. /**
  4502. * @brief Instance structure for the Q31 LMS filter.
  4503. */
  4504. typedef struct
  4505. {
  4506. uint16_t numTaps; /**< number of coefficients in the filter. */
  4507. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4508. q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4509. q31_t mu; /**< step size that controls filter coefficient updates. */
  4510. uint32_t postShift; /**< bit shift applied to coefficients. */
  4511. } arm_lms_instance_q31;
  4512. /**
  4513. * @brief Processing function for Q31 LMS filter.
  4514. * @param[in] S points to an instance of the Q15 LMS filter structure.
  4515. * @param[in] pSrc points to the block of input data.
  4516. * @param[in] pRef points to the block of reference data.
  4517. * @param[out] pOut points to the block of output data.
  4518. * @param[out] pErr points to the block of error data.
  4519. * @param[in] blockSize number of samples to process.
  4520. */
  4521. void arm_lms_q31(
  4522. const arm_lms_instance_q31 * S,
  4523. const q31_t * pSrc,
  4524. q31_t * pRef,
  4525. q31_t * pOut,
  4526. q31_t * pErr,
  4527. uint32_t blockSize);
  4528. /**
  4529. * @brief Initialization function for Q31 LMS filter.
  4530. * @param[in] S points to an instance of the Q31 LMS filter structure.
  4531. * @param[in] numTaps number of filter coefficients.
  4532. * @param[in] pCoeffs points to coefficient buffer.
  4533. * @param[in] pState points to state buffer.
  4534. * @param[in] mu step size that controls filter coefficient updates.
  4535. * @param[in] blockSize number of samples to process.
  4536. * @param[in] postShift bit shift applied to coefficients.
  4537. */
  4538. void arm_lms_init_q31(
  4539. arm_lms_instance_q31 * S,
  4540. uint16_t numTaps,
  4541. q31_t * pCoeffs,
  4542. q31_t * pState,
  4543. q31_t mu,
  4544. uint32_t blockSize,
  4545. uint32_t postShift);
  4546. /**
  4547. * @brief Instance structure for the floating-point normalized LMS filter.
  4548. */
  4549. typedef struct
  4550. {
  4551. uint16_t numTaps; /**< number of coefficients in the filter. */
  4552. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4553. float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4554. float32_t mu; /**< step size that control filter coefficient updates. */
  4555. float32_t energy; /**< saves previous frame energy. */
  4556. float32_t x0; /**< saves previous input sample. */
  4557. } arm_lms_norm_instance_f32;
  4558. /**
  4559. * @brief Processing function for floating-point normalized LMS filter.
  4560. * @param[in] S points to an instance of the floating-point normalized LMS filter structure.
  4561. * @param[in] pSrc points to the block of input data.
  4562. * @param[in] pRef points to the block of reference data.
  4563. * @param[out] pOut points to the block of output data.
  4564. * @param[out] pErr points to the block of error data.
  4565. * @param[in] blockSize number of samples to process.
  4566. */
  4567. void arm_lms_norm_f32(
  4568. arm_lms_norm_instance_f32 * S,
  4569. const float32_t * pSrc,
  4570. float32_t * pRef,
  4571. float32_t * pOut,
  4572. float32_t * pErr,
  4573. uint32_t blockSize);
  4574. /**
  4575. * @brief Initialization function for floating-point normalized LMS filter.
  4576. * @param[in] S points to an instance of the floating-point LMS filter structure.
  4577. * @param[in] numTaps number of filter coefficients.
  4578. * @param[in] pCoeffs points to coefficient buffer.
  4579. * @param[in] pState points to state buffer.
  4580. * @param[in] mu step size that controls filter coefficient updates.
  4581. * @param[in] blockSize number of samples to process.
  4582. */
  4583. void arm_lms_norm_init_f32(
  4584. arm_lms_norm_instance_f32 * S,
  4585. uint16_t numTaps,
  4586. float32_t * pCoeffs,
  4587. float32_t * pState,
  4588. float32_t mu,
  4589. uint32_t blockSize);
  4590. /**
  4591. * @brief Instance structure for the Q31 normalized LMS filter.
  4592. */
  4593. typedef struct
  4594. {
  4595. uint16_t numTaps; /**< number of coefficients in the filter. */
  4596. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4597. q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4598. q31_t mu; /**< step size that controls filter coefficient updates. */
  4599. uint8_t postShift; /**< bit shift applied to coefficients. */
  4600. const q31_t *recipTable; /**< points to the reciprocal initial value table. */
  4601. q31_t energy; /**< saves previous frame energy. */
  4602. q31_t x0; /**< saves previous input sample. */
  4603. } arm_lms_norm_instance_q31;
  4604. /**
  4605. * @brief Processing function for Q31 normalized LMS filter.
  4606. * @param[in] S points to an instance of the Q31 normalized LMS filter structure.
  4607. * @param[in] pSrc points to the block of input data.
  4608. * @param[in] pRef points to the block of reference data.
  4609. * @param[out] pOut points to the block of output data.
  4610. * @param[out] pErr points to the block of error data.
  4611. * @param[in] blockSize number of samples to process.
  4612. */
  4613. void arm_lms_norm_q31(
  4614. arm_lms_norm_instance_q31 * S,
  4615. const q31_t * pSrc,
  4616. q31_t * pRef,
  4617. q31_t * pOut,
  4618. q31_t * pErr,
  4619. uint32_t blockSize);
  4620. /**
  4621. * @brief Initialization function for Q31 normalized LMS filter.
  4622. * @param[in] S points to an instance of the Q31 normalized LMS filter structure.
  4623. * @param[in] numTaps number of filter coefficients.
  4624. * @param[in] pCoeffs points to coefficient buffer.
  4625. * @param[in] pState points to state buffer.
  4626. * @param[in] mu step size that controls filter coefficient updates.
  4627. * @param[in] blockSize number of samples to process.
  4628. * @param[in] postShift bit shift applied to coefficients.
  4629. */
  4630. void arm_lms_norm_init_q31(
  4631. arm_lms_norm_instance_q31 * S,
  4632. uint16_t numTaps,
  4633. q31_t * pCoeffs,
  4634. q31_t * pState,
  4635. q31_t mu,
  4636. uint32_t blockSize,
  4637. uint8_t postShift);
  4638. /**
  4639. * @brief Instance structure for the Q15 normalized LMS filter.
  4640. */
  4641. typedef struct
  4642. {
  4643. uint16_t numTaps; /**< Number of coefficients in the filter. */
  4644. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4645. q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4646. q15_t mu; /**< step size that controls filter coefficient updates. */
  4647. uint8_t postShift; /**< bit shift applied to coefficients. */
  4648. const q15_t *recipTable; /**< Points to the reciprocal initial value table. */
  4649. q15_t energy; /**< saves previous frame energy. */
  4650. q15_t x0; /**< saves previous input sample. */
  4651. } arm_lms_norm_instance_q15;
  4652. /**
  4653. * @brief Processing function for Q15 normalized LMS filter.
  4654. * @param[in] S points to an instance of the Q15 normalized LMS filter structure.
  4655. * @param[in] pSrc points to the block of input data.
  4656. * @param[in] pRef points to the block of reference data.
  4657. * @param[out] pOut points to the block of output data.
  4658. * @param[out] pErr points to the block of error data.
  4659. * @param[in] blockSize number of samples to process.
  4660. */
  4661. void arm_lms_norm_q15(
  4662. arm_lms_norm_instance_q15 * S,
  4663. const q15_t * pSrc,
  4664. q15_t * pRef,
  4665. q15_t * pOut,
  4666. q15_t * pErr,
  4667. uint32_t blockSize);
  4668. /**
  4669. * @brief Initialization function for Q15 normalized LMS filter.
  4670. * @param[in] S points to an instance of the Q15 normalized LMS filter structure.
  4671. * @param[in] numTaps number of filter coefficients.
  4672. * @param[in] pCoeffs points to coefficient buffer.
  4673. * @param[in] pState points to state buffer.
  4674. * @param[in] mu step size that controls filter coefficient updates.
  4675. * @param[in] blockSize number of samples to process.
  4676. * @param[in] postShift bit shift applied to coefficients.
  4677. */
  4678. void arm_lms_norm_init_q15(
  4679. arm_lms_norm_instance_q15 * S,
  4680. uint16_t numTaps,
  4681. q15_t * pCoeffs,
  4682. q15_t * pState,
  4683. q15_t mu,
  4684. uint32_t blockSize,
  4685. uint8_t postShift);
  4686. /**
  4687. * @brief Correlation of floating-point sequences.
  4688. * @param[in] pSrcA points to the first input sequence.
  4689. * @param[in] srcALen length of the first input sequence.
  4690. * @param[in] pSrcB points to the second input sequence.
  4691. * @param[in] srcBLen length of the second input sequence.
  4692. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4693. */
  4694. void arm_correlate_f32(
  4695. const float32_t * pSrcA,
  4696. uint32_t srcALen,
  4697. const float32_t * pSrcB,
  4698. uint32_t srcBLen,
  4699. float32_t * pDst);
  4700. /**
  4701. @brief Correlation of Q15 sequences
  4702. @param[in] pSrcA points to the first input sequence
  4703. @param[in] srcALen length of the first input sequence
  4704. @param[in] pSrcB points to the second input sequence
  4705. @param[in] srcBLen length of the second input sequence
  4706. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4707. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  4708. */
  4709. void arm_correlate_opt_q15(
  4710. const q15_t * pSrcA,
  4711. uint32_t srcALen,
  4712. const q15_t * pSrcB,
  4713. uint32_t srcBLen,
  4714. q15_t * pDst,
  4715. q15_t * pScratch);
  4716. /**
  4717. @brief Correlation of Q15 sequences.
  4718. @param[in] pSrcA points to the first input sequence
  4719. @param[in] srcALen length of the first input sequence
  4720. @param[in] pSrcB points to the second input sequence
  4721. @param[in] srcBLen length of the second input sequence
  4722. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4723. */
  4724. void arm_correlate_q15(
  4725. const q15_t * pSrcA,
  4726. uint32_t srcALen,
  4727. const q15_t * pSrcB,
  4728. uint32_t srcBLen,
  4729. q15_t * pDst);
  4730. /**
  4731. @brief Correlation of Q15 sequences (fast version).
  4732. @param[in] pSrcA points to the first input sequence
  4733. @param[in] srcALen length of the first input sequence
  4734. @param[in] pSrcB points to the second input sequence
  4735. @param[in] srcBLen length of the second input sequence
  4736. @param[out] pDst points to the location where the output result is written. Length 2 * max(srcALen, srcBLen) - 1.
  4737. @return none
  4738. */
  4739. void arm_correlate_fast_q15(
  4740. const q15_t * pSrcA,
  4741. uint32_t srcALen,
  4742. const q15_t * pSrcB,
  4743. uint32_t srcBLen,
  4744. q15_t * pDst);
  4745. /**
  4746. @brief Correlation of Q15 sequences (fast version).
  4747. @param[in] pSrcA points to the first input sequence.
  4748. @param[in] srcALen length of the first input sequence.
  4749. @param[in] pSrcB points to the second input sequence.
  4750. @param[in] srcBLen length of the second input sequence.
  4751. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4752. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  4753. */
  4754. void arm_correlate_fast_opt_q15(
  4755. const q15_t * pSrcA,
  4756. uint32_t srcALen,
  4757. const q15_t * pSrcB,
  4758. uint32_t srcBLen,
  4759. q15_t * pDst,
  4760. q15_t * pScratch);
  4761. /**
  4762. * @brief Correlation of Q31 sequences.
  4763. * @param[in] pSrcA points to the first input sequence.
  4764. * @param[in] srcALen length of the first input sequence.
  4765. * @param[in] pSrcB points to the second input sequence.
  4766. * @param[in] srcBLen length of the second input sequence.
  4767. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4768. */
  4769. void arm_correlate_q31(
  4770. const q31_t * pSrcA,
  4771. uint32_t srcALen,
  4772. const q31_t * pSrcB,
  4773. uint32_t srcBLen,
  4774. q31_t * pDst);
  4775. /**
  4776. @brief Correlation of Q31 sequences (fast version).
  4777. @param[in] pSrcA points to the first input sequence
  4778. @param[in] srcALen length of the first input sequence
  4779. @param[in] pSrcB points to the second input sequence
  4780. @param[in] srcBLen length of the second input sequence
  4781. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4782. */
  4783. void arm_correlate_fast_q31(
  4784. const q31_t * pSrcA,
  4785. uint32_t srcALen,
  4786. const q31_t * pSrcB,
  4787. uint32_t srcBLen,
  4788. q31_t * pDst);
  4789. /**
  4790. * @brief Correlation of Q7 sequences.
  4791. * @param[in] pSrcA points to the first input sequence.
  4792. * @param[in] srcALen length of the first input sequence.
  4793. * @param[in] pSrcB points to the second input sequence.
  4794. * @param[in] srcBLen length of the second input sequence.
  4795. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4796. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  4797. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen).
  4798. */
  4799. void arm_correlate_opt_q7(
  4800. const q7_t * pSrcA,
  4801. uint32_t srcALen,
  4802. const q7_t * pSrcB,
  4803. uint32_t srcBLen,
  4804. q7_t * pDst,
  4805. q15_t * pScratch1,
  4806. q15_t * pScratch2);
  4807. /**
  4808. * @brief Correlation of Q7 sequences.
  4809. * @param[in] pSrcA points to the first input sequence.
  4810. * @param[in] srcALen length of the first input sequence.
  4811. * @param[in] pSrcB points to the second input sequence.
  4812. * @param[in] srcBLen length of the second input sequence.
  4813. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4814. */
  4815. void arm_correlate_q7(
  4816. const q7_t * pSrcA,
  4817. uint32_t srcALen,
  4818. const q7_t * pSrcB,
  4819. uint32_t srcBLen,
  4820. q7_t * pDst);
  4821. /**
  4822. * @brief Instance structure for the floating-point sparse FIR filter.
  4823. */
  4824. typedef struct
  4825. {
  4826. uint16_t numTaps; /**< number of coefficients in the filter. */
  4827. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4828. float32_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4829. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4830. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4831. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4832. } arm_fir_sparse_instance_f32;
  4833. /**
  4834. * @brief Instance structure for the Q31 sparse FIR filter.
  4835. */
  4836. typedef struct
  4837. {
  4838. uint16_t numTaps; /**< number of coefficients in the filter. */
  4839. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4840. q31_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4841. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4842. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4843. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4844. } arm_fir_sparse_instance_q31;
  4845. /**
  4846. * @brief Instance structure for the Q15 sparse FIR filter.
  4847. */
  4848. typedef struct
  4849. {
  4850. uint16_t numTaps; /**< number of coefficients in the filter. */
  4851. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4852. q15_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4853. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4854. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4855. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4856. } arm_fir_sparse_instance_q15;
  4857. /**
  4858. * @brief Instance structure for the Q7 sparse FIR filter.
  4859. */
  4860. typedef struct
  4861. {
  4862. uint16_t numTaps; /**< number of coefficients in the filter. */
  4863. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4864. q7_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4865. const q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4866. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4867. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4868. } arm_fir_sparse_instance_q7;
  4869. /**
  4870. * @brief Processing function for the floating-point sparse FIR filter.
  4871. * @param[in] S points to an instance of the floating-point sparse FIR structure.
  4872. * @param[in] pSrc points to the block of input data.
  4873. * @param[out] pDst points to the block of output data
  4874. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4875. * @param[in] blockSize number of input samples to process per call.
  4876. */
  4877. void arm_fir_sparse_f32(
  4878. arm_fir_sparse_instance_f32 * S,
  4879. const float32_t * pSrc,
  4880. float32_t * pDst,
  4881. float32_t * pScratchIn,
  4882. uint32_t blockSize);
  4883. /**
  4884. * @brief Initialization function for the floating-point sparse FIR filter.
  4885. * @param[in,out] S points to an instance of the floating-point sparse FIR structure.
  4886. * @param[in] numTaps number of nonzero coefficients in the filter.
  4887. * @param[in] pCoeffs points to the array of filter coefficients.
  4888. * @param[in] pState points to the state buffer.
  4889. * @param[in] pTapDelay points to the array of offset times.
  4890. * @param[in] maxDelay maximum offset time supported.
  4891. * @param[in] blockSize number of samples that will be processed per block.
  4892. */
  4893. void arm_fir_sparse_init_f32(
  4894. arm_fir_sparse_instance_f32 * S,
  4895. uint16_t numTaps,
  4896. const float32_t * pCoeffs,
  4897. float32_t * pState,
  4898. int32_t * pTapDelay,
  4899. uint16_t maxDelay,
  4900. uint32_t blockSize);
  4901. /**
  4902. * @brief Processing function for the Q31 sparse FIR filter.
  4903. * @param[in] S points to an instance of the Q31 sparse FIR structure.
  4904. * @param[in] pSrc points to the block of input data.
  4905. * @param[out] pDst points to the block of output data
  4906. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4907. * @param[in] blockSize number of input samples to process per call.
  4908. */
  4909. void arm_fir_sparse_q31(
  4910. arm_fir_sparse_instance_q31 * S,
  4911. const q31_t * pSrc,
  4912. q31_t * pDst,
  4913. q31_t * pScratchIn,
  4914. uint32_t blockSize);
  4915. /**
  4916. * @brief Initialization function for the Q31 sparse FIR filter.
  4917. * @param[in,out] S points to an instance of the Q31 sparse FIR structure.
  4918. * @param[in] numTaps number of nonzero coefficients in the filter.
  4919. * @param[in] pCoeffs points to the array of filter coefficients.
  4920. * @param[in] pState points to the state buffer.
  4921. * @param[in] pTapDelay points to the array of offset times.
  4922. * @param[in] maxDelay maximum offset time supported.
  4923. * @param[in] blockSize number of samples that will be processed per block.
  4924. */
  4925. void arm_fir_sparse_init_q31(
  4926. arm_fir_sparse_instance_q31 * S,
  4927. uint16_t numTaps,
  4928. const q31_t * pCoeffs,
  4929. q31_t * pState,
  4930. int32_t * pTapDelay,
  4931. uint16_t maxDelay,
  4932. uint32_t blockSize);
  4933. /**
  4934. * @brief Processing function for the Q15 sparse FIR filter.
  4935. * @param[in] S points to an instance of the Q15 sparse FIR structure.
  4936. * @param[in] pSrc points to the block of input data.
  4937. * @param[out] pDst points to the block of output data
  4938. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4939. * @param[in] pScratchOut points to a temporary buffer of size blockSize.
  4940. * @param[in] blockSize number of input samples to process per call.
  4941. */
  4942. void arm_fir_sparse_q15(
  4943. arm_fir_sparse_instance_q15 * S,
  4944. const q15_t * pSrc,
  4945. q15_t * pDst,
  4946. q15_t * pScratchIn,
  4947. q31_t * pScratchOut,
  4948. uint32_t blockSize);
  4949. /**
  4950. * @brief Initialization function for the Q15 sparse FIR filter.
  4951. * @param[in,out] S points to an instance of the Q15 sparse FIR structure.
  4952. * @param[in] numTaps number of nonzero coefficients in the filter.
  4953. * @param[in] pCoeffs points to the array of filter coefficients.
  4954. * @param[in] pState points to the state buffer.
  4955. * @param[in] pTapDelay points to the array of offset times.
  4956. * @param[in] maxDelay maximum offset time supported.
  4957. * @param[in] blockSize number of samples that will be processed per block.
  4958. */
  4959. void arm_fir_sparse_init_q15(
  4960. arm_fir_sparse_instance_q15 * S,
  4961. uint16_t numTaps,
  4962. const q15_t * pCoeffs,
  4963. q15_t * pState,
  4964. int32_t * pTapDelay,
  4965. uint16_t maxDelay,
  4966. uint32_t blockSize);
  4967. /**
  4968. * @brief Processing function for the Q7 sparse FIR filter.
  4969. * @param[in] S points to an instance of the Q7 sparse FIR structure.
  4970. * @param[in] pSrc points to the block of input data.
  4971. * @param[out] pDst points to the block of output data
  4972. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4973. * @param[in] pScratchOut points to a temporary buffer of size blockSize.
  4974. * @param[in] blockSize number of input samples to process per call.
  4975. */
  4976. void arm_fir_sparse_q7(
  4977. arm_fir_sparse_instance_q7 * S,
  4978. const q7_t * pSrc,
  4979. q7_t * pDst,
  4980. q7_t * pScratchIn,
  4981. q31_t * pScratchOut,
  4982. uint32_t blockSize);
  4983. /**
  4984. * @brief Initialization function for the Q7 sparse FIR filter.
  4985. * @param[in,out] S points to an instance of the Q7 sparse FIR structure.
  4986. * @param[in] numTaps number of nonzero coefficients in the filter.
  4987. * @param[in] pCoeffs points to the array of filter coefficients.
  4988. * @param[in] pState points to the state buffer.
  4989. * @param[in] pTapDelay points to the array of offset times.
  4990. * @param[in] maxDelay maximum offset time supported.
  4991. * @param[in] blockSize number of samples that will be processed per block.
  4992. */
  4993. void arm_fir_sparse_init_q7(
  4994. arm_fir_sparse_instance_q7 * S,
  4995. uint16_t numTaps,
  4996. const q7_t * pCoeffs,
  4997. q7_t * pState,
  4998. int32_t * pTapDelay,
  4999. uint16_t maxDelay,
  5000. uint32_t blockSize);
  5001. /**
  5002. * @brief Floating-point sin_cos function.
  5003. * @param[in] theta input value in degrees
  5004. * @param[out] pSinVal points to the processed sine output.
  5005. * @param[out] pCosVal points to the processed cos output.
  5006. */
  5007. void arm_sin_cos_f32(
  5008. float32_t theta,
  5009. float32_t * pSinVal,
  5010. float32_t * pCosVal);
  5011. /**
  5012. * @brief Q31 sin_cos function.
  5013. * @param[in] theta scaled input value in degrees
  5014. * @param[out] pSinVal points to the processed sine output.
  5015. * @param[out] pCosVal points to the processed cosine output.
  5016. */
  5017. void arm_sin_cos_q31(
  5018. q31_t theta,
  5019. q31_t * pSinVal,
  5020. q31_t * pCosVal);
  5021. /**
  5022. * @brief Floating-point complex conjugate.
  5023. * @param[in] pSrc points to the input vector
  5024. * @param[out] pDst points to the output vector
  5025. * @param[in] numSamples number of complex samples in each vector
  5026. */
  5027. void arm_cmplx_conj_f32(
  5028. const float32_t * pSrc,
  5029. float32_t * pDst,
  5030. uint32_t numSamples);
  5031. /**
  5032. * @brief Q31 complex conjugate.
  5033. * @param[in] pSrc points to the input vector
  5034. * @param[out] pDst points to the output vector
  5035. * @param[in] numSamples number of complex samples in each vector
  5036. */
  5037. void arm_cmplx_conj_q31(
  5038. const q31_t * pSrc,
  5039. q31_t * pDst,
  5040. uint32_t numSamples);
  5041. /**
  5042. * @brief Q15 complex conjugate.
  5043. * @param[in] pSrc points to the input vector
  5044. * @param[out] pDst points to the output vector
  5045. * @param[in] numSamples number of complex samples in each vector
  5046. */
  5047. void arm_cmplx_conj_q15(
  5048. const q15_t * pSrc,
  5049. q15_t * pDst,
  5050. uint32_t numSamples);
  5051. /**
  5052. * @brief Floating-point complex magnitude squared
  5053. * @param[in] pSrc points to the complex input vector
  5054. * @param[out] pDst points to the real output vector
  5055. * @param[in] numSamples number of complex samples in the input vector
  5056. */
  5057. void arm_cmplx_mag_squared_f32(
  5058. const float32_t * pSrc,
  5059. float32_t * pDst,
  5060. uint32_t numSamples);
  5061. /**
  5062. * @brief Q31 complex magnitude squared
  5063. * @param[in] pSrc points to the complex input vector
  5064. * @param[out] pDst points to the real output vector
  5065. * @param[in] numSamples number of complex samples in the input vector
  5066. */
  5067. void arm_cmplx_mag_squared_q31(
  5068. const q31_t * pSrc,
  5069. q31_t * pDst,
  5070. uint32_t numSamples);
  5071. /**
  5072. * @brief Q15 complex magnitude squared
  5073. * @param[in] pSrc points to the complex input vector
  5074. * @param[out] pDst points to the real output vector
  5075. * @param[in] numSamples number of complex samples in the input vector
  5076. */
  5077. void arm_cmplx_mag_squared_q15(
  5078. const q15_t * pSrc,
  5079. q15_t * pDst,
  5080. uint32_t numSamples);
  5081. /**
  5082. * @ingroup groupController
  5083. */
  5084. /**
  5085. * @defgroup PID PID Motor Control
  5086. *
  5087. * A Proportional Integral Derivative (PID) controller is a generic feedback control
  5088. * loop mechanism widely used in industrial control systems.
  5089. * A PID controller is the most commonly used type of feedback controller.
  5090. *
  5091. * This set of functions implements (PID) controllers
  5092. * for Q15, Q31, and floating-point data types. The functions operate on a single sample
  5093. * of data and each call to the function returns a single processed value.
  5094. * <code>S</code> points to an instance of the PID control data structure. <code>in</code>
  5095. * is the input sample value. The functions return the output value.
  5096. *
  5097. * \par Algorithm:
  5098. * <pre>
  5099. * y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2]
  5100. * A0 = Kp + Ki + Kd
  5101. * A1 = (-Kp ) - (2 * Kd )
  5102. * A2 = Kd
  5103. * </pre>
  5104. *
  5105. * \par
  5106. * where \c Kp is proportional constant, \c Ki is Integral constant and \c Kd is Derivative constant
  5107. *
  5108. * \par
  5109. * \image html PID.gif "Proportional Integral Derivative Controller"
  5110. *
  5111. * \par
  5112. * The PID controller calculates an "error" value as the difference between
  5113. * the measured output and the reference input.
  5114. * The controller attempts to minimize the error by adjusting the process control inputs.
  5115. * The proportional value determines the reaction to the current error,
  5116. * the integral value determines the reaction based on the sum of recent errors,
  5117. * and the derivative value determines the reaction based on the rate at which the error has been changing.
  5118. *
  5119. * \par Instance Structure
  5120. * The Gains A0, A1, A2 and state variables for a PID controller are stored together in an instance data structure.
  5121. * A separate instance structure must be defined for each PID Controller.
  5122. * There are separate instance structure declarations for each of the 3 supported data types.
  5123. *
  5124. * \par Reset Functions
  5125. * There is also an associated reset function for each data type which clears the state array.
  5126. *
  5127. * \par Initialization Functions
  5128. * There is also an associated initialization function for each data type.
  5129. * The initialization function performs the following operations:
  5130. * - Initializes the Gains A0, A1, A2 from Kp,Ki, Kd gains.
  5131. * - Zeros out the values in the state buffer.
  5132. *
  5133. * \par
  5134. * Instance structure cannot be placed into a const data section and it is recommended to use the initialization function.
  5135. *
  5136. * \par Fixed-Point Behavior
  5137. * Care must be taken when using the fixed-point versions of the PID Controller functions.
  5138. * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered.
  5139. * Refer to the function specific documentation below for usage guidelines.
  5140. */
  5141. /**
  5142. * @addtogroup PID
  5143. * @{
  5144. */
  5145. /**
  5146. * @brief Process function for the floating-point PID Control.
  5147. * @param[in,out] S is an instance of the floating-point PID Control structure
  5148. * @param[in] in input sample to process
  5149. * @return processed output sample.
  5150. */
  5151. __STATIC_FORCEINLINE float32_t arm_pid_f32(
  5152. arm_pid_instance_f32 * S,
  5153. float32_t in)
  5154. {
  5155. float32_t out;
  5156. /* y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] */
  5157. out = (S->A0 * in) +
  5158. (S->A1 * S->state[0]) + (S->A2 * S->state[1]) + (S->state[2]);
  5159. /* Update state */
  5160. S->state[1] = S->state[0];
  5161. S->state[0] = in;
  5162. S->state[2] = out;
  5163. /* return to application */
  5164. return (out);
  5165. }
  5166. /**
  5167. @brief Process function for the Q31 PID Control.
  5168. @param[in,out] S points to an instance of the Q31 PID Control structure
  5169. @param[in] in input sample to process
  5170. @return processed output sample.
  5171. \par Scaling and Overflow Behavior
  5172. The function is implemented using an internal 64-bit accumulator.
  5173. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit.
  5174. Thus, if the accumulator result overflows it wraps around rather than clip.
  5175. In order to avoid overflows completely the input signal must be scaled down by 2 bits as there are four additions.
  5176. After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format.
  5177. */
  5178. __STATIC_FORCEINLINE q31_t arm_pid_q31(
  5179. arm_pid_instance_q31 * S,
  5180. q31_t in)
  5181. {
  5182. q63_t acc;
  5183. q31_t out;
  5184. /* acc = A0 * x[n] */
  5185. acc = (q63_t) S->A0 * in;
  5186. /* acc += A1 * x[n-1] */
  5187. acc += (q63_t) S->A1 * S->state[0];
  5188. /* acc += A2 * x[n-2] */
  5189. acc += (q63_t) S->A2 * S->state[1];
  5190. /* convert output to 1.31 format to add y[n-1] */
  5191. out = (q31_t) (acc >> 31U);
  5192. /* out += y[n-1] */
  5193. out += S->state[2];
  5194. /* Update state */
  5195. S->state[1] = S->state[0];
  5196. S->state[0] = in;
  5197. S->state[2] = out;
  5198. /* return to application */
  5199. return (out);
  5200. }
  5201. /**
  5202. @brief Process function for the Q15 PID Control.
  5203. @param[in,out] S points to an instance of the Q15 PID Control structure
  5204. @param[in] in input sample to process
  5205. @return processed output sample.
  5206. \par Scaling and Overflow Behavior
  5207. The function is implemented using a 64-bit internal accumulator.
  5208. Both Gains and state variables are represented in 1.15 format and multiplications yield a 2.30 result.
  5209. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format.
  5210. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved.
  5211. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits.
  5212. Lastly, the accumulator is saturated to yield a result in 1.15 format.
  5213. */
  5214. __STATIC_FORCEINLINE q15_t arm_pid_q15(
  5215. arm_pid_instance_q15 * S,
  5216. q15_t in)
  5217. {
  5218. q63_t acc;
  5219. q15_t out;
  5220. #if defined (ARM_MATH_DSP)
  5221. /* Implementation of PID controller */
  5222. /* acc = A0 * x[n] */
  5223. acc = (q31_t) __SMUAD((uint32_t)S->A0, (uint32_t)in);
  5224. /* acc += A1 * x[n-1] + A2 * x[n-2] */
  5225. acc = (q63_t)__SMLALD((uint32_t)S->A1, (uint32_t)read_q15x2 (S->state), (uint64_t)acc);
  5226. #else
  5227. /* acc = A0 * x[n] */
  5228. acc = ((q31_t) S->A0) * in;
  5229. /* acc += A1 * x[n-1] + A2 * x[n-2] */
  5230. acc += (q31_t) S->A1 * S->state[0];
  5231. acc += (q31_t) S->A2 * S->state[1];
  5232. #endif
  5233. /* acc += y[n-1] */
  5234. acc += (q31_t) S->state[2] << 15;
  5235. /* saturate the output */
  5236. out = (q15_t) (__SSAT((q31_t)(acc >> 15), 16));
  5237. /* Update state */
  5238. S->state[1] = S->state[0];
  5239. S->state[0] = in;
  5240. S->state[2] = out;
  5241. /* return to application */
  5242. return (out);
  5243. }
  5244. /**
  5245. * @} end of PID group
  5246. */
  5247. /**
  5248. * @brief Floating-point matrix inverse.
  5249. * @param[in] src points to the instance of the input floating-point matrix structure.
  5250. * @param[out] dst points to the instance of the output floating-point matrix structure.
  5251. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  5252. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  5253. */
  5254. arm_status arm_mat_inverse_f32(
  5255. const arm_matrix_instance_f32 * src,
  5256. arm_matrix_instance_f32 * dst);
  5257. /**
  5258. * @brief Floating-point matrix inverse.
  5259. * @param[in] src points to the instance of the input floating-point matrix structure.
  5260. * @param[out] dst points to the instance of the output floating-point matrix structure.
  5261. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  5262. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  5263. */
  5264. arm_status arm_mat_inverse_f64(
  5265. const arm_matrix_instance_f64 * src,
  5266. arm_matrix_instance_f64 * dst);
  5267. /**
  5268. * @ingroup groupController
  5269. */
  5270. /**
  5271. * @defgroup clarke Vector Clarke Transform
  5272. * Forward Clarke transform converts the instantaneous stator phases into a two-coordinate time invariant vector.
  5273. * Generally the Clarke transform uses three-phase currents <code>Ia, Ib and Ic</code> to calculate currents
  5274. * in the two-phase orthogonal stator axis <code>Ialpha</code> and <code>Ibeta</code>.
  5275. * When <code>Ialpha</code> is superposed with <code>Ia</code> as shown in the figure below
  5276. * \image html clarke.gif Stator current space vector and its components in (a,b).
  5277. * and <code>Ia + Ib + Ic = 0</code>, in this condition <code>Ialpha</code> and <code>Ibeta</code>
  5278. * can be calculated using only <code>Ia</code> and <code>Ib</code>.
  5279. *
  5280. * The function operates on a single sample of data and each call to the function returns the processed output.
  5281. * The library provides separate functions for Q31 and floating-point data types.
  5282. * \par Algorithm
  5283. * \image html clarkeFormula.gif
  5284. * where <code>Ia</code> and <code>Ib</code> are the instantaneous stator phases and
  5285. * <code>pIalpha</code> and <code>pIbeta</code> are the two coordinates of time invariant vector.
  5286. * \par Fixed-Point Behavior
  5287. * Care must be taken when using the Q31 version of the Clarke transform.
  5288. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5289. * Refer to the function specific documentation below for usage guidelines.
  5290. */
  5291. /**
  5292. * @addtogroup clarke
  5293. * @{
  5294. */
  5295. /**
  5296. *
  5297. * @brief Floating-point Clarke transform
  5298. * @param[in] Ia input three-phase coordinate <code>a</code>
  5299. * @param[in] Ib input three-phase coordinate <code>b</code>
  5300. * @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5301. * @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5302. * @return none
  5303. */
  5304. __STATIC_FORCEINLINE void arm_clarke_f32(
  5305. float32_t Ia,
  5306. float32_t Ib,
  5307. float32_t * pIalpha,
  5308. float32_t * pIbeta)
  5309. {
  5310. /* Calculate pIalpha using the equation, pIalpha = Ia */
  5311. *pIalpha = Ia;
  5312. /* Calculate pIbeta using the equation, pIbeta = (1/sqrt(3)) * Ia + (2/sqrt(3)) * Ib */
  5313. *pIbeta = ((float32_t) 0.57735026919 * Ia + (float32_t) 1.15470053838 * Ib);
  5314. }
  5315. /**
  5316. @brief Clarke transform for Q31 version
  5317. @param[in] Ia input three-phase coordinate <code>a</code>
  5318. @param[in] Ib input three-phase coordinate <code>b</code>
  5319. @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5320. @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5321. @return none
  5322. \par Scaling and Overflow Behavior
  5323. The function is implemented using an internal 32-bit accumulator.
  5324. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5325. There is saturation on the addition, hence there is no risk of overflow.
  5326. */
  5327. __STATIC_FORCEINLINE void arm_clarke_q31(
  5328. q31_t Ia,
  5329. q31_t Ib,
  5330. q31_t * pIalpha,
  5331. q31_t * pIbeta)
  5332. {
  5333. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5334. /* Calculating pIalpha from Ia by equation pIalpha = Ia */
  5335. *pIalpha = Ia;
  5336. /* Intermediate product is calculated by (1/(sqrt(3)) * Ia) */
  5337. product1 = (q31_t) (((q63_t) Ia * 0x24F34E8B) >> 30);
  5338. /* Intermediate product is calculated by (2/sqrt(3) * Ib) */
  5339. product2 = (q31_t) (((q63_t) Ib * 0x49E69D16) >> 30);
  5340. /* pIbeta is calculated by adding the intermediate products */
  5341. *pIbeta = __QADD(product1, product2);
  5342. }
  5343. /**
  5344. * @} end of clarke group
  5345. */
  5346. /**
  5347. * @ingroup groupController
  5348. */
  5349. /**
  5350. * @defgroup inv_clarke Vector Inverse Clarke Transform
  5351. * Inverse Clarke transform converts the two-coordinate time invariant vector into instantaneous stator phases.
  5352. *
  5353. * The function operates on a single sample of data and each call to the function returns the processed output.
  5354. * The library provides separate functions for Q31 and floating-point data types.
  5355. * \par Algorithm
  5356. * \image html clarkeInvFormula.gif
  5357. * where <code>pIa</code> and <code>pIb</code> are the instantaneous stator phases and
  5358. * <code>Ialpha</code> and <code>Ibeta</code> are the two coordinates of time invariant vector.
  5359. * \par Fixed-Point Behavior
  5360. * Care must be taken when using the Q31 version of the Clarke transform.
  5361. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5362. * Refer to the function specific documentation below for usage guidelines.
  5363. */
  5364. /**
  5365. * @addtogroup inv_clarke
  5366. * @{
  5367. */
  5368. /**
  5369. * @brief Floating-point Inverse Clarke transform
  5370. * @param[in] Ialpha input two-phase orthogonal vector axis alpha
  5371. * @param[in] Ibeta input two-phase orthogonal vector axis beta
  5372. * @param[out] pIa points to output three-phase coordinate <code>a</code>
  5373. * @param[out] pIb points to output three-phase coordinate <code>b</code>
  5374. * @return none
  5375. */
  5376. __STATIC_FORCEINLINE void arm_inv_clarke_f32(
  5377. float32_t Ialpha,
  5378. float32_t Ibeta,
  5379. float32_t * pIa,
  5380. float32_t * pIb)
  5381. {
  5382. /* Calculating pIa from Ialpha by equation pIa = Ialpha */
  5383. *pIa = Ialpha;
  5384. /* Calculating pIb from Ialpha and Ibeta by equation pIb = -(1/2) * Ialpha + (sqrt(3)/2) * Ibeta */
  5385. *pIb = -0.5f * Ialpha + 0.8660254039f * Ibeta;
  5386. }
  5387. /**
  5388. @brief Inverse Clarke transform for Q31 version
  5389. @param[in] Ialpha input two-phase orthogonal vector axis alpha
  5390. @param[in] Ibeta input two-phase orthogonal vector axis beta
  5391. @param[out] pIa points to output three-phase coordinate <code>a</code>
  5392. @param[out] pIb points to output three-phase coordinate <code>b</code>
  5393. @return none
  5394. \par Scaling and Overflow Behavior
  5395. The function is implemented using an internal 32-bit accumulator.
  5396. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5397. There is saturation on the subtraction, hence there is no risk of overflow.
  5398. */
  5399. __STATIC_FORCEINLINE void arm_inv_clarke_q31(
  5400. q31_t Ialpha,
  5401. q31_t Ibeta,
  5402. q31_t * pIa,
  5403. q31_t * pIb)
  5404. {
  5405. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5406. /* Calculating pIa from Ialpha by equation pIa = Ialpha */
  5407. *pIa = Ialpha;
  5408. /* Intermediate product is calculated by (1/(2*sqrt(3)) * Ia) */
  5409. product1 = (q31_t) (((q63_t) (Ialpha) * (0x40000000)) >> 31);
  5410. /* Intermediate product is calculated by (1/sqrt(3) * pIb) */
  5411. product2 = (q31_t) (((q63_t) (Ibeta) * (0x6ED9EBA1)) >> 31);
  5412. /* pIb is calculated by subtracting the products */
  5413. *pIb = __QSUB(product2, product1);
  5414. }
  5415. /**
  5416. * @} end of inv_clarke group
  5417. */
  5418. /**
  5419. * @ingroup groupController
  5420. */
  5421. /**
  5422. * @defgroup park Vector Park Transform
  5423. *
  5424. * Forward Park transform converts the input two-coordinate vector to flux and torque components.
  5425. * The Park transform can be used to realize the transformation of the <code>Ialpha</code> and the <code>Ibeta</code> currents
  5426. * from the stationary to the moving reference frame and control the spatial relationship between
  5427. * the stator vector current and rotor flux vector.
  5428. * If we consider the d axis aligned with the rotor flux, the diagram below shows the
  5429. * current vector and the relationship from the two reference frames:
  5430. * \image html park.gif "Stator current space vector and its component in (a,b) and in the d,q rotating reference frame"
  5431. *
  5432. * The function operates on a single sample of data and each call to the function returns the processed output.
  5433. * The library provides separate functions for Q31 and floating-point data types.
  5434. * \par Algorithm
  5435. * \image html parkFormula.gif
  5436. * where <code>Ialpha</code> and <code>Ibeta</code> are the stator vector components,
  5437. * <code>pId</code> and <code>pIq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the
  5438. * cosine and sine values of theta (rotor flux position).
  5439. * \par Fixed-Point Behavior
  5440. * Care must be taken when using the Q31 version of the Park transform.
  5441. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5442. * Refer to the function specific documentation below for usage guidelines.
  5443. */
  5444. /**
  5445. * @addtogroup park
  5446. * @{
  5447. */
  5448. /**
  5449. * @brief Floating-point Park transform
  5450. * @param[in] Ialpha input two-phase vector coordinate alpha
  5451. * @param[in] Ibeta input two-phase vector coordinate beta
  5452. * @param[out] pId points to output rotor reference frame d
  5453. * @param[out] pIq points to output rotor reference frame q
  5454. * @param[in] sinVal sine value of rotation angle theta
  5455. * @param[in] cosVal cosine value of rotation angle theta
  5456. * @return none
  5457. *
  5458. * The function implements the forward Park transform.
  5459. *
  5460. */
  5461. __STATIC_FORCEINLINE void arm_park_f32(
  5462. float32_t Ialpha,
  5463. float32_t Ibeta,
  5464. float32_t * pId,
  5465. float32_t * pIq,
  5466. float32_t sinVal,
  5467. float32_t cosVal)
  5468. {
  5469. /* Calculate pId using the equation, pId = Ialpha * cosVal + Ibeta * sinVal */
  5470. *pId = Ialpha * cosVal + Ibeta * sinVal;
  5471. /* Calculate pIq using the equation, pIq = - Ialpha * sinVal + Ibeta * cosVal */
  5472. *pIq = -Ialpha * sinVal + Ibeta * cosVal;
  5473. }
  5474. /**
  5475. @brief Park transform for Q31 version
  5476. @param[in] Ialpha input two-phase vector coordinate alpha
  5477. @param[in] Ibeta input two-phase vector coordinate beta
  5478. @param[out] pId points to output rotor reference frame d
  5479. @param[out] pIq points to output rotor reference frame q
  5480. @param[in] sinVal sine value of rotation angle theta
  5481. @param[in] cosVal cosine value of rotation angle theta
  5482. @return none
  5483. \par Scaling and Overflow Behavior
  5484. The function is implemented using an internal 32-bit accumulator.
  5485. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5486. There is saturation on the addition and subtraction, hence there is no risk of overflow.
  5487. */
  5488. __STATIC_FORCEINLINE void arm_park_q31(
  5489. q31_t Ialpha,
  5490. q31_t Ibeta,
  5491. q31_t * pId,
  5492. q31_t * pIq,
  5493. q31_t sinVal,
  5494. q31_t cosVal)
  5495. {
  5496. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5497. q31_t product3, product4; /* Temporary variables used to store intermediate results */
  5498. /* Intermediate product is calculated by (Ialpha * cosVal) */
  5499. product1 = (q31_t) (((q63_t) (Ialpha) * (cosVal)) >> 31);
  5500. /* Intermediate product is calculated by (Ibeta * sinVal) */
  5501. product2 = (q31_t) (((q63_t) (Ibeta) * (sinVal)) >> 31);
  5502. /* Intermediate product is calculated by (Ialpha * sinVal) */
  5503. product3 = (q31_t) (((q63_t) (Ialpha) * (sinVal)) >> 31);
  5504. /* Intermediate product is calculated by (Ibeta * cosVal) */
  5505. product4 = (q31_t) (((q63_t) (Ibeta) * (cosVal)) >> 31);
  5506. /* Calculate pId by adding the two intermediate products 1 and 2 */
  5507. *pId = __QADD(product1, product2);
  5508. /* Calculate pIq by subtracting the two intermediate products 3 from 4 */
  5509. *pIq = __QSUB(product4, product3);
  5510. }
  5511. /**
  5512. * @} end of park group
  5513. */
  5514. /**
  5515. * @ingroup groupController
  5516. */
  5517. /**
  5518. * @defgroup inv_park Vector Inverse Park transform
  5519. * Inverse Park transform converts the input flux and torque components to two-coordinate vector.
  5520. *
  5521. * The function operates on a single sample of data and each call to the function returns the processed output.
  5522. * The library provides separate functions for Q31 and floating-point data types.
  5523. * \par Algorithm
  5524. * \image html parkInvFormula.gif
  5525. * where <code>pIalpha</code> and <code>pIbeta</code> are the stator vector components,
  5526. * <code>Id</code> and <code>Iq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the
  5527. * cosine and sine values of theta (rotor flux position).
  5528. * \par Fixed-Point Behavior
  5529. * Care must be taken when using the Q31 version of the Park transform.
  5530. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5531. * Refer to the function specific documentation below for usage guidelines.
  5532. */
  5533. /**
  5534. * @addtogroup inv_park
  5535. * @{
  5536. */
  5537. /**
  5538. * @brief Floating-point Inverse Park transform
  5539. * @param[in] Id input coordinate of rotor reference frame d
  5540. * @param[in] Iq input coordinate of rotor reference frame q
  5541. * @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5542. * @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5543. * @param[in] sinVal sine value of rotation angle theta
  5544. * @param[in] cosVal cosine value of rotation angle theta
  5545. * @return none
  5546. */
  5547. __STATIC_FORCEINLINE void arm_inv_park_f32(
  5548. float32_t Id,
  5549. float32_t Iq,
  5550. float32_t * pIalpha,
  5551. float32_t * pIbeta,
  5552. float32_t sinVal,
  5553. float32_t cosVal)
  5554. {
  5555. /* Calculate pIalpha using the equation, pIalpha = Id * cosVal - Iq * sinVal */
  5556. *pIalpha = Id * cosVal - Iq * sinVal;
  5557. /* Calculate pIbeta using the equation, pIbeta = Id * sinVal + Iq * cosVal */
  5558. *pIbeta = Id * sinVal + Iq * cosVal;
  5559. }
  5560. /**
  5561. @brief Inverse Park transform for Q31 version
  5562. @param[in] Id input coordinate of rotor reference frame d
  5563. @param[in] Iq input coordinate of rotor reference frame q
  5564. @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5565. @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5566. @param[in] sinVal sine value of rotation angle theta
  5567. @param[in] cosVal cosine value of rotation angle theta
  5568. @return none
  5569. @par Scaling and Overflow Behavior
  5570. The function is implemented using an internal 32-bit accumulator.
  5571. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5572. There is saturation on the addition, hence there is no risk of overflow.
  5573. */
  5574. __STATIC_FORCEINLINE void arm_inv_park_q31(
  5575. q31_t Id,
  5576. q31_t Iq,
  5577. q31_t * pIalpha,
  5578. q31_t * pIbeta,
  5579. q31_t sinVal,
  5580. q31_t cosVal)
  5581. {
  5582. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5583. q31_t product3, product4; /* Temporary variables used to store intermediate results */
  5584. /* Intermediate product is calculated by (Id * cosVal) */
  5585. product1 = (q31_t) (((q63_t) (Id) * (cosVal)) >> 31);
  5586. /* Intermediate product is calculated by (Iq * sinVal) */
  5587. product2 = (q31_t) (((q63_t) (Iq) * (sinVal)) >> 31);
  5588. /* Intermediate product is calculated by (Id * sinVal) */
  5589. product3 = (q31_t) (((q63_t) (Id) * (sinVal)) >> 31);
  5590. /* Intermediate product is calculated by (Iq * cosVal) */
  5591. product4 = (q31_t) (((q63_t) (Iq) * (cosVal)) >> 31);
  5592. /* Calculate pIalpha by using the two intermediate products 1 and 2 */
  5593. *pIalpha = __QSUB(product1, product2);
  5594. /* Calculate pIbeta by using the two intermediate products 3 and 4 */
  5595. *pIbeta = __QADD(product4, product3);
  5596. }
  5597. /**
  5598. * @} end of Inverse park group
  5599. */
  5600. /**
  5601. * @ingroup groupInterpolation
  5602. */
  5603. /**
  5604. * @defgroup LinearInterpolate Linear Interpolation
  5605. *
  5606. * Linear interpolation is a method of curve fitting using linear polynomials.
  5607. * Linear interpolation works by effectively drawing a straight line between two neighboring samples and returning the appropriate point along that line
  5608. *
  5609. * \par
  5610. * \image html LinearInterp.gif "Linear interpolation"
  5611. *
  5612. * \par
  5613. * A Linear Interpolate function calculates an output value(y), for the input(x)
  5614. * using linear interpolation of the input values x0, x1( nearest input values) and the output values y0 and y1(nearest output values)
  5615. *
  5616. * \par Algorithm:
  5617. * <pre>
  5618. * y = y0 + (x - x0) * ((y1 - y0)/(x1-x0))
  5619. * where x0, x1 are nearest values of input x
  5620. * y0, y1 are nearest values to output y
  5621. * </pre>
  5622. *
  5623. * \par
  5624. * This set of functions implements Linear interpolation process
  5625. * for Q7, Q15, Q31, and floating-point data types. The functions operate on a single
  5626. * sample of data and each call to the function returns a single processed value.
  5627. * <code>S</code> points to an instance of the Linear Interpolate function data structure.
  5628. * <code>x</code> is the input sample value. The functions returns the output value.
  5629. *
  5630. * \par
  5631. * if x is outside of the table boundary, Linear interpolation returns first value of the table
  5632. * if x is below input range and returns last value of table if x is above range.
  5633. */
  5634. /**
  5635. * @addtogroup LinearInterpolate
  5636. * @{
  5637. */
  5638. /**
  5639. * @brief Process function for the floating-point Linear Interpolation Function.
  5640. * @param[in,out] S is an instance of the floating-point Linear Interpolation structure
  5641. * @param[in] x input sample to process
  5642. * @return y processed output sample.
  5643. *
  5644. */
  5645. __STATIC_FORCEINLINE float32_t arm_linear_interp_f32(
  5646. arm_linear_interp_instance_f32 * S,
  5647. float32_t x)
  5648. {
  5649. float32_t y;
  5650. float32_t x0, x1; /* Nearest input values */
  5651. float32_t y0, y1; /* Nearest output values */
  5652. float32_t xSpacing = S->xSpacing; /* spacing between input values */
  5653. int32_t i; /* Index variable */
  5654. float32_t *pYData = S->pYData; /* pointer to output table */
  5655. /* Calculation of index */
  5656. i = (int32_t) ((x - S->x1) / xSpacing);
  5657. if (i < 0)
  5658. {
  5659. /* Iniatilize output for below specified range as least output value of table */
  5660. y = pYData[0];
  5661. }
  5662. else if ((uint32_t)i >= (S->nValues - 1))
  5663. {
  5664. /* Iniatilize output for above specified range as last output value of table */
  5665. y = pYData[S->nValues - 1];
  5666. }
  5667. else
  5668. {
  5669. /* Calculation of nearest input values */
  5670. x0 = S->x1 + i * xSpacing;
  5671. x1 = S->x1 + (i + 1) * xSpacing;
  5672. /* Read of nearest output values */
  5673. y0 = pYData[i];
  5674. y1 = pYData[i + 1];
  5675. /* Calculation of output */
  5676. y = y0 + (x - x0) * ((y1 - y0) / (x1 - x0));
  5677. }
  5678. /* returns output value */
  5679. return (y);
  5680. }
  5681. /**
  5682. *
  5683. * @brief Process function for the Q31 Linear Interpolation Function.
  5684. * @param[in] pYData pointer to Q31 Linear Interpolation table
  5685. * @param[in] x input sample to process
  5686. * @param[in] nValues number of table values
  5687. * @return y processed output sample.
  5688. *
  5689. * \par
  5690. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  5691. * This function can support maximum of table size 2^12.
  5692. *
  5693. */
  5694. __STATIC_FORCEINLINE q31_t arm_linear_interp_q31(
  5695. q31_t * pYData,
  5696. q31_t x,
  5697. uint32_t nValues)
  5698. {
  5699. q31_t y; /* output */
  5700. q31_t y0, y1; /* Nearest output values */
  5701. q31_t fract; /* fractional part */
  5702. int32_t index; /* Index to read nearest output values */
  5703. /* Input is in 12.20 format */
  5704. /* 12 bits for the table index */
  5705. /* Index value calculation */
  5706. index = ((x & (q31_t)0xFFF00000) >> 20);
  5707. if (index >= (int32_t)(nValues - 1))
  5708. {
  5709. return (pYData[nValues - 1]);
  5710. }
  5711. else if (index < 0)
  5712. {
  5713. return (pYData[0]);
  5714. }
  5715. else
  5716. {
  5717. /* 20 bits for the fractional part */
  5718. /* shift left by 11 to keep fract in 1.31 format */
  5719. fract = (x & 0x000FFFFF) << 11;
  5720. /* Read two nearest output values from the index in 1.31(q31) format */
  5721. y0 = pYData[index];
  5722. y1 = pYData[index + 1];
  5723. /* Calculation of y0 * (1-fract) and y is in 2.30 format */
  5724. y = ((q31_t) ((q63_t) y0 * (0x7FFFFFFF - fract) >> 32));
  5725. /* Calculation of y0 * (1-fract) + y1 *fract and y is in 2.30 format */
  5726. y += ((q31_t) (((q63_t) y1 * fract) >> 32));
  5727. /* Convert y to 1.31 format */
  5728. return (y << 1U);
  5729. }
  5730. }
  5731. /**
  5732. *
  5733. * @brief Process function for the Q15 Linear Interpolation Function.
  5734. * @param[in] pYData pointer to Q15 Linear Interpolation table
  5735. * @param[in] x input sample to process
  5736. * @param[in] nValues number of table values
  5737. * @return y processed output sample.
  5738. *
  5739. * \par
  5740. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  5741. * This function can support maximum of table size 2^12.
  5742. *
  5743. */
  5744. __STATIC_FORCEINLINE q15_t arm_linear_interp_q15(
  5745. q15_t * pYData,
  5746. q31_t x,
  5747. uint32_t nValues)
  5748. {
  5749. q63_t y; /* output */
  5750. q15_t y0, y1; /* Nearest output values */
  5751. q31_t fract; /* fractional part */
  5752. int32_t index; /* Index to read nearest output values */
  5753. /* Input is in 12.20 format */
  5754. /* 12 bits for the table index */
  5755. /* Index value calculation */
  5756. index = ((x & (int32_t)0xFFF00000) >> 20);
  5757. if (index >= (int32_t)(nValues - 1))
  5758. {
  5759. return (pYData[nValues - 1]);
  5760. }
  5761. else if (index < 0)
  5762. {
  5763. return (pYData[0]);
  5764. }
  5765. else
  5766. {
  5767. /* 20 bits for the fractional part */
  5768. /* fract is in 12.20 format */
  5769. fract = (x & 0x000FFFFF);
  5770. /* Read two nearest output values from the index */
  5771. y0 = pYData[index];
  5772. y1 = pYData[index + 1];
  5773. /* Calculation of y0 * (1-fract) and y is in 13.35 format */
  5774. y = ((q63_t) y0 * (0xFFFFF - fract));
  5775. /* Calculation of (y0 * (1-fract) + y1 * fract) and y is in 13.35 format */
  5776. y += ((q63_t) y1 * (fract));
  5777. /* convert y to 1.15 format */
  5778. return (q15_t) (y >> 20);
  5779. }
  5780. }
  5781. /**
  5782. *
  5783. * @brief Process function for the Q7 Linear Interpolation Function.
  5784. * @param[in] pYData pointer to Q7 Linear Interpolation table
  5785. * @param[in] x input sample to process
  5786. * @param[in] nValues number of table values
  5787. * @return y processed output sample.
  5788. *
  5789. * \par
  5790. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  5791. * This function can support maximum of table size 2^12.
  5792. */
  5793. __STATIC_FORCEINLINE q7_t arm_linear_interp_q7(
  5794. q7_t * pYData,
  5795. q31_t x,
  5796. uint32_t nValues)
  5797. {
  5798. q31_t y; /* output */
  5799. q7_t y0, y1; /* Nearest output values */
  5800. q31_t fract; /* fractional part */
  5801. uint32_t index; /* Index to read nearest output values */
  5802. /* Input is in 12.20 format */
  5803. /* 12 bits for the table index */
  5804. /* Index value calculation */
  5805. if (x < 0)
  5806. {
  5807. return (pYData[0]);
  5808. }
  5809. index = (x >> 20) & 0xfff;
  5810. if (index >= (nValues - 1))
  5811. {
  5812. return (pYData[nValues - 1]);
  5813. }
  5814. else
  5815. {
  5816. /* 20 bits for the fractional part */
  5817. /* fract is in 12.20 format */
  5818. fract = (x & 0x000FFFFF);
  5819. /* Read two nearest output values from the index and are in 1.7(q7) format */
  5820. y0 = pYData[index];
  5821. y1 = pYData[index + 1];
  5822. /* Calculation of y0 * (1-fract ) and y is in 13.27(q27) format */
  5823. y = ((y0 * (0xFFFFF - fract)));
  5824. /* Calculation of y1 * fract + y0 * (1-fract) and y is in 13.27(q27) format */
  5825. y += (y1 * fract);
  5826. /* convert y to 1.7(q7) format */
  5827. return (q7_t) (y >> 20);
  5828. }
  5829. }
  5830. /**
  5831. * @} end of LinearInterpolate group
  5832. */
  5833. /**
  5834. * @brief Fast approximation to the trigonometric sine function for floating-point data.
  5835. * @param[in] x input value in radians.
  5836. * @return sin(x).
  5837. */
  5838. float32_t arm_sin_f32(
  5839. float32_t x);
  5840. /**
  5841. * @brief Fast approximation to the trigonometric sine function for Q31 data.
  5842. * @param[in] x Scaled input value in radians.
  5843. * @return sin(x).
  5844. */
  5845. q31_t arm_sin_q31(
  5846. q31_t x);
  5847. /**
  5848. * @brief Fast approximation to the trigonometric sine function for Q15 data.
  5849. * @param[in] x Scaled input value in radians.
  5850. * @return sin(x).
  5851. */
  5852. q15_t arm_sin_q15(
  5853. q15_t x);
  5854. /**
  5855. * @brief Fast approximation to the trigonometric cosine function for floating-point data.
  5856. * @param[in] x input value in radians.
  5857. * @return cos(x).
  5858. */
  5859. float32_t arm_cos_f32(
  5860. float32_t x);
  5861. /**
  5862. * @brief Fast approximation to the trigonometric cosine function for Q31 data.
  5863. * @param[in] x Scaled input value in radians.
  5864. * @return cos(x).
  5865. */
  5866. q31_t arm_cos_q31(
  5867. q31_t x);
  5868. /**
  5869. * @brief Fast approximation to the trigonometric cosine function for Q15 data.
  5870. * @param[in] x Scaled input value in radians.
  5871. * @return cos(x).
  5872. */
  5873. q15_t arm_cos_q15(
  5874. q15_t x);
  5875. /**
  5876. @brief Floating-point vector of log values.
  5877. @param[in] pSrc points to the input vector
  5878. @param[out] pDst points to the output vector
  5879. @param[in] blockSize number of samples in each vector
  5880. @return none
  5881. */
  5882. void arm_vlog_f32(
  5883. const float32_t * pSrc,
  5884. float32_t * pDst,
  5885. uint32_t blockSize);
  5886. /**
  5887. @brief Floating-point vector of exp values.
  5888. @param[in] pSrc points to the input vector
  5889. @param[out] pDst points to the output vector
  5890. @param[in] blockSize number of samples in each vector
  5891. @return none
  5892. */
  5893. void arm_vexp_f32(
  5894. const float32_t * pSrc,
  5895. float32_t * pDst,
  5896. uint32_t blockSize);
  5897. /**
  5898. * @ingroup groupFastMath
  5899. */
  5900. /**
  5901. * @defgroup SQRT Square Root
  5902. *
  5903. * Computes the square root of a number.
  5904. * There are separate functions for Q15, Q31, and floating-point data types.
  5905. * The square root function is computed using the Newton-Raphson algorithm.
  5906. * This is an iterative algorithm of the form:
  5907. * <pre>
  5908. * x1 = x0 - f(x0)/f'(x0)
  5909. * </pre>
  5910. * where <code>x1</code> is the current estimate,
  5911. * <code>x0</code> is the previous estimate, and
  5912. * <code>f'(x0)</code> is the derivative of <code>f()</code> evaluated at <code>x0</code>.
  5913. * For the square root function, the algorithm reduces to:
  5914. * <pre>
  5915. * x0 = in/2 [initial guess]
  5916. * x1 = 1/2 * ( x0 + in / x0) [each iteration]
  5917. * </pre>
  5918. */
  5919. /**
  5920. * @addtogroup SQRT
  5921. * @{
  5922. */
  5923. /**
  5924. @brief Floating-point square root function.
  5925. @param[in] in input value
  5926. @param[out] pOut square root of input value
  5927. @return execution status
  5928. - \ref ARM_MATH_SUCCESS : input value is positive
  5929. - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0
  5930. */
  5931. __STATIC_FORCEINLINE arm_status arm_sqrt_f32(
  5932. float32_t in,
  5933. float32_t * pOut)
  5934. {
  5935. if (in >= 0.0f)
  5936. {
  5937. #if defined ( __CC_ARM )
  5938. #if defined __TARGET_FPU_VFP
  5939. *pOut = __sqrtf(in);
  5940. #else
  5941. *pOut = sqrtf(in);
  5942. #endif
  5943. #elif defined ( __ICCARM__ )
  5944. #if defined __ARMVFP__
  5945. __ASM("VSQRT.F32 %0,%1" : "=t"(*pOut) : "t"(in));
  5946. #else
  5947. *pOut = sqrtf(in);
  5948. #endif
  5949. #else
  5950. *pOut = sqrtf(in);
  5951. #endif
  5952. return (ARM_MATH_SUCCESS);
  5953. }
  5954. else
  5955. {
  5956. *pOut = 0.0f;
  5957. return (ARM_MATH_ARGUMENT_ERROR);
  5958. }
  5959. }
  5960. /**
  5961. @brief Q31 square root function.
  5962. @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF
  5963. @param[out] pOut points to square root of input value
  5964. @return execution status
  5965. - \ref ARM_MATH_SUCCESS : input value is positive
  5966. - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0
  5967. */
  5968. arm_status arm_sqrt_q31(
  5969. q31_t in,
  5970. q31_t * pOut);
  5971. /**
  5972. @brief Q15 square root function.
  5973. @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF
  5974. @param[out] pOut points to square root of input value
  5975. @return execution status
  5976. - \ref ARM_MATH_SUCCESS : input value is positive
  5977. - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0
  5978. */
  5979. arm_status arm_sqrt_q15(
  5980. q15_t in,
  5981. q15_t * pOut);
  5982. /**
  5983. * @brief Vector Floating-point square root function.
  5984. * @param[in] pIn input vector.
  5985. * @param[out] pOut vector of square roots of input elements.
  5986. * @param[in] len length of input vector.
  5987. * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if
  5988. * <code>in</code> is negative value and returns zero output for negative values.
  5989. */
  5990. void arm_vsqrt_f32(
  5991. float32_t * pIn,
  5992. float32_t * pOut,
  5993. uint16_t len);
  5994. void arm_vsqrt_q31(
  5995. q31_t * pIn,
  5996. q31_t * pOut,
  5997. uint16_t len);
  5998. void arm_vsqrt_q15(
  5999. q15_t * pIn,
  6000. q15_t * pOut,
  6001. uint16_t len);
  6002. /**
  6003. * @} end of SQRT group
  6004. */
  6005. /**
  6006. * @brief floating-point Circular write function.
  6007. */
  6008. __STATIC_FORCEINLINE void arm_circularWrite_f32(
  6009. int32_t * circBuffer,
  6010. int32_t L,
  6011. uint16_t * writeOffset,
  6012. int32_t bufferInc,
  6013. const int32_t * src,
  6014. int32_t srcInc,
  6015. uint32_t blockSize)
  6016. {
  6017. uint32_t i = 0U;
  6018. int32_t wOffset;
  6019. /* Copy the value of Index pointer that points
  6020. * to the current location where the input samples to be copied */
  6021. wOffset = *writeOffset;
  6022. /* Loop over the blockSize */
  6023. i = blockSize;
  6024. while (i > 0U)
  6025. {
  6026. /* copy the input sample to the circular buffer */
  6027. circBuffer[wOffset] = *src;
  6028. /* Update the input pointer */
  6029. src += srcInc;
  6030. /* Circularly update wOffset. Watch out for positive and negative value */
  6031. wOffset += bufferInc;
  6032. if (wOffset >= L)
  6033. wOffset -= L;
  6034. /* Decrement the loop counter */
  6035. i--;
  6036. }
  6037. /* Update the index pointer */
  6038. *writeOffset = (uint16_t)wOffset;
  6039. }
  6040. /**
  6041. * @brief floating-point Circular Read function.
  6042. */
  6043. __STATIC_FORCEINLINE void arm_circularRead_f32(
  6044. int32_t * circBuffer,
  6045. int32_t L,
  6046. int32_t * readOffset,
  6047. int32_t bufferInc,
  6048. int32_t * dst,
  6049. int32_t * dst_base,
  6050. int32_t dst_length,
  6051. int32_t dstInc,
  6052. uint32_t blockSize)
  6053. {
  6054. uint32_t i = 0U;
  6055. int32_t rOffset;
  6056. int32_t* dst_end;
  6057. /* Copy the value of Index pointer that points
  6058. * to the current location from where the input samples to be read */
  6059. rOffset = *readOffset;
  6060. dst_end = dst_base + dst_length;
  6061. /* Loop over the blockSize */
  6062. i = blockSize;
  6063. while (i > 0U)
  6064. {
  6065. /* copy the sample from the circular buffer to the destination buffer */
  6066. *dst = circBuffer[rOffset];
  6067. /* Update the input pointer */
  6068. dst += dstInc;
  6069. if (dst == dst_end)
  6070. {
  6071. dst = dst_base;
  6072. }
  6073. /* Circularly update rOffset. Watch out for positive and negative value */
  6074. rOffset += bufferInc;
  6075. if (rOffset >= L)
  6076. {
  6077. rOffset -= L;
  6078. }
  6079. /* Decrement the loop counter */
  6080. i--;
  6081. }
  6082. /* Update the index pointer */
  6083. *readOffset = rOffset;
  6084. }
  6085. /**
  6086. * @brief Q15 Circular write function.
  6087. */
  6088. __STATIC_FORCEINLINE void arm_circularWrite_q15(
  6089. q15_t * circBuffer,
  6090. int32_t L,
  6091. uint16_t * writeOffset,
  6092. int32_t bufferInc,
  6093. const q15_t * src,
  6094. int32_t srcInc,
  6095. uint32_t blockSize)
  6096. {
  6097. uint32_t i = 0U;
  6098. int32_t wOffset;
  6099. /* Copy the value of Index pointer that points
  6100. * to the current location where the input samples to be copied */
  6101. wOffset = *writeOffset;
  6102. /* Loop over the blockSize */
  6103. i = blockSize;
  6104. while (i > 0U)
  6105. {
  6106. /* copy the input sample to the circular buffer */
  6107. circBuffer[wOffset] = *src;
  6108. /* Update the input pointer */
  6109. src += srcInc;
  6110. /* Circularly update wOffset. Watch out for positive and negative value */
  6111. wOffset += bufferInc;
  6112. if (wOffset >= L)
  6113. wOffset -= L;
  6114. /* Decrement the loop counter */
  6115. i--;
  6116. }
  6117. /* Update the index pointer */
  6118. *writeOffset = (uint16_t)wOffset;
  6119. }
  6120. /**
  6121. * @brief Q15 Circular Read function.
  6122. */
  6123. __STATIC_FORCEINLINE void arm_circularRead_q15(
  6124. q15_t * circBuffer,
  6125. int32_t L,
  6126. int32_t * readOffset,
  6127. int32_t bufferInc,
  6128. q15_t * dst,
  6129. q15_t * dst_base,
  6130. int32_t dst_length,
  6131. int32_t dstInc,
  6132. uint32_t blockSize)
  6133. {
  6134. uint32_t i = 0;
  6135. int32_t rOffset;
  6136. q15_t* dst_end;
  6137. /* Copy the value of Index pointer that points
  6138. * to the current location from where the input samples to be read */
  6139. rOffset = *readOffset;
  6140. dst_end = dst_base + dst_length;
  6141. /* Loop over the blockSize */
  6142. i = blockSize;
  6143. while (i > 0U)
  6144. {
  6145. /* copy the sample from the circular buffer to the destination buffer */
  6146. *dst = circBuffer[rOffset];
  6147. /* Update the input pointer */
  6148. dst += dstInc;
  6149. if (dst == dst_end)
  6150. {
  6151. dst = dst_base;
  6152. }
  6153. /* Circularly update wOffset. Watch out for positive and negative value */
  6154. rOffset += bufferInc;
  6155. if (rOffset >= L)
  6156. {
  6157. rOffset -= L;
  6158. }
  6159. /* Decrement the loop counter */
  6160. i--;
  6161. }
  6162. /* Update the index pointer */
  6163. *readOffset = rOffset;
  6164. }
  6165. /**
  6166. * @brief Q7 Circular write function.
  6167. */
  6168. __STATIC_FORCEINLINE void arm_circularWrite_q7(
  6169. q7_t * circBuffer,
  6170. int32_t L,
  6171. uint16_t * writeOffset,
  6172. int32_t bufferInc,
  6173. const q7_t * src,
  6174. int32_t srcInc,
  6175. uint32_t blockSize)
  6176. {
  6177. uint32_t i = 0U;
  6178. int32_t wOffset;
  6179. /* Copy the value of Index pointer that points
  6180. * to the current location where the input samples to be copied */
  6181. wOffset = *writeOffset;
  6182. /* Loop over the blockSize */
  6183. i = blockSize;
  6184. while (i > 0U)
  6185. {
  6186. /* copy the input sample to the circular buffer */
  6187. circBuffer[wOffset] = *src;
  6188. /* Update the input pointer */
  6189. src += srcInc;
  6190. /* Circularly update wOffset. Watch out for positive and negative value */
  6191. wOffset += bufferInc;
  6192. if (wOffset >= L)
  6193. wOffset -= L;
  6194. /* Decrement the loop counter */
  6195. i--;
  6196. }
  6197. /* Update the index pointer */
  6198. *writeOffset = (uint16_t)wOffset;
  6199. }
  6200. /**
  6201. * @brief Q7 Circular Read function.
  6202. */
  6203. __STATIC_FORCEINLINE void arm_circularRead_q7(
  6204. q7_t * circBuffer,
  6205. int32_t L,
  6206. int32_t * readOffset,
  6207. int32_t bufferInc,
  6208. q7_t * dst,
  6209. q7_t * dst_base,
  6210. int32_t dst_length,
  6211. int32_t dstInc,
  6212. uint32_t blockSize)
  6213. {
  6214. uint32_t i = 0;
  6215. int32_t rOffset;
  6216. q7_t* dst_end;
  6217. /* Copy the value of Index pointer that points
  6218. * to the current location from where the input samples to be read */
  6219. rOffset = *readOffset;
  6220. dst_end = dst_base + dst_length;
  6221. /* Loop over the blockSize */
  6222. i = blockSize;
  6223. while (i > 0U)
  6224. {
  6225. /* copy the sample from the circular buffer to the destination buffer */
  6226. *dst = circBuffer[rOffset];
  6227. /* Update the input pointer */
  6228. dst += dstInc;
  6229. if (dst == dst_end)
  6230. {
  6231. dst = dst_base;
  6232. }
  6233. /* Circularly update rOffset. Watch out for positive and negative value */
  6234. rOffset += bufferInc;
  6235. if (rOffset >= L)
  6236. {
  6237. rOffset -= L;
  6238. }
  6239. /* Decrement the loop counter */
  6240. i--;
  6241. }
  6242. /* Update the index pointer */
  6243. *readOffset = rOffset;
  6244. }
  6245. /**
  6246. * @brief Sum of the squares of the elements of a Q31 vector.
  6247. * @param[in] pSrc is input pointer
  6248. * @param[in] blockSize is the number of samples to process
  6249. * @param[out] pResult is output value.
  6250. */
  6251. void arm_power_q31(
  6252. const q31_t * pSrc,
  6253. uint32_t blockSize,
  6254. q63_t * pResult);
  6255. /**
  6256. * @brief Sum of the squares of the elements of a floating-point vector.
  6257. * @param[in] pSrc is input pointer
  6258. * @param[in] blockSize is the number of samples to process
  6259. * @param[out] pResult is output value.
  6260. */
  6261. void arm_power_f32(
  6262. const float32_t * pSrc,
  6263. uint32_t blockSize,
  6264. float32_t * pResult);
  6265. /**
  6266. * @brief Sum of the squares of the elements of a Q15 vector.
  6267. * @param[in] pSrc is input pointer
  6268. * @param[in] blockSize is the number of samples to process
  6269. * @param[out] pResult is output value.
  6270. */
  6271. void arm_power_q15(
  6272. const q15_t * pSrc,
  6273. uint32_t blockSize,
  6274. q63_t * pResult);
  6275. /**
  6276. * @brief Sum of the squares of the elements of a Q7 vector.
  6277. * @param[in] pSrc is input pointer
  6278. * @param[in] blockSize is the number of samples to process
  6279. * @param[out] pResult is output value.
  6280. */
  6281. void arm_power_q7(
  6282. const q7_t * pSrc,
  6283. uint32_t blockSize,
  6284. q31_t * pResult);
  6285. /**
  6286. * @brief Mean value of a Q7 vector.
  6287. * @param[in] pSrc is input pointer
  6288. * @param[in] blockSize is the number of samples to process
  6289. * @param[out] pResult is output value.
  6290. */
  6291. void arm_mean_q7(
  6292. const q7_t * pSrc,
  6293. uint32_t blockSize,
  6294. q7_t * pResult);
  6295. /**
  6296. * @brief Mean value of a Q15 vector.
  6297. * @param[in] pSrc is input pointer
  6298. * @param[in] blockSize is the number of samples to process
  6299. * @param[out] pResult is output value.
  6300. */
  6301. void arm_mean_q15(
  6302. const q15_t * pSrc,
  6303. uint32_t blockSize,
  6304. q15_t * pResult);
  6305. /**
  6306. * @brief Mean value of a Q31 vector.
  6307. * @param[in] pSrc is input pointer
  6308. * @param[in] blockSize is the number of samples to process
  6309. * @param[out] pResult is output value.
  6310. */
  6311. void arm_mean_q31(
  6312. const q31_t * pSrc,
  6313. uint32_t blockSize,
  6314. q31_t * pResult);
  6315. /**
  6316. * @brief Mean value of a floating-point vector.
  6317. * @param[in] pSrc is input pointer
  6318. * @param[in] blockSize is the number of samples to process
  6319. * @param[out] pResult is output value.
  6320. */
  6321. void arm_mean_f32(
  6322. const float32_t * pSrc,
  6323. uint32_t blockSize,
  6324. float32_t * pResult);
  6325. /**
  6326. * @brief Variance of the elements of a floating-point vector.
  6327. * @param[in] pSrc is input pointer
  6328. * @param[in] blockSize is the number of samples to process
  6329. * @param[out] pResult is output value.
  6330. */
  6331. void arm_var_f32(
  6332. const float32_t * pSrc,
  6333. uint32_t blockSize,
  6334. float32_t * pResult);
  6335. /**
  6336. * @brief Variance of the elements of a Q31 vector.
  6337. * @param[in] pSrc is input pointer
  6338. * @param[in] blockSize is the number of samples to process
  6339. * @param[out] pResult is output value.
  6340. */
  6341. void arm_var_q31(
  6342. const q31_t * pSrc,
  6343. uint32_t blockSize,
  6344. q31_t * pResult);
  6345. /**
  6346. * @brief Variance of the elements of a Q15 vector.
  6347. * @param[in] pSrc is input pointer
  6348. * @param[in] blockSize is the number of samples to process
  6349. * @param[out] pResult is output value.
  6350. */
  6351. void arm_var_q15(
  6352. const q15_t * pSrc,
  6353. uint32_t blockSize,
  6354. q15_t * pResult);
  6355. /**
  6356. * @brief Root Mean Square of the elements of a floating-point vector.
  6357. * @param[in] pSrc is input pointer
  6358. * @param[in] blockSize is the number of samples to process
  6359. * @param[out] pResult is output value.
  6360. */
  6361. void arm_rms_f32(
  6362. const float32_t * pSrc,
  6363. uint32_t blockSize,
  6364. float32_t * pResult);
  6365. /**
  6366. * @brief Root Mean Square of the elements of a Q31 vector.
  6367. * @param[in] pSrc is input pointer
  6368. * @param[in] blockSize is the number of samples to process
  6369. * @param[out] pResult is output value.
  6370. */
  6371. void arm_rms_q31(
  6372. const q31_t * pSrc,
  6373. uint32_t blockSize,
  6374. q31_t * pResult);
  6375. /**
  6376. * @brief Root Mean Square of the elements of a Q15 vector.
  6377. * @param[in] pSrc is input pointer
  6378. * @param[in] blockSize is the number of samples to process
  6379. * @param[out] pResult is output value.
  6380. */
  6381. void arm_rms_q15(
  6382. const q15_t * pSrc,
  6383. uint32_t blockSize,
  6384. q15_t * pResult);
  6385. /**
  6386. * @brief Standard deviation of the elements of a floating-point vector.
  6387. * @param[in] pSrc is input pointer
  6388. * @param[in] blockSize is the number of samples to process
  6389. * @param[out] pResult is output value.
  6390. */
  6391. void arm_std_f32(
  6392. const float32_t * pSrc,
  6393. uint32_t blockSize,
  6394. float32_t * pResult);
  6395. /**
  6396. * @brief Standard deviation of the elements of a Q31 vector.
  6397. * @param[in] pSrc is input pointer
  6398. * @param[in] blockSize is the number of samples to process
  6399. * @param[out] pResult is output value.
  6400. */
  6401. void arm_std_q31(
  6402. const q31_t * pSrc,
  6403. uint32_t blockSize,
  6404. q31_t * pResult);
  6405. /**
  6406. * @brief Standard deviation of the elements of a Q15 vector.
  6407. * @param[in] pSrc is input pointer
  6408. * @param[in] blockSize is the number of samples to process
  6409. * @param[out] pResult is output value.
  6410. */
  6411. void arm_std_q15(
  6412. const q15_t * pSrc,
  6413. uint32_t blockSize,
  6414. q15_t * pResult);
  6415. /**
  6416. * @brief Floating-point complex magnitude
  6417. * @param[in] pSrc points to the complex input vector
  6418. * @param[out] pDst points to the real output vector
  6419. * @param[in] numSamples number of complex samples in the input vector
  6420. */
  6421. void arm_cmplx_mag_f32(
  6422. const float32_t * pSrc,
  6423. float32_t * pDst,
  6424. uint32_t numSamples);
  6425. /**
  6426. * @brief Q31 complex magnitude
  6427. * @param[in] pSrc points to the complex input vector
  6428. * @param[out] pDst points to the real output vector
  6429. * @param[in] numSamples number of complex samples in the input vector
  6430. */
  6431. void arm_cmplx_mag_q31(
  6432. const q31_t * pSrc,
  6433. q31_t * pDst,
  6434. uint32_t numSamples);
  6435. /**
  6436. * @brief Q15 complex magnitude
  6437. * @param[in] pSrc points to the complex input vector
  6438. * @param[out] pDst points to the real output vector
  6439. * @param[in] numSamples number of complex samples in the input vector
  6440. */
  6441. void arm_cmplx_mag_q15(
  6442. const q15_t * pSrc,
  6443. q15_t * pDst,
  6444. uint32_t numSamples);
  6445. /**
  6446. * @brief Q15 complex dot product
  6447. * @param[in] pSrcA points to the first input vector
  6448. * @param[in] pSrcB points to the second input vector
  6449. * @param[in] numSamples number of complex samples in each vector
  6450. * @param[out] realResult real part of the result returned here
  6451. * @param[out] imagResult imaginary part of the result returned here
  6452. */
  6453. void arm_cmplx_dot_prod_q15(
  6454. const q15_t * pSrcA,
  6455. const q15_t * pSrcB,
  6456. uint32_t numSamples,
  6457. q31_t * realResult,
  6458. q31_t * imagResult);
  6459. /**
  6460. * @brief Q31 complex dot product
  6461. * @param[in] pSrcA points to the first input vector
  6462. * @param[in] pSrcB points to the second input vector
  6463. * @param[in] numSamples number of complex samples in each vector
  6464. * @param[out] realResult real part of the result returned here
  6465. * @param[out] imagResult imaginary part of the result returned here
  6466. */
  6467. void arm_cmplx_dot_prod_q31(
  6468. const q31_t * pSrcA,
  6469. const q31_t * pSrcB,
  6470. uint32_t numSamples,
  6471. q63_t * realResult,
  6472. q63_t * imagResult);
  6473. /**
  6474. * @brief Floating-point complex dot product
  6475. * @param[in] pSrcA points to the first input vector
  6476. * @param[in] pSrcB points to the second input vector
  6477. * @param[in] numSamples number of complex samples in each vector
  6478. * @param[out] realResult real part of the result returned here
  6479. * @param[out] imagResult imaginary part of the result returned here
  6480. */
  6481. void arm_cmplx_dot_prod_f32(
  6482. const float32_t * pSrcA,
  6483. const float32_t * pSrcB,
  6484. uint32_t numSamples,
  6485. float32_t * realResult,
  6486. float32_t * imagResult);
  6487. /**
  6488. * @brief Q15 complex-by-real multiplication
  6489. * @param[in] pSrcCmplx points to the complex input vector
  6490. * @param[in] pSrcReal points to the real input vector
  6491. * @param[out] pCmplxDst points to the complex output vector
  6492. * @param[in] numSamples number of samples in each vector
  6493. */
  6494. void arm_cmplx_mult_real_q15(
  6495. const q15_t * pSrcCmplx,
  6496. const q15_t * pSrcReal,
  6497. q15_t * pCmplxDst,
  6498. uint32_t numSamples);
  6499. /**
  6500. * @brief Q31 complex-by-real multiplication
  6501. * @param[in] pSrcCmplx points to the complex input vector
  6502. * @param[in] pSrcReal points to the real input vector
  6503. * @param[out] pCmplxDst points to the complex output vector
  6504. * @param[in] numSamples number of samples in each vector
  6505. */
  6506. void arm_cmplx_mult_real_q31(
  6507. const q31_t * pSrcCmplx,
  6508. const q31_t * pSrcReal,
  6509. q31_t * pCmplxDst,
  6510. uint32_t numSamples);
  6511. /**
  6512. * @brief Floating-point complex-by-real multiplication
  6513. * @param[in] pSrcCmplx points to the complex input vector
  6514. * @param[in] pSrcReal points to the real input vector
  6515. * @param[out] pCmplxDst points to the complex output vector
  6516. * @param[in] numSamples number of samples in each vector
  6517. */
  6518. void arm_cmplx_mult_real_f32(
  6519. const float32_t * pSrcCmplx,
  6520. const float32_t * pSrcReal,
  6521. float32_t * pCmplxDst,
  6522. uint32_t numSamples);
  6523. /**
  6524. * @brief Minimum value of a Q7 vector.
  6525. * @param[in] pSrc is input pointer
  6526. * @param[in] blockSize is the number of samples to process
  6527. * @param[out] result is output pointer
  6528. * @param[in] index is the array index of the minimum value in the input buffer.
  6529. */
  6530. void arm_min_q7(
  6531. const q7_t * pSrc,
  6532. uint32_t blockSize,
  6533. q7_t * result,
  6534. uint32_t * index);
  6535. /**
  6536. * @brief Minimum value of a Q15 vector.
  6537. * @param[in] pSrc is input pointer
  6538. * @param[in] blockSize is the number of samples to process
  6539. * @param[out] pResult is output pointer
  6540. * @param[in] pIndex is the array index of the minimum value in the input buffer.
  6541. */
  6542. void arm_min_q15(
  6543. const q15_t * pSrc,
  6544. uint32_t blockSize,
  6545. q15_t * pResult,
  6546. uint32_t * pIndex);
  6547. /**
  6548. * @brief Minimum value of a Q31 vector.
  6549. * @param[in] pSrc is input pointer
  6550. * @param[in] blockSize is the number of samples to process
  6551. * @param[out] pResult is output pointer
  6552. * @param[out] pIndex is the array index of the minimum value in the input buffer.
  6553. */
  6554. void arm_min_q31(
  6555. const q31_t * pSrc,
  6556. uint32_t blockSize,
  6557. q31_t * pResult,
  6558. uint32_t * pIndex);
  6559. /**
  6560. * @brief Minimum value of a floating-point vector.
  6561. * @param[in] pSrc is input pointer
  6562. * @param[in] blockSize is the number of samples to process
  6563. * @param[out] pResult is output pointer
  6564. * @param[out] pIndex is the array index of the minimum value in the input buffer.
  6565. */
  6566. void arm_min_f32(
  6567. const float32_t * pSrc,
  6568. uint32_t blockSize,
  6569. float32_t * pResult,
  6570. uint32_t * pIndex);
  6571. /**
  6572. * @brief Maximum value of a Q7 vector.
  6573. * @param[in] pSrc points to the input buffer
  6574. * @param[in] blockSize length of the input vector
  6575. * @param[out] pResult maximum value returned here
  6576. * @param[out] pIndex index of maximum value returned here
  6577. */
  6578. void arm_max_q7(
  6579. const q7_t * pSrc,
  6580. uint32_t blockSize,
  6581. q7_t * pResult,
  6582. uint32_t * pIndex);
  6583. /**
  6584. * @brief Maximum value of a Q15 vector.
  6585. * @param[in] pSrc points to the input buffer
  6586. * @param[in] blockSize length of the input vector
  6587. * @param[out] pResult maximum value returned here
  6588. * @param[out] pIndex index of maximum value returned here
  6589. */
  6590. void arm_max_q15(
  6591. const q15_t * pSrc,
  6592. uint32_t blockSize,
  6593. q15_t * pResult,
  6594. uint32_t * pIndex);
  6595. /**
  6596. * @brief Maximum value of a Q31 vector.
  6597. * @param[in] pSrc points to the input buffer
  6598. * @param[in] blockSize length of the input vector
  6599. * @param[out] pResult maximum value returned here
  6600. * @param[out] pIndex index of maximum value returned here
  6601. */
  6602. void arm_max_q31(
  6603. const q31_t * pSrc,
  6604. uint32_t blockSize,
  6605. q31_t * pResult,
  6606. uint32_t * pIndex);
  6607. /**
  6608. * @brief Maximum value of a floating-point vector.
  6609. * @param[in] pSrc points to the input buffer
  6610. * @param[in] blockSize length of the input vector
  6611. * @param[out] pResult maximum value returned here
  6612. * @param[out] pIndex index of maximum value returned here
  6613. */
  6614. void arm_max_f32(
  6615. const float32_t * pSrc,
  6616. uint32_t blockSize,
  6617. float32_t * pResult,
  6618. uint32_t * pIndex);
  6619. /**
  6620. @brief Maximum value of a floating-point vector.
  6621. @param[in] pSrc points to the input vector
  6622. @param[in] blockSize number of samples in input vector
  6623. @param[out] pResult maximum value returned here
  6624. @return none
  6625. */
  6626. void arm_max_no_idx_f32(
  6627. const float32_t *pSrc,
  6628. uint32_t blockSize,
  6629. float32_t *pResult);
  6630. /**
  6631. * @brief Q15 complex-by-complex multiplication
  6632. * @param[in] pSrcA points to the first input vector
  6633. * @param[in] pSrcB points to the second input vector
  6634. * @param[out] pDst points to the output vector
  6635. * @param[in] numSamples number of complex samples in each vector
  6636. */
  6637. void arm_cmplx_mult_cmplx_q15(
  6638. const q15_t * pSrcA,
  6639. const q15_t * pSrcB,
  6640. q15_t * pDst,
  6641. uint32_t numSamples);
  6642. /**
  6643. * @brief Q31 complex-by-complex multiplication
  6644. * @param[in] pSrcA points to the first input vector
  6645. * @param[in] pSrcB points to the second input vector
  6646. * @param[out] pDst points to the output vector
  6647. * @param[in] numSamples number of complex samples in each vector
  6648. */
  6649. void arm_cmplx_mult_cmplx_q31(
  6650. const q31_t * pSrcA,
  6651. const q31_t * pSrcB,
  6652. q31_t * pDst,
  6653. uint32_t numSamples);
  6654. /**
  6655. * @brief Floating-point complex-by-complex multiplication
  6656. * @param[in] pSrcA points to the first input vector
  6657. * @param[in] pSrcB points to the second input vector
  6658. * @param[out] pDst points to the output vector
  6659. * @param[in] numSamples number of complex samples in each vector
  6660. */
  6661. void arm_cmplx_mult_cmplx_f32(
  6662. const float32_t * pSrcA,
  6663. const float32_t * pSrcB,
  6664. float32_t * pDst,
  6665. uint32_t numSamples);
  6666. /**
  6667. * @brief Converts the elements of the floating-point vector to Q31 vector.
  6668. * @param[in] pSrc points to the floating-point input vector
  6669. * @param[out] pDst points to the Q31 output vector
  6670. * @param[in] blockSize length of the input vector
  6671. */
  6672. void arm_float_to_q31(
  6673. const float32_t * pSrc,
  6674. q31_t * pDst,
  6675. uint32_t blockSize);
  6676. /**
  6677. * @brief Converts the elements of the floating-point vector to Q15 vector.
  6678. * @param[in] pSrc points to the floating-point input vector
  6679. * @param[out] pDst points to the Q15 output vector
  6680. * @param[in] blockSize length of the input vector
  6681. */
  6682. void arm_float_to_q15(
  6683. const float32_t * pSrc,
  6684. q15_t * pDst,
  6685. uint32_t blockSize);
  6686. /**
  6687. * @brief Converts the elements of the floating-point vector to Q7 vector.
  6688. * @param[in] pSrc points to the floating-point input vector
  6689. * @param[out] pDst points to the Q7 output vector
  6690. * @param[in] blockSize length of the input vector
  6691. */
  6692. void arm_float_to_q7(
  6693. const float32_t * pSrc,
  6694. q7_t * pDst,
  6695. uint32_t blockSize);
  6696. /**
  6697. * @brief Converts the elements of the Q31 vector to floating-point vector.
  6698. * @param[in] pSrc is input pointer
  6699. * @param[out] pDst is output pointer
  6700. * @param[in] blockSize is the number of samples to process
  6701. */
  6702. void arm_q31_to_float(
  6703. const q31_t * pSrc,
  6704. float32_t * pDst,
  6705. uint32_t blockSize);
  6706. /**
  6707. * @brief Converts the elements of the Q31 vector to Q15 vector.
  6708. * @param[in] pSrc is input pointer
  6709. * @param[out] pDst is output pointer
  6710. * @param[in] blockSize is the number of samples to process
  6711. */
  6712. void arm_q31_to_q15(
  6713. const q31_t * pSrc,
  6714. q15_t * pDst,
  6715. uint32_t blockSize);
  6716. /**
  6717. * @brief Converts the elements of the Q31 vector to Q7 vector.
  6718. * @param[in] pSrc is input pointer
  6719. * @param[out] pDst is output pointer
  6720. * @param[in] blockSize is the number of samples to process
  6721. */
  6722. void arm_q31_to_q7(
  6723. const q31_t * pSrc,
  6724. q7_t * pDst,
  6725. uint32_t blockSize);
  6726. /**
  6727. * @brief Converts the elements of the Q15 vector to floating-point vector.
  6728. * @param[in] pSrc is input pointer
  6729. * @param[out] pDst is output pointer
  6730. * @param[in] blockSize is the number of samples to process
  6731. */
  6732. void arm_q15_to_float(
  6733. const q15_t * pSrc,
  6734. float32_t * pDst,
  6735. uint32_t blockSize);
  6736. /**
  6737. * @brief Converts the elements of the Q15 vector to Q31 vector.
  6738. * @param[in] pSrc is input pointer
  6739. * @param[out] pDst is output pointer
  6740. * @param[in] blockSize is the number of samples to process
  6741. */
  6742. void arm_q15_to_q31(
  6743. const q15_t * pSrc,
  6744. q31_t * pDst,
  6745. uint32_t blockSize);
  6746. /**
  6747. * @brief Converts the elements of the Q15 vector to Q7 vector.
  6748. * @param[in] pSrc is input pointer
  6749. * @param[out] pDst is output pointer
  6750. * @param[in] blockSize is the number of samples to process
  6751. */
  6752. void arm_q15_to_q7(
  6753. const q15_t * pSrc,
  6754. q7_t * pDst,
  6755. uint32_t blockSize);
  6756. /**
  6757. * @brief Converts the elements of the Q7 vector to floating-point vector.
  6758. * @param[in] pSrc is input pointer
  6759. * @param[out] pDst is output pointer
  6760. * @param[in] blockSize is the number of samples to process
  6761. */
  6762. void arm_q7_to_float(
  6763. const q7_t * pSrc,
  6764. float32_t * pDst,
  6765. uint32_t blockSize);
  6766. /**
  6767. * @brief Converts the elements of the Q7 vector to Q31 vector.
  6768. * @param[in] pSrc input pointer
  6769. * @param[out] pDst output pointer
  6770. * @param[in] blockSize number of samples to process
  6771. */
  6772. void arm_q7_to_q31(
  6773. const q7_t * pSrc,
  6774. q31_t * pDst,
  6775. uint32_t blockSize);
  6776. /**
  6777. * @brief Converts the elements of the Q7 vector to Q15 vector.
  6778. * @param[in] pSrc input pointer
  6779. * @param[out] pDst output pointer
  6780. * @param[in] blockSize number of samples to process
  6781. */
  6782. void arm_q7_to_q15(
  6783. const q7_t * pSrc,
  6784. q15_t * pDst,
  6785. uint32_t blockSize);
  6786. /**
  6787. * @brief Struct for specifying SVM Kernel
  6788. */
  6789. typedef enum
  6790. {
  6791. ARM_ML_KERNEL_LINEAR = 0,
  6792. /**< Linear kernel */
  6793. ARM_ML_KERNEL_POLYNOMIAL = 1,
  6794. /**< Polynomial kernel */
  6795. ARM_ML_KERNEL_RBF = 2,
  6796. /**< Radial Basis Function kernel */
  6797. ARM_ML_KERNEL_SIGMOID = 3
  6798. /**< Sigmoid kernel */
  6799. } arm_ml_kernel_type;
  6800. /**
  6801. * @brief Instance structure for linear SVM prediction function.
  6802. */
  6803. typedef struct
  6804. {
  6805. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6806. uint32_t vectorDimension; /**< Dimension of vector space */
  6807. float32_t intercept; /**< Intercept */
  6808. const float32_t *dualCoefficients; /**< Dual coefficients */
  6809. const float32_t *supportVectors; /**< Support vectors */
  6810. const int32_t *classes; /**< The two SVM classes */
  6811. } arm_svm_linear_instance_f32;
  6812. /**
  6813. * @brief Instance structure for polynomial SVM prediction function.
  6814. */
  6815. typedef struct
  6816. {
  6817. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6818. uint32_t vectorDimension; /**< Dimension of vector space */
  6819. float32_t intercept; /**< Intercept */
  6820. const float32_t *dualCoefficients; /**< Dual coefficients */
  6821. const float32_t *supportVectors; /**< Support vectors */
  6822. const int32_t *classes; /**< The two SVM classes */
  6823. int32_t degree; /**< Polynomial degree */
  6824. float32_t coef0; /**< Polynomial constant */
  6825. float32_t gamma; /**< Gamma factor */
  6826. } arm_svm_polynomial_instance_f32;
  6827. /**
  6828. * @brief Instance structure for rbf SVM prediction function.
  6829. */
  6830. typedef struct
  6831. {
  6832. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6833. uint32_t vectorDimension; /**< Dimension of vector space */
  6834. float32_t intercept; /**< Intercept */
  6835. const float32_t *dualCoefficients; /**< Dual coefficients */
  6836. const float32_t *supportVectors; /**< Support vectors */
  6837. const int32_t *classes; /**< The two SVM classes */
  6838. float32_t gamma; /**< Gamma factor */
  6839. } arm_svm_rbf_instance_f32;
  6840. /**
  6841. * @brief Instance structure for sigmoid SVM prediction function.
  6842. */
  6843. typedef struct
  6844. {
  6845. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6846. uint32_t vectorDimension; /**< Dimension of vector space */
  6847. float32_t intercept; /**< Intercept */
  6848. const float32_t *dualCoefficients; /**< Dual coefficients */
  6849. const float32_t *supportVectors; /**< Support vectors */
  6850. const int32_t *classes; /**< The two SVM classes */
  6851. float32_t coef0; /**< Independant constant */
  6852. float32_t gamma; /**< Gamma factor */
  6853. } arm_svm_sigmoid_instance_f32;
  6854. /**
  6855. * @brief SVM linear instance init function
  6856. * @param[in] S Parameters for SVM functions
  6857. * @param[in] nbOfSupportVectors Number of support vectors
  6858. * @param[in] vectorDimension Dimension of vector space
  6859. * @param[in] intercept Intercept
  6860. * @param[in] dualCoefficients Array of dual coefficients
  6861. * @param[in] supportVectors Array of support vectors
  6862. * @param[in] classes Array of 2 classes ID
  6863. * @return none.
  6864. *
  6865. */
  6866. void arm_svm_linear_init_f32(arm_svm_linear_instance_f32 *S,
  6867. uint32_t nbOfSupportVectors,
  6868. uint32_t vectorDimension,
  6869. float32_t intercept,
  6870. const float32_t *dualCoefficients,
  6871. const float32_t *supportVectors,
  6872. const int32_t *classes);
  6873. /**
  6874. * @brief SVM linear prediction
  6875. * @param[in] S Pointer to an instance of the linear SVM structure.
  6876. * @param[in] in Pointer to input vector
  6877. * @param[out] pResult Decision value
  6878. * @return none.
  6879. *
  6880. */
  6881. void arm_svm_linear_predict_f32(const arm_svm_linear_instance_f32 *S,
  6882. const float32_t * in,
  6883. int32_t * pResult);
  6884. /**
  6885. * @brief SVM polynomial instance init function
  6886. * @param[in] S points to an instance of the polynomial SVM structure.
  6887. * @param[in] nbOfSupportVectors Number of support vectors
  6888. * @param[in] vectorDimension Dimension of vector space
  6889. * @param[in] intercept Intercept
  6890. * @param[in] dualCoefficients Array of dual coefficients
  6891. * @param[in] supportVectors Array of support vectors
  6892. * @param[in] classes Array of 2 classes ID
  6893. * @param[in] degree Polynomial degree
  6894. * @param[in] coef0 coeff0 (scikit-learn terminology)
  6895. * @param[in] gamma gamma (scikit-learn terminology)
  6896. * @return none.
  6897. *
  6898. */
  6899. void arm_svm_polynomial_init_f32(arm_svm_polynomial_instance_f32 *S,
  6900. uint32_t nbOfSupportVectors,
  6901. uint32_t vectorDimension,
  6902. float32_t intercept,
  6903. const float32_t *dualCoefficients,
  6904. const float32_t *supportVectors,
  6905. const int32_t *classes,
  6906. int32_t degree,
  6907. float32_t coef0,
  6908. float32_t gamma
  6909. );
  6910. /**
  6911. * @brief SVM polynomial prediction
  6912. * @param[in] S Pointer to an instance of the polynomial SVM structure.
  6913. * @param[in] in Pointer to input vector
  6914. * @param[out] pResult Decision value
  6915. * @return none.
  6916. *
  6917. */
  6918. void arm_svm_polynomial_predict_f32(const arm_svm_polynomial_instance_f32 *S,
  6919. const float32_t * in,
  6920. int32_t * pResult);
  6921. /**
  6922. * @brief SVM radial basis function instance init function
  6923. * @param[in] S points to an instance of the polynomial SVM structure.
  6924. * @param[in] nbOfSupportVectors Number of support vectors
  6925. * @param[in] vectorDimension Dimension of vector space
  6926. * @param[in] intercept Intercept
  6927. * @param[in] dualCoefficients Array of dual coefficients
  6928. * @param[in] supportVectors Array of support vectors
  6929. * @param[in] classes Array of 2 classes ID
  6930. * @param[in] gamma gamma (scikit-learn terminology)
  6931. * @return none.
  6932. *
  6933. */
  6934. void arm_svm_rbf_init_f32(arm_svm_rbf_instance_f32 *S,
  6935. uint32_t nbOfSupportVectors,
  6936. uint32_t vectorDimension,
  6937. float32_t intercept,
  6938. const float32_t *dualCoefficients,
  6939. const float32_t *supportVectors,
  6940. const int32_t *classes,
  6941. float32_t gamma
  6942. );
  6943. /**
  6944. * @brief SVM rbf prediction
  6945. * @param[in] S Pointer to an instance of the rbf SVM structure.
  6946. * @param[in] in Pointer to input vector
  6947. * @param[out] pResult decision value
  6948. * @return none.
  6949. *
  6950. */
  6951. void arm_svm_rbf_predict_f32(const arm_svm_rbf_instance_f32 *S,
  6952. const float32_t * in,
  6953. int32_t * pResult);
  6954. /**
  6955. * @brief SVM sigmoid instance init function
  6956. * @param[in] S points to an instance of the rbf SVM structure.
  6957. * @param[in] nbOfSupportVectors Number of support vectors
  6958. * @param[in] vectorDimension Dimension of vector space
  6959. * @param[in] intercept Intercept
  6960. * @param[in] dualCoefficients Array of dual coefficients
  6961. * @param[in] supportVectors Array of support vectors
  6962. * @param[in] classes Array of 2 classes ID
  6963. * @param[in] coef0 coeff0 (scikit-learn terminology)
  6964. * @param[in] gamma gamma (scikit-learn terminology)
  6965. * @return none.
  6966. *
  6967. */
  6968. void arm_svm_sigmoid_init_f32(arm_svm_sigmoid_instance_f32 *S,
  6969. uint32_t nbOfSupportVectors,
  6970. uint32_t vectorDimension,
  6971. float32_t intercept,
  6972. const float32_t *dualCoefficients,
  6973. const float32_t *supportVectors,
  6974. const int32_t *classes,
  6975. float32_t coef0,
  6976. float32_t gamma
  6977. );
  6978. /**
  6979. * @brief SVM sigmoid prediction
  6980. * @param[in] S Pointer to an instance of the rbf SVM structure.
  6981. * @param[in] in Pointer to input vector
  6982. * @param[out] pResult Decision value
  6983. * @return none.
  6984. *
  6985. */
  6986. void arm_svm_sigmoid_predict_f32(const arm_svm_sigmoid_instance_f32 *S,
  6987. const float32_t * in,
  6988. int32_t * pResult);
  6989. /**
  6990. * @brief Instance structure for Naive Gaussian Bayesian estimator.
  6991. */
  6992. typedef struct
  6993. {
  6994. uint32_t vectorDimension; /**< Dimension of vector space */
  6995. uint32_t numberOfClasses; /**< Number of different classes */
  6996. const float32_t *theta; /**< Mean values for the Gaussians */
  6997. const float32_t *sigma; /**< Variances for the Gaussians */
  6998. const float32_t *classPriors; /**< Class prior probabilities */
  6999. float32_t epsilon; /**< Additive value to variances */
  7000. } arm_gaussian_naive_bayes_instance_f32;
  7001. /**
  7002. * @brief Naive Gaussian Bayesian Estimator
  7003. *
  7004. * @param[in] S points to a naive bayes instance structure
  7005. * @param[in] in points to the elements of the input vector.
  7006. * @param[in] pBuffer points to a buffer of length numberOfClasses
  7007. * @return The predicted class
  7008. *
  7009. */
  7010. uint32_t arm_gaussian_naive_bayes_predict_f32(const arm_gaussian_naive_bayes_instance_f32 *S,
  7011. const float32_t * in,
  7012. float32_t *pBuffer);
  7013. /**
  7014. * @brief Computation of the LogSumExp
  7015. *
  7016. * In probabilistic computations, the dynamic of the probability values can be very
  7017. * wide because they come from gaussian functions.
  7018. * To avoid underflow and overflow issues, the values are represented by their log.
  7019. * In this representation, multiplying the original exp values is easy : their logs are added.
  7020. * But adding the original exp values is requiring some special handling and it is the
  7021. * goal of the LogSumExp function.
  7022. *
  7023. * If the values are x1...xn, the function is computing:
  7024. *
  7025. * ln(exp(x1) + ... + exp(xn)) and the computation is done in such a way that
  7026. * rounding issues are minimised.
  7027. *
  7028. * The max xm of the values is extracted and the function is computing:
  7029. * xm + ln(exp(x1 - xm) + ... + exp(xn - xm))
  7030. *
  7031. * @param[in] *in Pointer to an array of input values.
  7032. * @param[in] blockSize Number of samples in the input array.
  7033. * @return LogSumExp
  7034. *
  7035. */
  7036. float32_t arm_logsumexp_f32(const float32_t *in, uint32_t blockSize);
  7037. /**
  7038. * @brief Dot product with log arithmetic
  7039. *
  7040. * Vectors are containing the log of the samples
  7041. *
  7042. * @param[in] pSrcA points to the first input vector
  7043. * @param[in] pSrcB points to the second input vector
  7044. * @param[in] blockSize number of samples in each vector
  7045. * @param[in] pTmpBuffer temporary buffer of length blockSize
  7046. * @return The log of the dot product .
  7047. *
  7048. */
  7049. float32_t arm_logsumexp_dot_prod_f32(const float32_t * pSrcA,
  7050. const float32_t * pSrcB,
  7051. uint32_t blockSize,
  7052. float32_t *pTmpBuffer);
  7053. /**
  7054. * @brief Entropy
  7055. *
  7056. * @param[in] pSrcA Array of input values.
  7057. * @param[in] blockSize Number of samples in the input array.
  7058. * @return Entropy -Sum(p ln p)
  7059. *
  7060. */
  7061. float32_t arm_entropy_f32(const float32_t * pSrcA,uint32_t blockSize);
  7062. /**
  7063. * @brief Entropy
  7064. *
  7065. * @param[in] pSrcA Array of input values.
  7066. * @param[in] blockSize Number of samples in the input array.
  7067. * @return Entropy -Sum(p ln p)
  7068. *
  7069. */
  7070. float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize);
  7071. /**
  7072. * @brief Kullback-Leibler
  7073. *
  7074. * @param[in] pSrcA Pointer to an array of input values for probability distribution A.
  7075. * @param[in] pSrcB Pointer to an array of input values for probability distribution B.
  7076. * @param[in] blockSize Number of samples in the input array.
  7077. * @return Kullback-Leibler Divergence D(A || B)
  7078. *
  7079. */
  7080. float32_t arm_kullback_leibler_f32(const float32_t * pSrcA
  7081. ,const float32_t * pSrcB
  7082. ,uint32_t blockSize);
  7083. /**
  7084. * @brief Kullback-Leibler
  7085. *
  7086. * @param[in] pSrcA Pointer to an array of input values for probability distribution A.
  7087. * @param[in] pSrcB Pointer to an array of input values for probability distribution B.
  7088. * @param[in] blockSize Number of samples in the input array.
  7089. * @return Kullback-Leibler Divergence D(A || B)
  7090. *
  7091. */
  7092. float64_t arm_kullback_leibler_f64(const float64_t * pSrcA,
  7093. const float64_t * pSrcB,
  7094. uint32_t blockSize);
  7095. /**
  7096. * @brief Weighted sum
  7097. *
  7098. *
  7099. * @param[in] *in Array of input values.
  7100. * @param[in] *weigths Weights
  7101. * @param[in] blockSize Number of samples in the input array.
  7102. * @return Weighted sum
  7103. *
  7104. */
  7105. float32_t arm_weighted_sum_f32(const float32_t *in
  7106. , const float32_t *weigths
  7107. , uint32_t blockSize);
  7108. /**
  7109. * @brief Barycenter
  7110. *
  7111. *
  7112. * @param[in] in List of vectors
  7113. * @param[in] weights Weights of the vectors
  7114. * @param[out] out Barycenter
  7115. * @param[in] nbVectors Number of vectors
  7116. * @param[in] vecDim Dimension of space (vector dimension)
  7117. * @return None
  7118. *
  7119. */
  7120. void arm_barycenter_f32(const float32_t *in
  7121. , const float32_t *weights
  7122. , float32_t *out
  7123. , uint32_t nbVectors
  7124. , uint32_t vecDim);
  7125. /**
  7126. * @brief Euclidean distance between two vectors
  7127. * @param[in] pA First vector
  7128. * @param[in] pB Second vector
  7129. * @param[in] blockSize vector length
  7130. * @return distance
  7131. *
  7132. */
  7133. float32_t arm_euclidean_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7134. /**
  7135. * @brief Bray-Curtis distance between two vectors
  7136. * @param[in] pA First vector
  7137. * @param[in] pB Second vector
  7138. * @param[in] blockSize vector length
  7139. * @return distance
  7140. *
  7141. */
  7142. float32_t arm_braycurtis_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7143. /**
  7144. * @brief Canberra distance between two vectors
  7145. *
  7146. * This function may divide by zero when samples pA[i] and pB[i] are both zero.
  7147. * The result of the computation will be correct. So the division per zero may be
  7148. * ignored.
  7149. *
  7150. * @param[in] pA First vector
  7151. * @param[in] pB Second vector
  7152. * @param[in] blockSize vector length
  7153. * @return distance
  7154. *
  7155. */
  7156. float32_t arm_canberra_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7157. /**
  7158. * @brief Chebyshev distance between two vectors
  7159. * @param[in] pA First vector
  7160. * @param[in] pB Second vector
  7161. * @param[in] blockSize vector length
  7162. * @return distance
  7163. *
  7164. */
  7165. float32_t arm_chebyshev_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7166. /**
  7167. * @brief Cityblock (Manhattan) distance between two vectors
  7168. * @param[in] pA First vector
  7169. * @param[in] pB Second vector
  7170. * @param[in] blockSize vector length
  7171. * @return distance
  7172. *
  7173. */
  7174. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7175. /**
  7176. * @brief Correlation distance between two vectors
  7177. *
  7178. * The input vectors are modified in place !
  7179. *
  7180. * @param[in] pA First vector
  7181. * @param[in] pB Second vector
  7182. * @param[in] blockSize vector length
  7183. * @return distance
  7184. *
  7185. */
  7186. float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize);
  7187. /**
  7188. * @brief Cosine distance between two vectors
  7189. *
  7190. * @param[in] pA First vector
  7191. * @param[in] pB Second vector
  7192. * @param[in] blockSize vector length
  7193. * @return distance
  7194. *
  7195. */
  7196. float32_t arm_cosine_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7197. /**
  7198. * @brief Jensen-Shannon distance between two vectors
  7199. *
  7200. * This function is assuming that elements of second vector are > 0
  7201. * and 0 only when the corresponding element of first vector is 0.
  7202. * Otherwise the result of the computation does not make sense
  7203. * and for speed reasons, the cases returning NaN or Infinity are not
  7204. * managed.
  7205. *
  7206. * When the function is computing x log (x / y) with x 0 and y 0,
  7207. * it will compute the right value (0) but a division per zero will occur
  7208. * and shoudl be ignored in client code.
  7209. *
  7210. * @param[in] pA First vector
  7211. * @param[in] pB Second vector
  7212. * @param[in] blockSize vector length
  7213. * @return distance
  7214. *
  7215. */
  7216. float32_t arm_jensenshannon_distance_f32(const float32_t *pA,const float32_t *pB,uint32_t blockSize);
  7217. /**
  7218. * @brief Minkowski distance between two vectors
  7219. *
  7220. * @param[in] pA First vector
  7221. * @param[in] pB Second vector
  7222. * @param[in] n Norm order (>= 2)
  7223. * @param[in] blockSize vector length
  7224. * @return distance
  7225. *
  7226. */
  7227. float32_t arm_minkowski_distance_f32(const float32_t *pA,const float32_t *pB, int32_t order, uint32_t blockSize);
  7228. /**
  7229. * @brief Dice distance between two vectors
  7230. *
  7231. * @param[in] pA First vector of packed booleans
  7232. * @param[in] pB Second vector of packed booleans
  7233. * @param[in] order Distance order
  7234. * @param[in] blockSize Number of samples
  7235. * @return distance
  7236. *
  7237. */
  7238. float32_t arm_dice_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7239. /**
  7240. * @brief Hamming distance between two vectors
  7241. *
  7242. * @param[in] pA First vector of packed booleans
  7243. * @param[in] pB Second vector of packed booleans
  7244. * @param[in] numberOfBools Number of booleans
  7245. * @return distance
  7246. *
  7247. */
  7248. float32_t arm_hamming_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7249. /**
  7250. * @brief Jaccard distance between two vectors
  7251. *
  7252. * @param[in] pA First vector of packed booleans
  7253. * @param[in] pB Second vector of packed booleans
  7254. * @param[in] numberOfBools Number of booleans
  7255. * @return distance
  7256. *
  7257. */
  7258. float32_t arm_jaccard_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7259. /**
  7260. * @brief Kulsinski distance between two vectors
  7261. *
  7262. * @param[in] pA First vector of packed booleans
  7263. * @param[in] pB Second vector of packed booleans
  7264. * @param[in] numberOfBools Number of booleans
  7265. * @return distance
  7266. *
  7267. */
  7268. float32_t arm_kulsinski_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7269. /**
  7270. * @brief Roger Stanimoto distance between two vectors
  7271. *
  7272. * @param[in] pA First vector of packed booleans
  7273. * @param[in] pB Second vector of packed booleans
  7274. * @param[in] numberOfBools Number of booleans
  7275. * @return distance
  7276. *
  7277. */
  7278. float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7279. /**
  7280. * @brief Russell-Rao distance between two vectors
  7281. *
  7282. * @param[in] pA First vector of packed booleans
  7283. * @param[in] pB Second vector of packed booleans
  7284. * @param[in] numberOfBools Number of booleans
  7285. * @return distance
  7286. *
  7287. */
  7288. float32_t arm_russellrao_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7289. /**
  7290. * @brief Sokal-Michener distance between two vectors
  7291. *
  7292. * @param[in] pA First vector of packed booleans
  7293. * @param[in] pB Second vector of packed booleans
  7294. * @param[in] numberOfBools Number of booleans
  7295. * @return distance
  7296. *
  7297. */
  7298. float32_t arm_sokalmichener_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7299. /**
  7300. * @brief Sokal-Sneath distance between two vectors
  7301. *
  7302. * @param[in] pA First vector of packed booleans
  7303. * @param[in] pB Second vector of packed booleans
  7304. * @param[in] numberOfBools Number of booleans
  7305. * @return distance
  7306. *
  7307. */
  7308. float32_t arm_sokalsneath_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7309. /**
  7310. * @brief Yule distance between two vectors
  7311. *
  7312. * @param[in] pA First vector of packed booleans
  7313. * @param[in] pB Second vector of packed booleans
  7314. * @param[in] numberOfBools Number of booleans
  7315. * @return distance
  7316. *
  7317. */
  7318. float32_t arm_yule_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7319. /**
  7320. * @ingroup groupInterpolation
  7321. */
  7322. /**
  7323. * @defgroup BilinearInterpolate Bilinear Interpolation
  7324. *
  7325. * Bilinear interpolation is an extension of linear interpolation applied to a two dimensional grid.
  7326. * The underlying function <code>f(x, y)</code> is sampled on a regular grid and the interpolation process
  7327. * determines values between the grid points.
  7328. * Bilinear interpolation is equivalent to two step linear interpolation, first in the x-dimension and then in the y-dimension.
  7329. * Bilinear interpolation is often used in image processing to rescale images.
  7330. * The CMSIS DSP library provides bilinear interpolation functions for Q7, Q15, Q31, and floating-point data types.
  7331. *
  7332. * <b>Algorithm</b>
  7333. * \par
  7334. * The instance structure used by the bilinear interpolation functions describes a two dimensional data table.
  7335. * For floating-point, the instance structure is defined as:
  7336. * <pre>
  7337. * typedef struct
  7338. * {
  7339. * uint16_t numRows;
  7340. * uint16_t numCols;
  7341. * float32_t *pData;
  7342. * } arm_bilinear_interp_instance_f32;
  7343. * </pre>
  7344. *
  7345. * \par
  7346. * where <code>numRows</code> specifies the number of rows in the table;
  7347. * <code>numCols</code> specifies the number of columns in the table;
  7348. * and <code>pData</code> points to an array of size <code>numRows*numCols</code> values.
  7349. * The data table <code>pTable</code> is organized in row order and the supplied data values fall on integer indexes.
  7350. * That is, table element (x,y) is located at <code>pTable[x + y*numCols]</code> where x and y are integers.
  7351. *
  7352. * \par
  7353. * Let <code>(x, y)</code> specify the desired interpolation point. Then define:
  7354. * <pre>
  7355. * XF = floor(x)
  7356. * YF = floor(y)
  7357. * </pre>
  7358. * \par
  7359. * The interpolated output point is computed as:
  7360. * <pre>
  7361. * f(x, y) = f(XF, YF) * (1-(x-XF)) * (1-(y-YF))
  7362. * + f(XF+1, YF) * (x-XF)*(1-(y-YF))
  7363. * + f(XF, YF+1) * (1-(x-XF))*(y-YF)
  7364. * + f(XF+1, YF+1) * (x-XF)*(y-YF)
  7365. * </pre>
  7366. * Note that the coordinates (x, y) contain integer and fractional components.
  7367. * The integer components specify which portion of the table to use while the
  7368. * fractional components control the interpolation processor.
  7369. *
  7370. * \par
  7371. * if (x,y) are outside of the table boundary, Bilinear interpolation returns zero output.
  7372. */
  7373. /**
  7374. * @addtogroup BilinearInterpolate
  7375. * @{
  7376. */
  7377. /**
  7378. * @brief Floating-point bilinear interpolation.
  7379. * @param[in,out] S points to an instance of the interpolation structure.
  7380. * @param[in] X interpolation coordinate.
  7381. * @param[in] Y interpolation coordinate.
  7382. * @return out interpolated value.
  7383. */
  7384. __STATIC_FORCEINLINE float32_t arm_bilinear_interp_f32(
  7385. const arm_bilinear_interp_instance_f32 * S,
  7386. float32_t X,
  7387. float32_t Y)
  7388. {
  7389. float32_t out;
  7390. float32_t f00, f01, f10, f11;
  7391. float32_t *pData = S->pData;
  7392. int32_t xIndex, yIndex, index;
  7393. float32_t xdiff, ydiff;
  7394. float32_t b1, b2, b3, b4;
  7395. xIndex = (int32_t) X;
  7396. yIndex = (int32_t) Y;
  7397. /* Care taken for table outside boundary */
  7398. /* Returns zero output when values are outside table boundary */
  7399. if (xIndex < 0 || xIndex > (S->numCols - 2) || yIndex < 0 || yIndex > (S->numRows - 2))
  7400. {
  7401. return (0);
  7402. }
  7403. /* Calculation of index for two nearest points in X-direction */
  7404. index = (xIndex ) + (yIndex ) * S->numCols;
  7405. /* Read two nearest points in X-direction */
  7406. f00 = pData[index];
  7407. f01 = pData[index + 1];
  7408. /* Calculation of index for two nearest points in Y-direction */
  7409. index = (xIndex ) + (yIndex+1) * S->numCols;
  7410. /* Read two nearest points in Y-direction */
  7411. f10 = pData[index];
  7412. f11 = pData[index + 1];
  7413. /* Calculation of intermediate values */
  7414. b1 = f00;
  7415. b2 = f01 - f00;
  7416. b3 = f10 - f00;
  7417. b4 = f00 - f01 - f10 + f11;
  7418. /* Calculation of fractional part in X */
  7419. xdiff = X - xIndex;
  7420. /* Calculation of fractional part in Y */
  7421. ydiff = Y - yIndex;
  7422. /* Calculation of bi-linear interpolated output */
  7423. out = b1 + b2 * xdiff + b3 * ydiff + b4 * xdiff * ydiff;
  7424. /* return to application */
  7425. return (out);
  7426. }
  7427. /**
  7428. * @brief Q31 bilinear interpolation.
  7429. * @param[in,out] S points to an instance of the interpolation structure.
  7430. * @param[in] X interpolation coordinate in 12.20 format.
  7431. * @param[in] Y interpolation coordinate in 12.20 format.
  7432. * @return out interpolated value.
  7433. */
  7434. __STATIC_FORCEINLINE q31_t arm_bilinear_interp_q31(
  7435. arm_bilinear_interp_instance_q31 * S,
  7436. q31_t X,
  7437. q31_t Y)
  7438. {
  7439. q31_t out; /* Temporary output */
  7440. q31_t acc = 0; /* output */
  7441. q31_t xfract, yfract; /* X, Y fractional parts */
  7442. q31_t x1, x2, y1, y2; /* Nearest output values */
  7443. int32_t rI, cI; /* Row and column indices */
  7444. q31_t *pYData = S->pData; /* pointer to output table values */
  7445. uint32_t nCols = S->numCols; /* num of rows */
  7446. /* Input is in 12.20 format */
  7447. /* 12 bits for the table index */
  7448. /* Index value calculation */
  7449. rI = ((X & (q31_t)0xFFF00000) >> 20);
  7450. /* Input is in 12.20 format */
  7451. /* 12 bits for the table index */
  7452. /* Index value calculation */
  7453. cI = ((Y & (q31_t)0xFFF00000) >> 20);
  7454. /* Care taken for table outside boundary */
  7455. /* Returns zero output when values are outside table boundary */
  7456. if (rI < 0 || rI > (S->numCols - 2) || cI < 0 || cI > (S->numRows - 2))
  7457. {
  7458. return (0);
  7459. }
  7460. /* 20 bits for the fractional part */
  7461. /* shift left xfract by 11 to keep 1.31 format */
  7462. xfract = (X & 0x000FFFFF) << 11U;
  7463. /* Read two nearest output values from the index */
  7464. x1 = pYData[(rI) + (int32_t)nCols * (cI) ];
  7465. x2 = pYData[(rI) + (int32_t)nCols * (cI) + 1];
  7466. /* 20 bits for the fractional part */
  7467. /* shift left yfract by 11 to keep 1.31 format */
  7468. yfract = (Y & 0x000FFFFF) << 11U;
  7469. /* Read two nearest output values from the index */
  7470. y1 = pYData[(rI) + (int32_t)nCols * (cI + 1) ];
  7471. y2 = pYData[(rI) + (int32_t)nCols * (cI + 1) + 1];
  7472. /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 3.29(q29) format */
  7473. out = ((q31_t) (((q63_t) x1 * (0x7FFFFFFF - xfract)) >> 32));
  7474. acc = ((q31_t) (((q63_t) out * (0x7FFFFFFF - yfract)) >> 32));
  7475. /* x2 * (xfract) * (1-yfract) in 3.29(q29) and adding to acc */
  7476. out = ((q31_t) ((q63_t) x2 * (0x7FFFFFFF - yfract) >> 32));
  7477. acc += ((q31_t) ((q63_t) out * (xfract) >> 32));
  7478. /* y1 * (1 - xfract) * (yfract) in 3.29(q29) and adding to acc */
  7479. out = ((q31_t) ((q63_t) y1 * (0x7FFFFFFF - xfract) >> 32));
  7480. acc += ((q31_t) ((q63_t) out * (yfract) >> 32));
  7481. /* y2 * (xfract) * (yfract) in 3.29(q29) and adding to acc */
  7482. out = ((q31_t) ((q63_t) y2 * (xfract) >> 32));
  7483. acc += ((q31_t) ((q63_t) out * (yfract) >> 32));
  7484. /* Convert acc to 1.31(q31) format */
  7485. return ((q31_t)(acc << 2));
  7486. }
  7487. /**
  7488. * @brief Q15 bilinear interpolation.
  7489. * @param[in,out] S points to an instance of the interpolation structure.
  7490. * @param[in] X interpolation coordinate in 12.20 format.
  7491. * @param[in] Y interpolation coordinate in 12.20 format.
  7492. * @return out interpolated value.
  7493. */
  7494. __STATIC_FORCEINLINE q15_t arm_bilinear_interp_q15(
  7495. arm_bilinear_interp_instance_q15 * S,
  7496. q31_t X,
  7497. q31_t Y)
  7498. {
  7499. q63_t acc = 0; /* output */
  7500. q31_t out; /* Temporary output */
  7501. q15_t x1, x2, y1, y2; /* Nearest output values */
  7502. q31_t xfract, yfract; /* X, Y fractional parts */
  7503. int32_t rI, cI; /* Row and column indices */
  7504. q15_t *pYData = S->pData; /* pointer to output table values */
  7505. uint32_t nCols = S->numCols; /* num of rows */
  7506. /* Input is in 12.20 format */
  7507. /* 12 bits for the table index */
  7508. /* Index value calculation */
  7509. rI = ((X & (q31_t)0xFFF00000) >> 20);
  7510. /* Input is in 12.20 format */
  7511. /* 12 bits for the table index */
  7512. /* Index value calculation */
  7513. cI = ((Y & (q31_t)0xFFF00000) >> 20);
  7514. /* Care taken for table outside boundary */
  7515. /* Returns zero output when values are outside table boundary */
  7516. if (rI < 0 || rI > (S->numCols - 2) || cI < 0 || cI > (S->numRows - 2))
  7517. {
  7518. return (0);
  7519. }
  7520. /* 20 bits for the fractional part */
  7521. /* xfract should be in 12.20 format */
  7522. xfract = (X & 0x000FFFFF);
  7523. /* Read two nearest output values from the index */
  7524. x1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) ];
  7525. x2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) + 1];
  7526. /* 20 bits for the fractional part */
  7527. /* yfract should be in 12.20 format */
  7528. yfract = (Y & 0x000FFFFF);
  7529. /* Read two nearest output values from the index */
  7530. y1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) ];
  7531. y2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) + 1];
  7532. /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 13.51 format */
  7533. /* x1 is in 1.15(q15), xfract in 12.20 format and out is in 13.35 format */
  7534. /* convert 13.35 to 13.31 by right shifting and out is in 1.31 */
  7535. out = (q31_t) (((q63_t) x1 * (0x0FFFFF - xfract)) >> 4U);
  7536. acc = ((q63_t) out * (0x0FFFFF - yfract));
  7537. /* x2 * (xfract) * (1-yfract) in 1.51 and adding to acc */
  7538. out = (q31_t) (((q63_t) x2 * (0x0FFFFF - yfract)) >> 4U);
  7539. acc += ((q63_t) out * (xfract));
  7540. /* y1 * (1 - xfract) * (yfract) in 1.51 and adding to acc */
  7541. out = (q31_t) (((q63_t) y1 * (0x0FFFFF - xfract)) >> 4U);
  7542. acc += ((q63_t) out * (yfract));
  7543. /* y2 * (xfract) * (yfract) in 1.51 and adding to acc */
  7544. out = (q31_t) (((q63_t) y2 * (xfract)) >> 4U);
  7545. acc += ((q63_t) out * (yfract));
  7546. /* acc is in 13.51 format and down shift acc by 36 times */
  7547. /* Convert out to 1.15 format */
  7548. return ((q15_t)(acc >> 36));
  7549. }
  7550. /**
  7551. * @brief Q7 bilinear interpolation.
  7552. * @param[in,out] S points to an instance of the interpolation structure.
  7553. * @param[in] X interpolation coordinate in 12.20 format.
  7554. * @param[in] Y interpolation coordinate in 12.20 format.
  7555. * @return out interpolated value.
  7556. */
  7557. __STATIC_FORCEINLINE q7_t arm_bilinear_interp_q7(
  7558. arm_bilinear_interp_instance_q7 * S,
  7559. q31_t X,
  7560. q31_t Y)
  7561. {
  7562. q63_t acc = 0; /* output */
  7563. q31_t out; /* Temporary output */
  7564. q31_t xfract, yfract; /* X, Y fractional parts */
  7565. q7_t x1, x2, y1, y2; /* Nearest output values */
  7566. int32_t rI, cI; /* Row and column indices */
  7567. q7_t *pYData = S->pData; /* pointer to output table values */
  7568. uint32_t nCols = S->numCols; /* num of rows */
  7569. /* Input is in 12.20 format */
  7570. /* 12 bits for the table index */
  7571. /* Index value calculation */
  7572. rI = ((X & (q31_t)0xFFF00000) >> 20);
  7573. /* Input is in 12.20 format */
  7574. /* 12 bits for the table index */
  7575. /* Index value calculation */
  7576. cI = ((Y & (q31_t)0xFFF00000) >> 20);
  7577. /* Care taken for table outside boundary */
  7578. /* Returns zero output when values are outside table boundary */
  7579. if (rI < 0 || rI > (S->numCols - 2) || cI < 0 || cI > (S->numRows - 2))
  7580. {
  7581. return (0);
  7582. }
  7583. /* 20 bits for the fractional part */
  7584. /* xfract should be in 12.20 format */
  7585. xfract = (X & (q31_t)0x000FFFFF);
  7586. /* Read two nearest output values from the index */
  7587. x1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) ];
  7588. x2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) + 1];
  7589. /* 20 bits for the fractional part */
  7590. /* yfract should be in 12.20 format */
  7591. yfract = (Y & (q31_t)0x000FFFFF);
  7592. /* Read two nearest output values from the index */
  7593. y1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) ];
  7594. y2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) + 1];
  7595. /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 16.47 format */
  7596. out = ((x1 * (0xFFFFF - xfract)));
  7597. acc = (((q63_t) out * (0xFFFFF - yfract)));
  7598. /* x2 * (xfract) * (1-yfract) in 2.22 and adding to acc */
  7599. out = ((x2 * (0xFFFFF - yfract)));
  7600. acc += (((q63_t) out * (xfract)));
  7601. /* y1 * (1 - xfract) * (yfract) in 2.22 and adding to acc */
  7602. out = ((y1 * (0xFFFFF - xfract)));
  7603. acc += (((q63_t) out * (yfract)));
  7604. /* y2 * (xfract) * (yfract) in 2.22 and adding to acc */
  7605. out = ((y2 * (yfract)));
  7606. acc += (((q63_t) out * (xfract)));
  7607. /* acc in 16.47 format and down shift by 40 to convert to 1.7 format */
  7608. return ((q7_t)(acc >> 40));
  7609. }
  7610. /**
  7611. * @} end of BilinearInterpolate group
  7612. */
  7613. /* SMMLAR */
  7614. #define multAcc_32x32_keep32_R(a, x, y) \
  7615. a = (q31_t) (((((q63_t) a) << 32) + ((q63_t) x * y) + 0x80000000LL ) >> 32)
  7616. /* SMMLSR */
  7617. #define multSub_32x32_keep32_R(a, x, y) \
  7618. a = (q31_t) (((((q63_t) a) << 32) - ((q63_t) x * y) + 0x80000000LL ) >> 32)
  7619. /* SMMULR */
  7620. #define mult_32x32_keep32_R(a, x, y) \
  7621. a = (q31_t) (((q63_t) x * y + 0x80000000LL ) >> 32)
  7622. /* SMMLA */
  7623. #define multAcc_32x32_keep32(a, x, y) \
  7624. a += (q31_t) (((q63_t) x * y) >> 32)
  7625. /* SMMLS */
  7626. #define multSub_32x32_keep32(a, x, y) \
  7627. a -= (q31_t) (((q63_t) x * y) >> 32)
  7628. /* SMMUL */
  7629. #define mult_32x32_keep32(a, x, y) \
  7630. a = (q31_t) (((q63_t) x * y ) >> 32)
  7631. #if defined ( __CC_ARM )
  7632. /* Enter low optimization region - place directly above function definition */
  7633. #if defined( __ARM_ARCH_7EM__ )
  7634. #define LOW_OPTIMIZATION_ENTER \
  7635. _Pragma ("push") \
  7636. _Pragma ("O1")
  7637. #else
  7638. #define LOW_OPTIMIZATION_ENTER
  7639. #endif
  7640. /* Exit low optimization region - place directly after end of function definition */
  7641. #if defined ( __ARM_ARCH_7EM__ )
  7642. #define LOW_OPTIMIZATION_EXIT \
  7643. _Pragma ("pop")
  7644. #else
  7645. #define LOW_OPTIMIZATION_EXIT
  7646. #endif
  7647. /* Enter low optimization region - place directly above function definition */
  7648. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7649. /* Exit low optimization region - place directly after end of function definition */
  7650. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7651. #elif defined (__ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  7652. #define LOW_OPTIMIZATION_ENTER
  7653. #define LOW_OPTIMIZATION_EXIT
  7654. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7655. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7656. #elif defined ( __GNUC__ )
  7657. #define LOW_OPTIMIZATION_ENTER \
  7658. __attribute__(( optimize("-O1") ))
  7659. #define LOW_OPTIMIZATION_EXIT
  7660. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7661. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7662. #elif defined ( __ICCARM__ )
  7663. /* Enter low optimization region - place directly above function definition */
  7664. #if defined ( __ARM_ARCH_7EM__ )
  7665. #define LOW_OPTIMIZATION_ENTER \
  7666. _Pragma ("optimize=low")
  7667. #else
  7668. #define LOW_OPTIMIZATION_ENTER
  7669. #endif
  7670. /* Exit low optimization region - place directly after end of function definition */
  7671. #define LOW_OPTIMIZATION_EXIT
  7672. /* Enter low optimization region - place directly above function definition */
  7673. #if defined ( __ARM_ARCH_7EM__ )
  7674. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER \
  7675. _Pragma ("optimize=low")
  7676. #else
  7677. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7678. #endif
  7679. /* Exit low optimization region - place directly after end of function definition */
  7680. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7681. #elif defined ( __TI_ARM__ )
  7682. #define LOW_OPTIMIZATION_ENTER
  7683. #define LOW_OPTIMIZATION_EXIT
  7684. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7685. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7686. #elif defined ( __CSMC__ )
  7687. #define LOW_OPTIMIZATION_ENTER
  7688. #define LOW_OPTIMIZATION_EXIT
  7689. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7690. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7691. #elif defined ( __TASKING__ )
  7692. #define LOW_OPTIMIZATION_ENTER
  7693. #define LOW_OPTIMIZATION_EXIT
  7694. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7695. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7696. #elif defined ( _MSC_VER ) || defined(__GNUC_PYTHON__)
  7697. #define LOW_OPTIMIZATION_ENTER
  7698. #define LOW_OPTIMIZATION_EXIT
  7699. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7700. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7701. #endif
  7702. /* Compiler specific diagnostic adjustment */
  7703. #if defined ( __CC_ARM )
  7704. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  7705. #elif defined ( __GNUC__ )
  7706. #pragma GCC diagnostic pop
  7707. #elif defined ( __ICCARM__ )
  7708. #elif defined ( __TI_ARM__ )
  7709. #elif defined ( __CSMC__ )
  7710. #elif defined ( __TASKING__ )
  7711. #elif defined ( _MSC_VER )
  7712. #else
  7713. #error Unknown compiler
  7714. #endif
  7715. #ifdef __cplusplus
  7716. }
  7717. #endif
  7718. #endif /* _ARM_MATH_H */
  7719. /**
  7720. *
  7721. * End of file.
  7722. */