arm_linear_interp_f16.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_linear_interp_f16.c
  4. * Description: Floating-point linear interpolation
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "dsp/interpolation_functions_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. /**
  31. @ingroup groupInterpolation
  32. */
  33. /**
  34. * @addtogroup LinearInterpolate
  35. * @{
  36. */
  37. /**
  38. * @brief Process function for the floating-point Linear Interpolation Function.
  39. * @param[in,out] S is an instance of the floating-point Linear Interpolation structure
  40. * @param[in] x input sample to process
  41. * @return y processed output sample.
  42. *
  43. */
  44. float16_t arm_linear_interp_f16(
  45. const arm_linear_interp_instance_f16 * S,
  46. float16_t x)
  47. {
  48. float16_t y;
  49. float16_t x0, x1; /* Nearest input values */
  50. float16_t y0, y1; /* Nearest output values */
  51. float16_t xSpacing = S->xSpacing; /* spacing between input values */
  52. int32_t i; /* Index variable */
  53. const float16_t *pYData = S->pYData; /* pointer to output table */
  54. /* Calculation of index */
  55. i = (int32_t) (((_Float16)x - (_Float16)S->x1) / (_Float16)xSpacing);
  56. if (((_Float16)x < (_Float16)S->x1))
  57. {
  58. /* Iniatilize output for below specified range as least output value of table */
  59. y = pYData[0];
  60. }
  61. else if ((uint32_t)i >= (S->nValues - 1))
  62. {
  63. /* Iniatilize output for above specified range as last output value of table */
  64. y = pYData[S->nValues - 1];
  65. }
  66. else
  67. {
  68. /* Calculation of nearest input values */
  69. x0 = (_Float16)S->x1 + (_Float16)i * (_Float16)xSpacing;
  70. x1 = (_Float16)S->x1 + (_Float16)(i + 1) * (_Float16)xSpacing;
  71. /* Read of nearest output values */
  72. y0 = pYData[i];
  73. y1 = pYData[i + 1];
  74. /* Calculation of output */
  75. y = (_Float16)y0 + ((_Float16)x - (_Float16)x0) *
  76. (((_Float16)y1 - (_Float16)y0) / ((_Float16)x1 - (_Float16)x0));
  77. }
  78. /* returns output value */
  79. return (y);
  80. }
  81. /**
  82. * @} end of LinearInterpolate group
  83. */
  84. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */