An improved method for implementing parabolic nonlinear functions
By using the parabolic interpolation method based on the class lookup table in the embedded system, the parabolic interpolation coefficient of the nonlinear function is calculated, and the error problem of linear interpolation method when the function curve changes large or bends is solved, achieving higher accuracy and better The effect of low storage resource occupancy.
Patent Information
- Application Number
- CN202411180389.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-08-27
AI Technical Summary
In the prior art, the linear interpolation method of nonlinear functions cannot accurately capture changes when the function curve changes largely or bends, resulting in large interpolation errors and occupies a lot of storage resources, especially in embedded systems with limited resources. In case.
The parabolic interpolation method based on the class lookup table is used. By selecting n sampling points in the input interval, dividing them evenly into n-1 intervals, the parabolic interpolation quadratic polynomial coefficients for every three adjacent sampling points are calculated for estimation. Function approximation of input values, reducing storage requirements and interpolation errors.
The accuracy of the nonlinear function results is improved, the interpolation error is reduced, the result is smoother, and the storage space is consumed, half of the storage resources are occupied, and the number of times the memory address is read is reduced.
Smart Images

Figure CN118708868B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of digital circuits, and in particular relates to an improved method for realizing a parabola-like nonlinear function. Background Art
[0002] Nonlinear functions play an important role in many scientific and engineering fields, such as power amplifier models in communication systems and grayscale transformation in image processing. However, directly calculating nonlinear functions often requires a lot of computing resources, especially in embedded systems, where resource constraints become a major challenge. In order to improve computing efficiency and reduce hardware costs, using a lookup table (LUT) to approximate nonlinear functions is an effective means.
[0003] Ideally, LUT needs to pre-calculate and store the output values corresponding to all possible input values, but this will take up a lot of storage space. In order to reduce storage requirements, LUT usually does not store all possible input values, but stores the values of a series of sampling points and estimates the values of other points through interpolation methods when querying.
[0004] In the prior art, the function values of two adjacent sampling points of the input value on the left and right of the x-axis are usually queried, and these two function values and the slope calculated by the input value are used to perform linear interpolation to estimate the function value of the input value.
[0005] However, when the function curve changes greatly or is very curved within a certain interval, linear interpolation may not be able to accurately capture this change, resulting in a large interpolation error. At the same time, the interpolation result is piecewise linear, which means that there will be sudden changes in direction between data points, which may cause the result to look not smooth enough.
[0006] In addition, in the prior art, the RAM depth used to store sampling point function values is equal to the number of sampling points. In order to ensure the accuracy of the linear interpolation result, the number of sampling points is generally large, which will occupy more storage resources. Summary of the invention
[0007] The object of the present invention is to provide an improved method for realizing a parabola-like nonlinear function, so as to improve the interpolation method of the parabola-like nonlinear function result accuracy in the implementation hardware.
[0008] In order to solve the above technical problems, the present invention provides an improved method for realizing a parabola-like nonlinear function. In the implementation hardware, the approximate value of the parabola-like nonlinear function is calculated by a method based on a quasi-lookup table and a parabolic interpolation method; the method comprises the following steps:
[0009] Step 1: Select n sampling points in the input interval of the parabolic nonlinear function to be implemented, and the n sampling points evenly divide the entire interval range into n-1 intervals with equal step lengths; the length of the interval step length is equal to the length of the input interval divided by (n-1);
[0010] Step 2: Starting from the first sampling point, every three adjacent sampling points and their function values are put into the equation system consisting of three parabolic interpolation quadratic polynomials to calculate the parabolic interpolation coefficients corresponding to the search interval segment composed of the sampling points;
[0011] Step 3: Determine which search interval the input value falls into, and obtain the calculated interpolation coefficient within the range. Substitute the input value and the parabolic interpolation coefficient into the parabolic interpolation quadratic polynomial to calculate the function approximation of the input value.
[0012] Preferably, in the step 1, the parabola-like nonlinear function is a power function, an exponential function or other more complex nonlinear function of a parabola-like curve;
[0013] The input interval of the parabolic nonlinear function can be configured in the implementation hardware;
[0014] The number of sampling points is fixed in the implementation hardware.
[0015] Preferably, in step 2, the first sampling point is the minimum value of the input interval, and the last sampling point is the maximum value of the input interval; the values of the sampling points are not stored in the memory of the implementation hardware;
[0016] The first search interval segment composed of the three adjacent sampling points is composed of the first sampling point to the third sampling point, the second search interval segment is composed of the third sampling point to the fifth sampling point, and so on; the length of each search interval segment is two interval steps, and each search interval segment corresponds to three parabolic interpolation coefficients;
[0017] The function value and parabolic interpolation coefficient of the sampling point are not calculated in the implementation hardware, but are calculated in advance; the function value of the sampling point is not stored in the memory of the implementation hardware, and the parabolic interpolation coefficient needs to be stored in the memory of the implementation hardware. The parabolic interpolation coefficient corresponding to the first search interval is stored in memory address 0, and so on.
[0018] Preferably, in step three, it is determined which search interval the input value falls into, and this process is performed through multiple judgment logics in the implementation hardware.
[0019] Preferably, the judgment logic includes:
[0020] The input value is judged sequentially from the first search interval segment until it is hit; then the three parabolic interpolation coefficients in the memory address corresponding to the hit search interval segment are output;
[0021] If the input value is exactly a sampling point shared by two search intervals, the parabolic interpolation coefficients corresponding to the two search intervals are output and the two parabolic interpolation approximations are calculated. The final output result value can be configured in the implementation hardware.
[0022] If the input value is less than the minimum value of the configured input interval, the three parabolic interpolation coefficients corresponding to the first search interval consisting of sampling points are output;
[0023] If the input value is greater than the maximum value of the configured input interval, the three parabolic interpolation coefficients corresponding to the last search interval segment consisting of sampling points are output.
[0024] Preferably, the parabolic interpolation quadratic polynomial is: ; where x is the input value, a 0 , a 1 , a 2 It is the parabolic interpolation coefficient calculated by the system of equations consisting of parabolic interpolation quadratic polynomials.
[0025] Preferably, the system of equations is as follows:
[0026] ;
[0027] ;
[0028] ;
[0029] in x 0 , x 1 , x 2 are three adjacent sampling points.
[0030] Preferably, the three parabolic interpolation coefficients calculated by the equation group need to be stored in a memory of the implementation hardware, and the memory uses a RAM with a depth of negative half of the number of sampling points and a width of the sum of the bit widths of the three parabolic interpolation coefficients.
[0031] Preferably, the write logic of the RAM is:
[0032] The three parabolic interpolation coefficients corresponding to the first search interval are stored in RAM address 0, the three parabolic interpolation coefficients corresponding to the second search interval are stored in RAM address 1, and so on;
[0033] The read logic of the RAM is:
[0034] If the input value belongs to the first search interval after the judgment logic, the data in RAM address 0 is read out. If the input value belongs to the second search interval after the judgment logic, the data in RAM address 1 is read out, and so on.
[0035] Preferably, the function approximation is obtained by a parabolic interpolation operation module, which includes:
[0036] Three multipliers for calculating ;
[0037] Two adders for calculating .
[0038] Compared with the prior art, the present invention has the following beneficial effects:
[0039] 1. The results calculated by the existing LUT and linear interpolation technology are based on straight lines and may have large errors. The present invention fits the original parabolic function curve by a quadratic parabolic interpolation polynomial, which can reduce the interpolation error and make the result smoother.
[0040] 2. In the existing LUT-based and linear interpolation technology, if the input overflows (greater than the maximum value of the input interval) or underflows (less than the minimum value of the input interval), if linear interpolation is continued to be used, it may cause a larger error, and an additional specific calculation method is required to approximate the actual function value; for the input underflow situation, the present invention uses the interpolation coefficients corresponding to the first group of sampling intervals for interpolation; for the input overflow situation, the interpolation coefficients corresponding to the last group of sampling intervals are used for interpolation; neither overflow situation changes the final interpolation method.
[0041] 3. The existing LUT and linear interpolation-based technology needs to read out data of two memory addresses for one table lookup, while the present invention only needs to read out data of one address.
[0042] 4. The existing LUT-based and linear interpolation-based technologies require a memory depth approximately equal to the number of sampling points. The memory depth required by the present invention is half of that of the existing technologies, thus occupying a smaller storage space.
[0043] 5. The existing technology based on LUT and linear interpolation needs to calculate the input value as a memory address, and needs to be divided by the interval step during the calculation process. In order to convert the division into a shift, the interval step needs to be set to a power of 2; the interval step of the present invention does not have this limitation, and does not need to calculate the input value as a memory address, but instead obtains the memory address through judgment logic. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1It is a schematic diagram of the process of the present invention.
[0045] Figure 2 The present invention is a flowchart showing a specific implementation of the present invention.
[0046] Figure 3 This is a hardware structure diagram of a specific implementation of the present invention. DETAILED DESCRIPTION
[0047] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become more apparent from the following description. It should be noted that the accompanying drawings are in very simplified form and in non-precise proportions, and are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention.
[0048] like Figures 1 to 3 As shown, the embodiment of the present invention provides an improved method for realizing a parabola-like nonlinear function, comprising the following steps:
[0049] Now the power function This nonlinear function is implemented and explained, and it is confirmed that the input data interval is [2, 20], the sampling points are (2, 5, 8, 11, 14, 17, 20) for a total of 7, and the interval step size is 3.
[0050] Every three of the seven sampling points are selected to form a search interval, and three search intervals are obtained in total. The first one is [2, 8], the second one is [8, 14], and the third one is [14, 20].
[0051] Substitute the three sets of data (2, 5, 8), (8, 11, 14), and (14, 17, 20) that constitute the three search intervals into the following three sets of parabolic interpolation equations to calculate three sets of parabolic interpolation coefficients:
[0052]
[0053]
[0054]
[0055] Calculate a 0 =-6.2222; a 1 =-17.7778; a 2 =12.4444;
[0056] Equation 2:
[0057]
[0058]
[0059]
[0060] Calculate a 0 =1233;a 1 =-351; a 2 =36;
[0061] Equation set 3:
[0062]
[0063]
[0064]
[0065] Calculate a 0 =35001;a 1 =-4527;a 2 =162;
[0066] The three groups of parabolic interpolation coefficients calculated by the above three equations are concatenated into one data, and each group of three coefficients is stored in the implementation hardware memory RAM address 0-3 respectively.
[0067] The input value is 9, which is input into the implementation hardware. After logical judgment, it belongs to the interval [8, 14]. The corresponding parabolic interpolation coefficient a is found. 0 =1233;a 1 =-351; a 2 =36.
[0068] will enter the value 9 and a 0 , a 1 , a 2 The three parabolic interpolation coefficients are parsed and input into the hardware parabolic interpolation operation module which contains three multipliers and two adders to perform Calculated The parabolic interpolation approximation is 990.
[0069] For comparison, the input data 9 is linearly interpolated in the interval [8, 11].
[0070] Calculate using linear interpolation formula ≈ +( - ) (9-8) / (11-8)=1062.
[0071] For functions , x =9, the actual result is 1000.
[0072] For the input value 9, the error of the parabolic interpolation result is 1%; the error of the linear difference is 6.2%; parabolic interpolation reduces the error range by nearly 6 times.
[0073] Moreover, for the input data interval [2, 20] and the sampling points (2, 5, 8, 11, 14, 17, 20), the present invention stores the parabolic interpolation coefficients and occupies a memory depth of 3; the existing technology based on LUT and linear interpolation needs to store 7 sampling points. Value, the memory depth is 7.
[0074] Similarly, the following power function and exponential function Take as an example, select a certain input interval, number of sampling points and input value, and describe the process of parabolic interpolation and linear interpolation of two example functions in detail below:
[0075] For the power function , perform parabolic interpolation:
[0076] Select the input interval [1, 5] and 5 sampling points [1, 2, 3, 4, 5], then the search intervals are [1, 3] and [3, 5]. Select the input value as 2.5, the corresponding search interval is [1, 3]. Substitute it into the following equation group to calculate the parabolic interpolation coefficient a 0 , a 1 , a 2 :
[0077]
[0078]
[0079]
[0080] Calculate a 0 =36, a 1 =-60, a 2 =25, then f The parabolic interpolation result of (2.5) is 36+(-60) 2.5+25 2.5 2 =42.25; perform linear interpolation in the interval [2, 3]: f (2.5)≈ f (2)+( f (3)- f (2) (2.5-2) / (3-2)=48.5.
[0081] Select the input interval [2, 8] and 7 sampling points [2, 3, 4, 5, 6, 7, 8], then the search interval is [2, 4], [4, 6], [6, 8]. The input value is 4.5, and the corresponding search interval is [4, 6]. Substitute it into the parabolic interpolation equation group to calculate a 0 =1800,a 1 =-990, a 2 =151, then f The parabolic interpolation result of (4.5) is 1800+(-990) 4.5+151 4.5 2 =402.75; perform linear interpolation between the interval [4, 5]: f (4.5)≈ f (4)+( f (5)- f (4) (4.5-4) / (5-4)=440.5.
[0082] Select the input interval [3, 11] and 9 sampling points [3, 4, 5, 6, 7, 8, 9, 10, 11], then the search interval is [3, 5], [5, 7], [7, 9], [9, 11]. The input value is 6.5, and the corresponding search interval is [5, 7]. Substitute it into the parabolic interpolation equation group to calculate a 0 =3780,a 1 =-1716, a 2 =217, then f The parabolic interpolation result of (6.5) is 3780+(-1716) 6.5+217 2 =1794.25; perform linear interpolation in the interval [6, 7]: f (6.5)≈ f (6)+( f (7)- f (6) (6.5-6) / (7-6)=1848.5.
[0083] For exponential function , perform parabolic interpolation:
[0084] Select the input interval [1, 5] and 5 sampling points [1, 2, 3, 4, 5], then the search intervals are [1, 3] and [3, 5]. Select the input value as 2.5, the corresponding search interval is [1, 3]. Substitute it into the parabolic interpolation equation group to calculate a 0 =1.0001, a 1 =1.0001, a 2=0.7181, then f The parabolic interpolation result of (2.5) is 1.0001+1.0001 2.5+0.7181 2.5 2 =7.9885; perform linear interpolation between the interval [2, 3]: f (2.5)≈ f (3)+( f (3)- f (2) (2.5-2) / (3-2)=440.5.
[0085] Select [2, 8] and 7 sampling points [2, 3, 4, 5, 6, 7, 8], then the search interval is [2, 4], [4, 6], [6, 8]. The input value is 4.5, and the corresponding search interval is [4, 6]. Substitute it into the parabolic interpolation equation group to calculate a 0 =1291.4096, a 1 =-631.6193, a 2 =80.6042, then f The parabolic interpolation result of (4.5) is 1291.4096+(-631.6193) 4.5+80.6042 4.5 2 =81.3578; Linear interpolation is performed between the interval [4,5]: f (4.5)≈ f (4)+( f (5)- f (4) (4.5-4) / (5-4)=101.5089.
[0086] Select the input interval [3, 11] and 9 sampling points [3, 4, 5, 6, 7, 8, 9, 10, 11], then the search interval is [3, 5], [5, 7], [7, 9], [9, 11]. The input value is 6.5, and the corresponding search interval is [5, 7]. Substitute it into the parabolic interpolation equation group to calculate a 0 =5446.4726, a 1 =-2155.1424, a 2 =219.1063, then f The parabolic interpolation result of (6.5) is 5446.4726+(-2155.1424) 6.5+219.1063 6.5 2 =695.2882; perform linear interpolation in the interval [6, 7]: f(6.5)≈ f (6)+( f (7)- f (6) (6.5-6) / (7-6)=750.0647.
[0087] The following table 1 is a power function and exponential function Comparison of linear interpolation errors and parabolic interpolation errors in different input intervals and input values:
[0088] Table 1
[0089]
[0090] It can be found from Table 1 that, compared with the existing LUT and linear interpolation-based technology, the function approximation achieved by the present invention has higher accuracy, and the error range is reduced by 2 to 6 times compared with the existing linear interpolation technology. That is, the present invention fits the original parabolic function curve through a quadratic parabola interpolation polynomial, which can reduce the interpolation error and make the result smoother than linear interpolation, and the hardware implementation occupies less storage space.
[0091] The above description is only a description of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any changes or modifications made by a person skilled in the art in the field of the present invention based on the above disclosure shall fall within the scope of protection of the claims.
Claims
1. An improved method for realizing a parabola-like nonlinear function, characterized in that: In the implementation hardware, the approximate value of the parabola-like nonlinear function is calculated by a lookup table-like method and a parabolic interpolation method; the steps include: Step 1: Select n sampling points in the input interval of the parabolic nonlinear function to be implemented, and the n sampling points evenly divide the entire interval into n-1 intervals with equal step lengths; Step 2: Starting from the first sampling point, every three adjacent sampling points and their function values are put into the equation system consisting of three parabolic interpolation quadratic polynomials to calculate the parabolic interpolation coefficients corresponding to the search interval segment composed of the sampling points; Step 3: Determine which search interval the input value falls into, that is, obtain the calculated interpolation coefficient within the range, and substitute the input value and the parabolic interpolation coefficient into the parabolic interpolation quadratic polynomial to calculate the function approximation of the input value; In the step 2, the first sampling point is the minimum value of the input interval, and the last sampling point is the maximum value of the input interval; the values of the sampling points are not stored in the memory of the implementation hardware; The first search interval segment composed of the three adjacent sampling points is composed of the first sampling point to the third sampling point, the second search interval segment is composed of the third sampling point to the fifth sampling point, and so on; the length of each search interval segment is two interval steps, and each search interval segment corresponds to three parabolic interpolation coefficients; The function value and the parabolic interpolation coefficient of the sampling point are not calculated in the implementation hardware, but are calculated in advance; the function value of the sampling point is not stored in the memory of the implementation hardware, and the parabolic interpolation coefficient needs to be stored in the memory of the implementation hardware, and the parabolic interpolation coefficient corresponding to the first search interval is stored in the memory address 0, and so on; In the step 3, it is determined which search interval the input value falls into. This process is determined by multiple determination logics in the implementation hardware. The judgment logic includes: The input value is judged sequentially from the first search interval segment until it is hit; then the three parabolic interpolation coefficients in the memory address corresponding to the hit search interval segment are output; If the input value is exactly a sampling point shared by two search intervals, the parabolic interpolation coefficients corresponding to the two search intervals are output and the two parabolic interpolation approximations are calculated. The final output result value can be configured in the implementation hardware. If the input value is less than the minimum value of the configured input interval, the three parabolic interpolation coefficients corresponding to the first search interval consisting of sampling points are output; If the input value is greater than the maximum value of the configured input interval, the three parabolic interpolation coefficients corresponding to the last search interval segment consisting of sampling points are output.
2. The improved method for realizing a parabola-like nonlinear function according to claim 1, characterized in that: In the step 1, the parabola-like nonlinear function is a power function, an exponential function or other nonlinear function of a parabola-like curve; The input interval of the parabolic nonlinear function can be configured in the implementation hardware; The number of sampling points is fixed in the implementation hardware.
3. The improved method for realizing a parabola-like nonlinear function according to claim 1, characterized in that: The parabolic interpolation quadratic polynomial is: ; where x is the input value, a0, a1, a2 are the parabolic interpolation coefficients calculated by the equation system consisting of parabolic interpolation quadratic polynomials.
4. The improved method for realizing a parabola-like nonlinear function as claimed in claim 3, characterized in that: The system of equations is as follows: ; ; ; in x 0, x 1, x 2 represents three adjacent sampling points.
5. The improved method for realizing a parabola-like nonlinear function as claimed in claim 4, characterized in that: The three parabolic interpolation coefficients calculated by the equation group need to be stored in the memory of the implementation hardware. The memory uses a RAM with a depth of negative half of the number of sampling points and a width of the sum of the bit widths of the three parabolic interpolation coefficients.
6. The improved method for realizing a parabola-like nonlinear function as claimed in claim 5, characterized in that: The write logic of the RAM is: The three parabolic interpolation coefficients corresponding to the first search interval are stored in RAM address 0, the three parabolic interpolation coefficients corresponding to the second search interval are stored in RAM address 1, and so on; The read logic of the RAM is: If the input value belongs to the first search interval after the judgment logic, the data in RAM address 0 is read out. If the input value belongs to the second search interval after the judgment logic, the data in RAM address 1 is read out, and so on.
7. The improved method for realizing a parabola-like nonlinear function as claimed in claim 4, characterized in that: The function approximation is obtained by a parabolic interpolation operation module, which includes: Three multipliers for calculating ; Two adders for calculating .
