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