interpolation_functions.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /******************************************************************************
  2. * @file interpolation_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef _INTERPOLATION_FUNCTIONS_H_
  26. #define _INTERPOLATION_FUNCTIONS_H_
  27. #include "arm_math_types.h"
  28. #include "arm_math_memory.h"
  29. #include "dsp/none.h"
  30. #include "dsp/utils.h"
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. /**
  36. * @defgroup groupInterpolation Interpolation Functions
  37. * These functions perform 1- and 2-dimensional interpolation of data.
  38. * Linear interpolation is used for 1-dimensional data and
  39. * bilinear interpolation is used for 2-dimensional data.
  40. */
  41. /**
  42. * @brief Instance structure for the floating-point Linear Interpolate function.
  43. */
  44. typedef struct
  45. {
  46. uint32_t nValues; /**< nValues */
  47. float32_t x1; /**< x1 */
  48. float32_t xSpacing; /**< xSpacing */
  49. const float32_t *pYData; /**< pointer to the table of Y values */
  50. } arm_linear_interp_instance_f32;
  51. /**
  52. * @brief Instance structure for the floating-point bilinear interpolation function.
  53. */
  54. typedef struct
  55. {
  56. uint16_t numRows; /**< number of rows in the data table. */
  57. uint16_t numCols; /**< number of columns in the data table. */
  58. const float32_t *pData; /**< points to the data table. */
  59. } arm_bilinear_interp_instance_f32;
  60. /**
  61. * @brief Instance structure for the Q31 bilinear interpolation function.
  62. */
  63. typedef struct
  64. {
  65. uint16_t numRows; /**< number of rows in the data table. */
  66. uint16_t numCols; /**< number of columns in the data table. */
  67. const q31_t *pData; /**< points to the data table. */
  68. } arm_bilinear_interp_instance_q31;
  69. /**
  70. * @brief Instance structure for the Q15 bilinear interpolation function.
  71. */
  72. typedef struct
  73. {
  74. uint16_t numRows; /**< number of rows in the data table. */
  75. uint16_t numCols; /**< number of columns in the data table. */
  76. const q15_t *pData; /**< points to the data table. */
  77. } arm_bilinear_interp_instance_q15;
  78. /**
  79. * @brief Instance structure for the Q15 bilinear interpolation function.
  80. */
  81. typedef struct
  82. {
  83. uint16_t numRows; /**< number of rows in the data table. */
  84. uint16_t numCols; /**< number of columns in the data table. */
  85. const q7_t *pData; /**< points to the data table. */
  86. } arm_bilinear_interp_instance_q7;
  87. /**
  88. * @brief Struct for specifying cubic spline type
  89. */
  90. typedef enum
  91. {
  92. ARM_SPLINE_NATURAL = 0, /**< Natural spline */
  93. ARM_SPLINE_PARABOLIC_RUNOUT = 1 /**< Parabolic runout spline */
  94. } arm_spline_type;
  95. /**
  96. * @brief Instance structure for the floating-point cubic spline interpolation.
  97. */
  98. typedef struct
  99. {
  100. arm_spline_type type; /**< Type (boundary conditions) */
  101. const float32_t * x; /**< x values */
  102. const float32_t * y; /**< y values */
  103. uint32_t n_x; /**< Number of known data points */
  104. float32_t * coeffs; /**< Coefficients buffer (b,c, and d) */
  105. } arm_spline_instance_f32;
  106. /**
  107. * @brief Processing function for the floating-point cubic spline interpolation.
  108. * @param[in] S points to an instance of the floating-point spline structure.
  109. * @param[in] xq points to the x values ot the interpolated data points.
  110. * @param[out] pDst points to the block of output data.
  111. * @param[in] blockSize number of samples of output data.
  112. */
  113. void arm_spline_f32(
  114. arm_spline_instance_f32 * S,
  115. const float32_t * xq,
  116. float32_t * pDst,
  117. uint32_t blockSize);
  118. /**
  119. * @brief Initialization function for the floating-point cubic spline interpolation.
  120. * @param[in,out] S points to an instance of the floating-point spline structure.
  121. * @param[in] type type of cubic spline interpolation (boundary conditions)
  122. * @param[in] x points to the x values of the known data points.
  123. * @param[in] y points to the y values of the known data points.
  124. * @param[in] n number of known data points.
  125. * @param[in] coeffs coefficients array for b, c, and d
  126. * @param[in] tempBuffer buffer array for internal computations
  127. */
  128. void arm_spline_init_f32(
  129. arm_spline_instance_f32 * S,
  130. arm_spline_type type,
  131. const float32_t * x,
  132. const float32_t * y,
  133. uint32_t n,
  134. float32_t * coeffs,
  135. float32_t * tempBuffer);
  136. /**
  137. * @brief Process function for the floating-point Linear Interpolation Function.
  138. * @param[in,out] S is an instance of the floating-point Linear Interpolation structure
  139. * @param[in] x input sample to process
  140. * @return y processed output sample.
  141. *
  142. */
  143. float32_t arm_linear_interp_f32(
  144. const arm_linear_interp_instance_f32 * S,
  145. float32_t x);
  146. /**
  147. *
  148. * @brief Process function for the Q31 Linear Interpolation Function.
  149. * @param[in] pYData pointer to Q31 Linear Interpolation table
  150. * @param[in] x input sample to process
  151. * @param[in] nValues number of table values
  152. * @return y processed output sample.
  153. *
  154. * \par
  155. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  156. * This function can support maximum of table size 2^12.
  157. *
  158. */
  159. q31_t arm_linear_interp_q31(
  160. const q31_t * pYData,
  161. q31_t x,
  162. uint32_t nValues);
  163. /**
  164. *
  165. * @brief Process function for the Q15 Linear Interpolation Function.
  166. * @param[in] pYData pointer to Q15 Linear Interpolation table
  167. * @param[in] x input sample to process
  168. * @param[in] nValues number of table values
  169. * @return y processed output sample.
  170. *
  171. * \par
  172. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  173. * This function can support maximum of table size 2^12.
  174. *
  175. */
  176. q15_t arm_linear_interp_q15(
  177. const q15_t * pYData,
  178. q31_t x,
  179. uint32_t nValues);
  180. /**
  181. *
  182. * @brief Process function for the Q7 Linear Interpolation Function.
  183. * @param[in] pYData pointer to Q7 Linear Interpolation table
  184. * @param[in] x input sample to process
  185. * @param[in] nValues number of table values
  186. * @return y processed output sample.
  187. *
  188. * \par
  189. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  190. * This function can support maximum of table size 2^12.
  191. */
  192. q7_t arm_linear_interp_q7(
  193. const q7_t * pYData,
  194. q31_t x,
  195. uint32_t nValues);
  196. /**
  197. * @brief Floating-point bilinear interpolation.
  198. * @param[in,out] S points to an instance of the interpolation structure.
  199. * @param[in] X interpolation coordinate.
  200. * @param[in] Y interpolation coordinate.
  201. * @return out interpolated value.
  202. */
  203. float32_t arm_bilinear_interp_f32(
  204. const arm_bilinear_interp_instance_f32 * S,
  205. float32_t X,
  206. float32_t Y);
  207. /**
  208. * @brief Q31 bilinear interpolation.
  209. * @param[in,out] S points to an instance of the interpolation structure.
  210. * @param[in] X interpolation coordinate in 12.20 format.
  211. * @param[in] Y interpolation coordinate in 12.20 format.
  212. * @return out interpolated value.
  213. */
  214. q31_t arm_bilinear_interp_q31(
  215. arm_bilinear_interp_instance_q31 * S,
  216. q31_t X,
  217. q31_t Y);
  218. /**
  219. * @brief Q15 bilinear interpolation.
  220. * @param[in,out] S points to an instance of the interpolation structure.
  221. * @param[in] X interpolation coordinate in 12.20 format.
  222. * @param[in] Y interpolation coordinate in 12.20 format.
  223. * @return out interpolated value.
  224. */
  225. q15_t arm_bilinear_interp_q15(
  226. arm_bilinear_interp_instance_q15 * S,
  227. q31_t X,
  228. q31_t Y);
  229. /**
  230. * @brief Q7 bilinear interpolation.
  231. * @param[in,out] S points to an instance of the interpolation structure.
  232. * @param[in] X interpolation coordinate in 12.20 format.
  233. * @param[in] Y interpolation coordinate in 12.20 format.
  234. * @return out interpolated value.
  235. */
  236. q7_t arm_bilinear_interp_q7(
  237. arm_bilinear_interp_instance_q7 * S,
  238. q31_t X,
  239. q31_t Y);
  240. #ifdef __cplusplus
  241. }
  242. #endif
  243. #endif /* ifndef _INTERPOLATION_FUNCTIONS_H_ */