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 29 #include "dsp/interpolation_functions_f16.h" 30 31 #if defined(ARM_FLOAT16_SUPPORTED) 32 33 34 /** 35 @ingroup groupInterpolation 36 */ 37 38 39 /** 40 * @addtogroup LinearInterpolate 41 * @{ 42 */ 43 44 /** 45 * @brief Process function for the floating-point Linear Interpolation Function. 46 * @param[in,out] S is an instance of the floating-point Linear Interpolation structure 47 * @param[in] x input sample to process 48 * @return y processed output sample. 49 * 50 */ arm_linear_interp_f16(const arm_linear_interp_instance_f16 * S,float16_t x)51 float16_t arm_linear_interp_f16( 52 const arm_linear_interp_instance_f16 * S, 53 float16_t x) 54 { 55 float16_t y; 56 float16_t x0, x1; /* Nearest input values */ 57 float16_t y0, y1; /* Nearest output values */ 58 float16_t xSpacing = S->xSpacing; /* spacing between input values */ 59 int32_t i; /* Index variable */ 60 const float16_t *pYData = S->pYData; /* pointer to output table */ 61 62 /* Calculation of index */ 63 i = (int32_t) (((_Float16)x - (_Float16)S->x1) / (_Float16)xSpacing); 64 65 if (((_Float16)x < (_Float16)S->x1)) 66 { 67 /* Iniatilize output for below specified range as least output value of table */ 68 y = pYData[0]; 69 } 70 else if ((uint32_t)i >= (S->nValues - 1)) 71 { 72 /* Iniatilize output for above specified range as last output value of table */ 73 y = pYData[S->nValues - 1]; 74 } 75 else 76 { 77 /* Calculation of nearest input values */ 78 x0 = (_Float16)S->x1 + (_Float16)i * (_Float16)xSpacing; 79 x1 = (_Float16)S->x1 + (_Float16)(i + 1) * (_Float16)xSpacing; 80 81 /* Read of nearest output values */ 82 y0 = pYData[i]; 83 y1 = pYData[i + 1]; 84 85 /* Calculation of output */ 86 y = (_Float16)y0 + ((_Float16)x - (_Float16)x0) * 87 (((_Float16)y1 - (_Float16)y0) / ((_Float16)x1 - (_Float16)x0)); 88 89 } 90 91 /* returns output value */ 92 return (y); 93 } 94 95 /** 96 * @} end of LinearInterpolate group 97 */ 98 99 100 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */ 101 102