interpolation_functions.h 9.1 KB

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