Sine and cosine approximation method based on data storage
By storing angle points and their sine or cosine values into the data table and using the difference table for linear approximation calculation, the problem of excessive storage space of the sine lookup table is solved, and the high-precision angle-to-sine value conversion is achieved, and the storage space requirement is reduced.
Patent Information
- Application Number
- CN202510139106.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-08
- Publication Date
- 2025-05-30
AI Technical Summary
In the prior art, the memory space required for the sine cosine lookup table is too large, making it difficult to achieve high-precision angle-to-sine conversion on a small chip.
By dividing the preset angle into multiple angle points, storing these angle points and their sine or cosine values into the first data table, and then sine difference or cosine difference between each two adjacent angle points into the second data table, the sine or cosine approximation of the angle to be found is obtained using the lookup table and linear approximation.
It realizes high-precision sine cosine calculation, and greatly reduces the storage space requirement, and is suitable for small chip applications.
Smart Images

Figure CN120066453A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of signal processing, and in particular, to a method for approximating sine and cosine based on data storage. Background Art
[0002] A resolver-to-digital converter (RDC) converts the analog output signal of a resolver into a digital angle signal to realize the digital conversion of the position / angle analog quantity, and is widely used in position angle measurement fields such as aerospace, numerical control machine tools, and industrial servo control. In the prior art, the conversion circuit mainly consists of an error processor, a phase-sensitive demodulator, a digital filter, an angular velocity integrator, an angle integrator, a sine-cosine lookup table, etc. to form a closed-loop tracking loop. When the input analog angle signal θ and the digital angle meet it can be considered that the digital angle at this time is equal to the analog angle θ, thereby realizing the conversion from the analog angle to the digital angle.
[0003] Among them, the sine-cosine lookup table is mainly used to convert the digital angle value generated by the tracking loop into digital sine and cosine values. The conventional design method of the sine-cosine lookup table generally stores the sine and cosine values of 1 / 4 of a cycle (90 degrees) according to the symmetry characteristics of sine and cosine, and then obtains the sine and cosine values in the range of 360 degrees of a cycle through quadrant judgment and sign processing. In this method, if the angle representation accuracy is 16 bits and the sine and cosine values are also 16-bit accuracy, then (65536 / 4)×16bit×2 = 64kB of ROM storage space is required. For some small chips, such a scale of ROM circuit is unacceptable. Summary of the Invention
[0004] Based on the above situation of the prior art, the purpose of the embodiments of the present invention is to provide a method for approximating sine and cosine based on data storage, which occupies a small amount of space for data storage and can achieve high calculation accuracy.
[0005] To achieve the above object, according to one aspect of the present invention, a method for approximating sine and cosine based on data storage is provided, including the steps of:
[0006] Dividing a preset angle into a first number of angle points, and storing the first number of angle points and their corresponding sine values or cosine values into a first data table; the preset angle is less than or equal to 90 degrees;
[0007] Storing the difference between the sine values or the difference between the cosine values between every two adjacent angle points among the first number of angle points into a second data table;
[0008] Determining a first lookup table address and a second lookup table address according to the angle to be searched;
[0009] Obtain the first data from the first data table according to the first table lookup address;
[0010] Obtain the second data from the second data table according to the second table lookup address;
[0011] Obtain the sine approximation or cosine approximation of the angle to be searched according to the first data and the second data;
[0012] Wherein, the first quantity is related to the approximation accuracy and the storage space of the data table.
[0013] Further, determining the first table lookup address and the second table lookup address according to the angle to be searched includes the steps of:
[0014] Convert the angle to be searched into first angle data, where the first angle data is the binary representation of the angle to be searched; determine the first table lookup address and the second table lookup address according to the address bits of the first angle data.
[0015] Further, obtaining the sine approximation or cosine approximation of the angle to be searched according to the first data and the second data includes the steps of:
[0016] Determine the transformation coefficient according to the coefficient bits of the first angle data and the first quantity;
[0017] Obtain the first sine approximation or the first cosine approximation of the angle to be searched according to the first data, the second data and the transformation coefficient;
[0018] The first sine approximation or the first cosine approximation is the sine approximation or the cosine approximation of the angle to be searched.
[0019] Further, the address bits are determined according to the first quantity, the coefficient bits are determined according to the number of bits, the sign bit and the address bits of the first angle data, and the sign bit of the first angle data is determined according to the preset angle.
[0020] Further, the sine approximation of the angle to be searched is calculated according to the following formula:
[0021] sinx = tab 2 (add 2 )·k + tab 1 (add 1 )
[0022] Wherein, x represents the angle to be searched, add 1 represents the first table lookup address, tab 1 (add 1) represents the first data obtained from the first data table according to the first table lookup address, add 2 represents the second table lookup address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second table lookup address, and k represents the transformation coefficient.
[0023] Further, the cosine approximation value of the angle to be searched is calculated according to the following formula:
[0024] cosx = tab 2 (add 2 )·k - tab 1 (add 1 )
[0025] where x represents the angle to be searched, add 1 represents the first table lookup address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first table lookup address, add 2 represents the second table lookup address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second table lookup address, and k represents the transformation coefficient.
[0026] Further, the method further includes the steps of:
[0027] Determine the angle transformation formula and transformation sign according to the sign bit of the first angle data;
[0028] Calculate the sine approximation value or cosine approximation value of the angle to be searched according to the first sine approximation value or first cosine approximation value of the angle to be searched, the angle transformation formula and the transformation sign.
[0029] Further, the sine approximation value of the angle to be searched is calculated according to the following formula:
[0030] sinx = sign[tab 2 (add 2 )·k + tab 1 (add 1 )]
[0031] where x represents the angle to be searched, add 1 represents the first table lookup address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first table lookup address, add 2 represents the second table lookup address, tab 2 (add2 ) represents the second data obtained from the second data table according to the second look-up table address, k represents the transformation coefficient, and sign[] represents the transformation according to the angle transformation formula and the transformation symbol.
[0032] Furthermore, the cosine approximation value of the angle to be searched is calculated according to the following formula:
[0033] cosx = sign[tab 2 (add 2 )·k - tab 1 (add 1 )]
[0034] where x represents the angle to be searched, add 1 represents the first look-up table address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first look-up table address, add 2 represents the second look-up table address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second look-up table address, k represents the transformation coefficient, and sign[] represents the transformation according to the angle transformation formula and the transformation symbol.
[0035] In summary, the embodiment of the present invention provides a sine and cosine approximation method based on data storage, including the steps of: dividing a preset angle into a first number of angle points, storing the first number of angle points and their corresponding sine values or cosine values in a first data table; storing the sine value difference or cosine value difference between every two adjacent angle points among the first number of angle points in a second data table; determining a first look-up table address and a second look-up table address according to the angle to be searched; obtaining first data from the first data table according to the first look-up table address; obtaining second data from the second data table according to the second look-up table address; and obtaining a sine approximation value or a cosine approximation value of the angle to be searched according to the first data and the second data. The technical solution provided by the embodiment of the present invention stores the sine values and sine value differences or cosine values and cosine value differences of each angle point in the first data table and the second data table respectively according to a specific strategy, and can obtain the estimated values of sine and cosine through look-up tables and corresponding linear approximation calculations. The calculation result has a small error, high calculation accuracy, and greatly reduces the demand for storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a flowchart of the sine and cosine approximation method based on data storage provided by the embodiment of the present invention;
[0037] Figure 2 is a schematic diagram of the principle of the linear approximation sine look-up table provided by the embodiment of the present invention;
[0038] Figure 3 It is a schematic diagram of the principle of the linear approximation cosine lookup table according to an embodiment of the present invention;
[0039] Figure 4 It is a schematic diagram of the circuit structure based on the sine-cosine approximation method provided by an embodiment of the present invention. Specific Embodiments
[0040] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings. It should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts of the present invention.
[0041] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in one or more embodiments of the present invention should have the ordinary meanings understood by those of ordinary skill in the art to which the present invention pertains. The "first", "second", and similar terms used in one or more embodiments of the present invention do not denote any order, quantity, or importance, but are only used to distinguish different components. The terms such as "including" or "comprising" mean that the elements or items appearing before this word cover the elements or items listed after this word and their equivalents, without excluding other elements or items. The terms such as "connected" or "coupled" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect.
[0042] The technical solutions of the present invention will be described in detail below with reference to the accompanying drawings. An embodiment of the present invention provides a sine-cosine approximation method based on data storage. Figure 1 The flowchart of the sine-cosine approximation method based on data storage is shown in Figure 1 As shown, the method includes the following steps:
[0043] S202. Divide a preset angle into a first number of angle points, and store the first number of angle points and their corresponding sine values or cosine values in a first data table. Wherein, the preset angle is less than or equal to 90 degrees, and the selection of the first number is related to the approximation accuracy and the storage space of the data table. For example, in an embodiment of the present invention, 90 degrees is divided into 128 angle points, and the degree represented by each angle point is: 90° / 128 = 0.703125°. If it is stored in a ROM, the storage space required to store the sine values or cosine values of 128 angle points is: 128×16bit×2 = 512B.
[0044] S204. Store the difference between the sine values or the difference between the cosine values between every two adjacent angular points among the first quantity of angular points into a second data table. In an embodiment of the present invention, the difference between the sine values or the difference between the cosine values between every two of the 128 angular points is stored. According to the curvature characteristics of the sine function, the difference between the angular points in the angular range of 0° - (90° / 128) is the largest, and this difference is: [sin(90 / 128)×32768] - 0 = 402. This difference requires 9 bits to store. Therefore, storing the sine value differences and the cosine value differences into the ROM requires a storage space of 128×9 bits×2 = 288B.
[0045] Figure 2 The schematic diagram of the principle of the linear approximation sine lookup table according to the embodiment of the present invention is shown. Figure 3 The schematic diagram of the principle of the linear approximation cosine lookup table according to the embodiment of the present invention is shown. As Figure 2 shown, the abscissa represents the position of the sine table corresponding to the angular value in the range of 0 - 90°, and the ordinate represents the sine value corresponding to the angular value in the range of 0 - 90°; as Figure 3 shown, the abscissa represents the position of the cosine table corresponding to the angular value in the range of 0 - 90°, and the ordinate represents the cosine value corresponding to the angular value in the range of 0 - 90°. Among them, both the sine value and the cosine value adopt 15 - bit precision. In order to reduce the storage capacity of the lookup table, the embodiment of the present invention designs the above - mentioned first data table and second data table in a segmented linear approximation manner.
[0046] Taking the angle of 10° as an example, the principle of using the sine first data table and the second data table to complete the approximate calculation of sin(10°) is described below, and its accuracy is calculated.
[0047] (1) Calculate the decimal expression value of 10° with 16 - bit precision as A = 65536×10° / 360° = 1820.
[0048] (2) For the angular value with 16 - bit precision, after dividing 90 degrees into 128 points, the interval between two phase points is (65536 / 4) / 128 = 128. Calculate the position of the sine table of 10° as A / 128 = 14 + 28 / 128, denoted as 14...28. Therefore, it can be known that sin(10°) is between the 14th and 15th positions in the sine first data table and the second data table. Since the angular difference between two phase points is very small, as Figure 2 shown, the linear approximation equation y = k·x + b can be used for calculation, where k = (tab(15) - tab(14)) / 128, x = 28, b = tab(14), and sin(10°) = tab(14)+(tab(15) - tab(14))×28 / 128 is obtained.
[0049] (3) The values of tab(14) and tab(15) are stored in the first sine data table, and the value of (tab(15) - tab(14)) is stored in the second sine data table. The calculation is as follows:
[0050] tab(14) = sin(14 × 0.703125°) = sin(9.84375°) = 5602;
[0051] tab(15) = sin(15 × 0.703125°) = sin(10.546875°) = 5998;
[0052] (tab(15) - tab(14)) = 396;
[0053] Therefore, sin(10°) = 5602 + 396 × 28 / 128 = 5689.
[0054] (4) The calculation error is abs(5689 / 32767 - sin(10°)) = 2.84e -5 , and the error can be accurate to 5 decimal places.
[0055] The following takes the angle 80° as an example to illustrate the process of using the first cosine data table and the second cosine data table to complete cos(80°) and calculate its accuracy.
[0056] (1) Calculate the 16-bit precision decimal representation value of 80° as A = 65536 × 80° / 360° = 14564.
[0057] (2) For the 16-bit precision angle value, after dividing 90 degrees into 128 points, the interval between two phase points is (65536 / 4) / 128 = 128. Calculate the cosine table position of 80° as A / 128 = 113 + 100 / 128, denoted as 113...100. Therefore, it can be known that cos(80°) is between 113 and 114 in the first cosine data table and the second cosine data table. Since the angle difference between two phase points is very small, as Figure 3 shown, the linear approximation equation y = k·x + b can be used for calculation, where k = (tab(114) - tab(113)) / 128, x = 100, b = tab(113), and cos(80°) = tab(113) + (tab(114) - tab(113)) × 100 / 128 is obtained.
[0058] (3) The values of tab(113) and tab(114) are stored in the first cosine data table, and the value of (tab(114) - tab(113)) is stored in the second cosine data table. The calculation is as follows:
[0059] tab(113) = cos(113 × 0.703125°) = cos(79.453125°) = 5998;
[0060] tab(114) = cos(114 × 0.703125° = cos(80.15625°) = 5602;
[0061] (tab(114) - tab(113)) = -396;
[0062] Therefore, cos(80°) = 5998 - 396 × 100 / 128 = 5689.
[0063] (4) The calculation error is abs(5689 / 32767 - cos(80°)) = 2.84e -5 , and the error can be accurate to 5 decimal places.
[0064] S206. Determine the first table lookup address and the second table lookup address according to the angle to be searched. The determination of the table lookup address can be based on the following steps:
[0065] S2061. Convert the angle to be searched into the first angle data, and the first angle data is the binary representation of the angle to be searched.
[0066] S2062. Determine the first table lookup address and the second table lookup address according to the address bits of the first angle data.
[0067] S208. Obtain the first data from the first data table according to the first table lookup address.
[0068] S210. Obtain the second data from the second data table according to the second table lookup address.
[0069] S212. Obtain the sine approximation or cosine approximation of the angle to be searched according to the first data and the second data. The obtaining of the sine approximation or cosine approximation according to the first data and the second data can be based on the following steps:
[0070] S2121. Determine the transformation coefficient according to the coefficient bits of the first angle data and the first quantity.
[0071] S2122. Obtain the first sine approximation or the first cosine approximation of the angle to be searched according to the first data, the second data and the transformation coefficient.
[0072] The first sine approximation or the first cosine approximation is the sine approximation or cosine approximation of the angle to be searched.
[0073] Among them, the address bits can be determined according to the first quantity, the coefficient bits can be determined according to the number of bits, sign bits, and address bits of the first angle data, and the sign bits of the first angle data can be determined according to a preset angle.
[0074] Table 1 lists the relationships among the precision, the divided first quantity, and the above-mentioned address bits, coefficient bits, and sign bits (where the number of bits is from high to low):
[0075] Table 1
[0076] Precision (unit: bit) Preset angle First quantity Number of bits (sign bit - address bit - coefficient bit) 16 90° 128 2-7-7 18 90° 128 2-7-9 16 90° 256 2-8-6
[0077] Among them, the sign bits of the first angle data can be determined according to a preset angle. For example, when the preset angle is 90°, since 360° / 90° = 4, 4 digits require 2 bits to represent, so as to distinguish different quadrants, and the highest 2 bits of the first angle data are the sign bits. The address bits of the first angle data can be determined according to the first quantity. For example, when the first quantity is 128, according to 128 = 2 7 , at this time the address bits are the middle 7 bits. The coefficient bits of the first angle data are determined by the number of bits, sign bits, and address bits of the first angle data. For example, in the case shown in the first row of Table 1, the coefficient bits are: 16 - 2 - 7 = 7, that is, the lowest 7 bits.
[0078] In the above steps, the sine approximation value of the angle to be searched can be calculated according to the following formula:
[0079] sinx = tab 2 (add 2 )·k + tab 1 (add 1 )
[0080] Among them, x represents the angle to be searched, add 1 represents the first look-up table address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first look-up table address, add 2 represents the second look-up table address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second look-up table address, and k represents the transformation coefficient.
[0081] In the above steps, the cosine approximation value of the angle to be searched can be calculated according to the following formula:
[0082] cosx = tab 2 (add 2 )·k - tab 1 (add 1 )
[0083] Among them, x represents the angle to be searched, add 1 represents the first look-up table address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first look-up table address, add 2 represents the second look-up table address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second look-up table address, and k represents the transformation coefficient.
[0084] According to some optional embodiments, the method further includes the following steps:
[0085] S214. Determine the angle transformation formula and transformation symbol according to the sign bit of the first angle data;
[0086] S216. Calculate the sine approximation value or cosine approximation value of the angle to be searched according to the first sine approximation value or the first cosine approximation value of the angle to be searched, the angle transformation formula and the transformation symbol.
[0087] In the above steps, the sine approximation value of the angle to be searched can be calculated according to the following formula:
[0088] sinx = sign[tab 2 (add 2 )·k + tab 1 (add 1 )]
[0089] Among them, x represents the angle to be searched, add 1 represents the first look-up table address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first look-up table address, add 2 represents the second look-up table address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second look-up table address, k represents the transformation coefficient, and sign[] represents the transformation according to the angle transformation formula and the transformation symbol.
[0090] In the above steps, the cosine approximation value of the angle to be searched can be calculated according to the following formula:
[0091] cosx = sign[tab 2 (add 2 )·k - tab 1 (add 1 )]
[0092] Where x represents the angle to be searched, add 1 represents the first look-up table address, tab 1 (add 1 ) represents the first data obtained from the first data table according to the first look-up table address, add 2 represents the second look-up table address, tab 2 (add 2 ) represents the second data obtained from the second data table according to the second look-up table address, k represents the transformation coefficient, and sign[] represents the transformation according to the angle transformation formula and the transformation symbol.
[0093] Figure 4 shows a schematic diagram of the circuit structure of the sine and cosine approximation method provided based on the embodiments of the present invention. Figure 4 The upper figure therein shows a schematic diagram of the circuit structure based on the sine approximation method, Figure 4 and the lower figure therein shows a schematic diagram of the circuit structure based on the cosine approximation method. The sine and cosine approximation methods provided in the above embodiments of the present invention include the sine approximation method and the cosine approximation method. The sine approximation method and the cosine approximation method can be used separately or simultaneously in the same system. The circuit based on the sine approximation method includes a sine angle transformation and sign decision module, a first sine ROM memory (such as Figure 4 SIN_ROM1 therein, for storing the first sine data table), a second sine ROM memory (such as Figure 4 SIN_ROM2 therein, for storing the second sine data table), a multiplier, a shift circuit, an adder, and a sign transformation circuit. The circuit based on the cosine approximation method includes a cosine angle transformation and sign decision module, a first cosine ROM memory (such as Figure 4 COS_ROM1 therein, for storing the first cosine data table), a second cosine ROM memory (such as Figure 4 COS_ROM2 therein, for storing the second cosine data table), a multiplier, a shift circuit, a subtractor, and a sign transformation circuit.
[0094] In the sine and cosine approximation method provided in the above embodiments, when the sine approximation method is adopted, the first look-up table address and the second look-up table address are determined according to the angle to be searched. For example, in the example, the preset angle is 90 degrees, the first quantity is 128, and 16-bit precision is adopted. When the angle to be searched is less than or equal to 90 degrees, the angle to be searched is respectively converted into a decimal representation A and a binary representation sin_deg[15:0], where the binary representation sin_deg[15:0] is used as the first angle data, and the first look-up table address and the second look-up table address are determined according to the address bits of the first angle data. In this example, the address bits are sin_deg[13:7]. The first sine data table stores the sine values of 128 angle points in the range of 0° - 90°, that is, tab 1(1), tab 1 (2)... tab 1 (128), look up the corresponding sine value based on the address bits sin_deg[13:7]. The second sine data table stores the sine difference between every two angle points among 128 angle points in the range of 0° - 90°, that is, tab 2 (1), tab 2 (2)... tab 2 (127), where tab 2 (1) = tab 1 (2) - tab 1 (1), tab 2 (2) = tab 1 (3) - tab 1 (2)……tab 2 (127) = tab 1 (128) - tab 1 (127), look up the corresponding sine difference based on the address bits sin_deg[13:7]. Determine the transformation coefficient according to the coefficient bits sin_deg[6:0] of the first angle data and the divided first quantity 128. According to the looked-up sine value (i.e., the first data), sine difference (i.e., the second data) and transformation coefficient, obtain the first sine approximation value of the angle to be looked up. The second data can be multiplied by the coefficient bits sin_deg[6:0] and the product is divided by 128 (for example, implemented by a shift circuit), and the result of the division is added to the first data to obtain the first sine approximation value. In this embodiment, the first sine approximation value is the sine approximation value of the angle to be looked up.
[0095] According to some optional embodiments, when the angle to be looked up is greater than 90 degrees (less than or equal to 360 degrees), angle transformation and sign determination are also required. The sine angle change and sign determination module can judge which quadrant the angle to be looked up belongs to based on sin_deg[15:14] and perform angle transformation and sign determination according to its quadrant. 00 indicates that the angle to be looked up belongs to the first quadrant 0° - 90°, the angle is denoted as A, and the sign is positive; 01 indicates that the angle to be looked up belongs to the second quadrant 90° - 180°, the angle is transformed into 32768 - A, and the sign is positive; 10 indicates that the angle to be looked up belongs to the third quadrant 180° - 270°, the angle is transformed into A - 32768, and the sign is negative; 11 indicates that the angle to be looked up belongs to the fourth quadrant 270° - 360°, the angle is transformed into 65536 - A, and the sign is negative. The calculation method of the angles after transformation in the second, third, and fourth quadrants is the same as that of the angles in the first quadrant. Table 2 shows the sine angle change and sign determination.
[0096] Table 2
[0097] sin_deg[15:14] Angle range Quadrant Angle transformation Sign 00 0°-90° First A Positive 01 90°-180° Second 32768-A Positive 10 180°-270° Third A-32768 Negative 11 270°-360° Fourth 65536-A Negative
[0098] When the angle value to be searched is greater than 90 degrees, the above first sine approximation value determines whether to perform a negative number transformation through the sign transformation circuit based on the sign in the sine angle transformation and sign decision module. If the sign is positive, the first sine approximation value does not need to be negatively transformed, and the sine value sin[15:0] of the angle to be searched is directly obtained; if the sign is negative, the first sine approximation value is negatively transformed (for example, through the sign transformation circuit) to obtain the sine value of the angle to be searched. Among them, the sign transformation circuit can be implemented by a binary complement conversion circuit.
[0099] The implementation steps of the cosine approximation method are basically the same as those of the above sine approximation method. The difference is that the signs in the second and fourth quadrants are different from those of the sine, so whether to use the sign transformation circuit for negative number transformation is different from that of the sine. In addition, because the cosine value decreases in the 0-90 degree interval and the cosine difference between two angle points is negative (for example, (tab(114)-tab(113))=-396), in terms of circuit implementation, a subtractor can be directly used to implement it, so that negative numbers do not need to be stored in the ROM. Of course, in terms of circuit implementation, an adder can also be used. In this way, the minus sign in the calculation formula of the cosine approximation values of the above two angles to be searched is changed to a plus sign, as shown in the following formula. Here, it can be selected according to actual needs.
[0100] cosx = tab 2 (add 2 )·k + tab 1 (add 1 )
[0101] cosx = sign[tab 2 (add 2 )·k + tab 1 (add 1 )]
[0102] Table 3 shows the cosine angle change and sign decision.
[0103] Table 3
[0104] cos_deg[15:14] Angle range Quadrant Angle transformation Sign 00 0°-90° First A Positive 01 90°-180° Second 32768-A Negative 10 180°-270° Third A-32768 Negative 11 270°-360° Fourth 65536-A Positive
[0105] The following uses a specific example to illustrate the sine and cosine approximation method based on data storage according to the embodiments of the present invention.
[0106] Example 1: The angle to be searched is 10°
[0107] The 16-bit precision decimal number and binary number for the angle to be searched at 10° are A = 1820 and sin_deg[15:0] = 0000 0111 0001 1100 respectively. The sine angle change and sign decision module is based on the decision result of sin_deg[15:14] being 00, indicating that the angle to be searched is in the first quadrant 0°-90°, and the angle does not need to be transformed, denoted as A, and the sign is positive. The address bits sin_deg[13:7] are 001110, whose decimal value is 14, and the coefficient bits sin_deg[6:0] are 0011100, whose decimal value is 28. Based on the address bits sin_deg[13:7], both the first look-up table address and the second look-up table address are determined to be 14. Looking up the corresponding sine value (i.e., the first data) tab(14) = 5602 in the first sine data table, and looking up the corresponding sine difference (i.e., the second data) (tab(15)-tab(14)) = 396 in the second sine data table. The sine approximation value of the angle to be searched is calculated according to the following formula:
[0108] sinx = tab 2 (add 2 )·k + tab 1 (add 1 )
[0109] Wherein, the first look-up table address add 1 is 14, the second look-up table address add 2 is 14, and k = 28 / 128. The output (tab(15)-tab(14)) of the second sine ROM memory can be multiplied by sin_deg[6:0], that is, 28, through the multiplier in Figure 4 to obtain the output (tab(15)-tab(14))×28. The output result is shifted 7 bits to the right by the shift circuit to implement the algorithm of dividing by 128. The output of the shift circuit (tab(15)-tab(14))×28 / 128 and the output tab(14) of the first sine ROM memory are added by the adder to get 5602 + 396×28 / 128 = 5689. Since the sign in the sine angle transformation and sign decision module is positive, the output result of the adder does not need to be transformed into a negative number, and the sine value of 10° is directly output as 5689.
[0110] Example 2. The angle to be searched is 170°
[0111] The 16 - bit decimal number and binary number for the angle to be searched, 170°, are A = 30948 and sin_deg[15:0]=0111 1000 1110 0100 respectively. The sine angle change and sign decision module, based on the sin_deg[15:14] decision result of 01, indicates that the angle to be searched is in the range of 90° - 180°. The angle value is transformed to 32768 - A = 1820, and the sign is positive. The angle transformation result 1820 is the same as the 16 - bit precision decimal number A = 1820 for 10°. Therefore, its calculation method is the same as that for the angle to be searched of 10°, and the output result of the adder is 5689. Since the sign in the sine angle transformation and sign decision module is positive, the output result of the adder does not need negative transformation and directly outputs the sine value of 170° as 5689.
[0112] Example 3: The angle to be searched is 190°
[0113] The 16 - bit decimal number and binary number for the angle to be searched, 190°, are A = 34588 and sin_deg[15:0]=1000 0111 0001 1100 respectively. The sine angle change and sign decision module, based on the sin_deg[15:14] decision result of 10, indicates that the angle is in the range of 180° - 270°. The angle value is transformed to A - 32768 = 1820, and the sign is negative. The angle transformation result 1820 is the same as the 16 - bit precision decimal number A = 1820 for 10°. Therefore, its calculation method is the same as that for the angle to be searched of 10°, and the output result of the adder is 5689. Since the sign in the sine angle transformation and sign decision module is negative, the output result of the adder undergoes negative transformation in the sign transformation circuit, and the sine value of 190° is obtained as - 5689.
[0114] Example 4: The angle to be searched is 350°
[0115] The 16 - bit decimal number and binary number for the angle to be searched, 350°, are A = 63716 and sin_deg[15:0]=1111 1000 1110 0100 respectively. The sine angle change and sign decision module, based on sin_deg[15:14] being 11, indicates that the angle is in the range of 270° - 360°. The angle value is transformed to 65536 - A = 1820, and the sign is negative. The angle transformation result 1820 is the same as the 16 - bit precision decimal number A = 1820 for 10°. Therefore, its calculation method is the same as that for the angle to be searched of 10°, and the output result of the adder is 5689. Since the sign in the sine angle transformation and sign decision module is negative, the output result of the adder undergoes negative transformation in the sign transformation circuit, and the sine value of 350° is obtained as - 5689.
[0116] The cosine approximation method for the angle to be searched is the same as the above sine method.
[0117] In summary, the embodiment of the present invention relates to a sine and cosine approximation method based on data storage, including the steps of: dividing a preset angle into a first number of angle points, and storing the first number of angle points and their corresponding sine values or cosine values in a first data table; storing the sine value difference or cosine value difference between every two adjacent angle points among the first number of angle points in a second data table; determining a first lookup table address and a second lookup table address according to the angle to be searched; obtaining a first data from the first data table according to the first lookup table address; obtaining a second data from the second data table according to the second lookup table address; and obtaining a sine approximation value or a cosine approximation value of the angle to be searched according to the first data and the second data. The technical solution provided by the embodiment of the present invention stores the sine values and sine value differences or cosine values and cosine value differences of each angle point in the first data table and the second data table respectively according to a specific strategy, and can obtain the estimated values of sine and cosine through table lookup and corresponding linear approximation calculations. The calculation result has a small error and a high calculation accuracy, and greatly reduces the demand for storage space.
[0118] It should be understood that any discussion of the above embodiments is only exemplary and is not intended to imply that the scope of the present invention (including the claims) is limited to these examples; under the idea of the present invention, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations in different aspects of one or more embodiments of the present invention as described above, which are not provided in detail for the sake of brevity. The above specific embodiments of the present invention are only used for exemplary illustration or explanation of the principle of the present invention, and do not constitute a limitation to the present invention. Therefore, any modification, equivalent replacement, improvement, etc. made without departing from the spirit and scope of the present invention shall be included in the protection scope of the present invention. In addition, the appended claims of the present invention are intended to cover all changes and modification examples falling within the scope and boundaries of the appended claims or equivalent forms of such scope and boundaries.
Claims
1. A sine-cosine approximation method based on data storage, characterized in that: Includes steps: Divide the preset angle into a first number of angle points, and store the first number of angle points and their corresponding sine values or cosine values in a first data table; the preset angle is less than or equal to 90 degrees; storing the sine value difference or cosine value difference between every two adjacent angle points in the first number of angle points in a second data table; Determine a first table lookup address and a second table lookup address according to the angle to be searched; Acquire first data from a first data table according to the first table lookup address; Acquire second data from a second data table according to the second table lookup address; Obtaining a sine approximation or a cosine approximation of the angle to be found according to the first data and the second data; The first number is related to the approximate accuracy and the storage space of the data table.
2. The method according to claim 1, characterized in that Determining a first table lookup address and a second table lookup address according to the angle to be searched includes the steps of: The angle to be searched is converted into first angle data, where the first angle data is a binary representation of the angle to be searched; and the first table lookup address and the second table lookup address are determined according to the address bits of the first angle data.
3. The method according to claim 2, characterized in that Obtaining a sine approximation or a cosine approximation of the angle to be found according to the first data and the second data, comprising the steps of: determining a transform coefficient based on coefficient bits of the first angle data and the first quantity; Obtaining a first sine approximation or a first cosine approximation of the angle to be found according to the first data, the second data and the transformation coefficient; The first sine approximation or the first cosine approximation is the sine approximation or the cosine approximation of the angle to be found.
4. The method according to claim 3, characterized in that The address bit is determined according to the first number, the coefficient bit is determined according to the bit number, the sign bit and the address bit of the first angle data, and the sign bit of the first angle data is determined according to the preset angle.
5. The method according to claim 4, characterized in that The sine approximation of the angle to be found is calculated according to the following formula: sinx=tab2(add2)·k+tab1(add1) Among them, x represents the angle to be searched, add1 represents the first table lookup address, tab1(add1) represents the first data obtained from the first data table according to the first table lookup address, add2 represents the second table lookup address, tab2(add2) represents the second data obtained from the second data table according to the second table lookup address, and k represents the transformation coefficient.
6. The method according to claim 4, characterized in that The cosine approximation of the angle to be found is calculated according to the following formula: cosx = tab2(add2)·k-tab1(add1) Among them, x represents the angle to be searched, add1 represents the first table lookup address, tab1(add1) represents the first data obtained from the first data table according to the first table lookup address, add2 represents the second table lookup address, tab2(add2) represents the second data obtained from the second data table according to the second table lookup address, and k represents the transformation coefficient.
7. The method according to claim 5 or 6, characterized in that: The method further comprises the steps of: Determine an angle transformation formula and a transformation sign according to the sign bit of the first angle data; The sine approximation or cosine approximation of the angle to be found is calculated based on the first sine approximation or the first cosine approximation of the angle to be found, the angle transformation formula and the transformation sign.
8. The method according to claim 7, characterized in that The sine approximation of the angle to be found is calculated according to the following formula: sinx=sign[tab2(add2)·k+tab1(add1)] Among them, x represents the angle to be searched, add1 represents the first table lookup address, tab1(add1) represents the first data obtained from the first data table according to the first table lookup address, add2 represents the second table lookup address, tab2(add2) represents the second data obtained from the second data table according to the second table lookup address, k represents the transformation coefficient, and sign[] represents the transformation according to the angle transformation formula and the transformation sign.
9. The method according to claim 7, characterized in that: The cosine approximation of the angle to be found is calculated according to the following formula: cosx=sign[tab2(add2)·k-tab1(add1)] Among them, x represents the angle to be searched, add1 represents the first table lookup address, tab1(add1) represents the first data obtained from the first data table according to the first table lookup address, add2 represents the second table lookup address, tab2(add2) represents the second data obtained from the second data table according to the second table lookup address, k represents the transformation coefficient, and sign[] represents the transformation according to the angle transformation formula and the transformation sign.
Citation Information
Cited By
Twisted factor storage method and reading method for FFT (Fast Fourier Transform) operation and hardware accelerator
CN122111347A