Microcomputer Protection System usually needs to carry on Square Root Operations, such as Newton iterative algorithm, traditional Taylor Expansion algorithm, etc. However, there is not enough high precision to calculate for traditional Square Root Operations. Address to this issue, Taylor Expansion and Piecewise Calculation Square Root algorithm is purposed. In this algorithm, square root algorithm of Taylor Expansion and piecewise calculation are used, and then by successive approximation method the error is reduced. At last, by piecewise calculation the radicand is lessening. Simulation shows that, compared error between uniform segment method and non-uniform segment method, Taylor Expansion and Piecewise Calculation Square Root algorithm has the characters such as high precision and low computation. The precision of this algorithm is high enough to the Microcomputer Protection System, in which there is not more than the error 1.5 10.
Embedded microcontroller application system usually needs to carry on Fourier transform to obtain the real and imaginary parts of the ac signal, thus to obtain the effective value, and at this time micro controller must carry on the Square Root operation. This is the prerequisite and basis for protecting logic and other algorithms, so the speed and precision of the square root operation directly affect the performance of the microcomputer protection [1].
Many researchers have spent more time in the square root operation. In [2], Digit-Recurrence Algorithms for Division and Square Root with Limited Precision Primitives is proposed, which is suitable for the low power and high radix implementation. This algorithm is based on the look-up table. The accuracy of the look-up table method is not enough. If we want high precision, we will need more limited memory. Moreover, the accuracy and speed of the look-up table method depends on the length of the table interval and the rationality of the table design. To improve the calculation accuracy, the length of the table should be increased, which makes it necessary to take up more memory [3, 4]. With the development of electronic technology, computer protection hardware has been greatly improved, but existing microcontrollers have very limited memory and CPU speed [8], which contradicts the application of computer protection algorithm. In [5], a radix-16 combined division and square root unit obtained by overlapping two radix-4 stages is proposed, which has fast iteration speed. Newton iterative method has high computational precision, however, the approximate degree of initial value and truth value directly determines the number of iterations and the precision of the calculation. The difficulty lies in the improper selection of initial value, which will increase the number of iterations and take long time [6, 7, 8]. However, the dynamic range of voltage and current in actual measurement is large, and the selection of approximate initial value is more difficult.The fixed initial value is usually selected, which results in a particularly slow convergence at some time. Therefore, there is a lack of an excellent square root algorithm for speed and precision. The traditional Taylor Expansion method requires further processing to meet the accuracy requirements [9, 10, 11, 12, 13]. The accuracy and speed of the Taylor expansion method depends on the length of the table interval and the rationality of the table design. In [14] a fused floating-point multiply/divide/square root unit based on Taylor-series expansion algorithm is proposed, which exhibits a reasonably good area-performance balance. This is a kind of existing Taylor Expansion, whose precision is not high enough. Therefore, high precision Taylor Expansion and Piecewise Calculation Square Root Algorithm of microcomputer protection, which open square algorithm of Taylor Expansion and piecewise calculation are used, and then by successive approximation method the error is reduced.
Taylor Expansion and error analysis
In this section, we will analyze the process of Taylor Expansion and its error. Taylor’s formula is a way of approximating a function with derivatives at . At first, we expand the Taylor series and then get the error expression. Then we analyze the relationship between error and derivatives (between error and ), we devise the method of reduce the error.
Assume , , so: , and then , therefore, the following form of the square operation is:
where 0 1.
The following method of square operation is based on the Eq. (1).
From Eq. (7), obviously, Eq. (3) Taylor’s expansion’s relative error is decided by and the number of Taylor Expansion items .
The number of terms vs. the error.
The error of Taylor’s expansion and
Obviously, the number of terms is more, the error is smaller as shown in Fig. 1 ( 1). We can know that the error is smaller as the bigger . When 5, the relative error decreases sharply with the increase of . when 5, the speed of error declines slowly. The more the number of expansion, the smaller the error, but the greater the amount of computation. Therefore, it is not good to improve the numbers of in the computational efficiency. When 5, the amount of calculation increases little, but the error decreases obviously, so the efficiency is higher; when 5, the amount of calculation increases more, but the error decreases less, and the efficiency is lower. For embedded devices, the amount of computation and the speed of computation are still important constraints. Therefore, the number of items should not exceed 5.
The error varies as
2
3
4
5
1
2.77E00
1.65E00
1.12E00
8.18E01
0.5
4.89E01
1.48E01
5.09E02
1.88E02
0.25
7.57E02
1.16E02
2.01E03
3.75E04
0.125
1.07E02
8.27E04
7.20E05
6.72E06
0.1
5.61E03
3.48E04
2.43E05
1.81E06
0.075
2.43E03
1.13E04
5.93E06
3.32E07
0.05
7.39E04
2.30E05
8.04E07
3.01E08
0.01
6.18E06
3.86E08
2.70E10
2.03E12
in the interval [0, 1].
segment in interval [0, 1].
The error of Taylor’s expansion and
The relative error is approximately proportional to . When 0 1, the the Eq. (7) is
From this expression, when is defined, the relative error is proportional to . With the decrease of , the error declines rapidly; otherwise, with the increase of , the error increases sharply. The relationship between Taylor Expansion relative error and is shown in Fig. 2. The specific values are shown in Table 1.
Therefore, can be reduced in a certain interval as shown in Fig. 3.
Assume that is in the th interval, in other word , then where, 0 , the value is depended on the segment, usually is smaller than 1.
When is evenly divided into the 8 sections, in th sector, maximum value , when the maximum value , as well as computation Taylor launches the square item biggest error as shown in Table 2 according to type Eq. (7).
Evenly divided into 8 segments
(%)
1
0.125
0.1250
0.0115
2
0.125
0.1111
0.0081
3
0.125
0.1000
0.0060
4
0.125
0.0909
0.0045
5
0.125
0.0833
0.0035
6
0.125
0.0769
0.0027
7
0.125
0.0714
0.0022
8
0.125
0.0667
0.0018
Divides equally 8 relative errors and changing conditions.
As seen in Table 2, the [0, 1] sector is divided into 8 segments evenly, the maximum value , the maximum error is 0.0115%.
The detailed error and the change of the when Taylor unfolds into the square is shown in Fig. 2. Obviously, the variation trend of relative error is very similar to that of ; the maximum relative error between each cell and the maximum value of are decreasing, the first inter-cell relative error and maximum are the largest among the individual cells. Because , therefore, when is evenly segmented, the segment of is not uniform, and the segments of decrease rapidly with the increase of , in the meanwhile, the maximum value of each cell decreases rapidly as increases, so that the relative error is rapidly reduced.
Figure 5, the -coordinate is , if the -coordinate changes to , the situation is similar. Similarly, if is evenly divided into segments, the result is similar to the case where is evenly segmented, this article no longer analyzes.
Divide nonuniformly into segments
From the above analysis, it can be seen that the uniform segmentation method is not ideal, because the maximum of each cell is not uniform, so that the relative error is not uniform, resulting in the largest error is relatively large.
In order to solve the problem of unevenness of each interval after segmentation, the segmentation method should make the maximum value of in each interval the same, and the maximum error between the individual cells is the same.
Assume that the interval is divided into segments, as shown in Fig. 6.
Establish to be in the cells, namely , then this sector’s maximum value is:
and,
Non-uniform divides into eight segments
(%)
1
0.0905
0.0905
0.0044
2
0.0987
0.0905
0.0044
3
0.1076
0.0905
0.0044
4
0.1174
0.0905
0.0044
5
0.1280
0.0905
0.0044
6
0.1396
0.0905
0.0044
7
0.1522
0.0905
0.0044
8
0.1660
0.0905
0.0044
Non-uniform segmentation schematic drawing.
Non-uniform divide into eight paragraphs unfold two items error.
Let the maximum value of each cell be equal, get the following equations:
Solve the above equations:
and . At the interval , is maximum value of, the maximum value , respectively is:
When is divided into the eight sections, in the th interval, maximum value , the maximum value , as well as computation Taylor launches the square item biggest error as shown in Table 3 according to type Eq. (7).
As seen in Table 3, the length of in each cell is increasing as the proportion of , The maximum value of in each cell is the same and the maximum error is the same.When you expand to a square item, the maximum error of each cell is 0.0044%. The detailed error when Taylor Expands 2 is shown in Fig. 7.
Improved algorithm.
Compared with the uniform segmentation method, the non-uniform segmentation method further reduces the maximum value of , and the maximum of each cell is equal, thus the maximum relative error decreased by 2.6 times.
Algorithm improvement
Note that in the above algorithm, the error is always positive or negative. This is because is a non-negative real number. If can be positive and negative symmetry, then will be reduced by half, so the error is greatly reduced.
As shown in Fig. 8, let be in the th interval, that is ,
Let: where, , .
Then:
Compared with the original , the range is 0 , after improvement , positive and negative symmetry, reduced by half.
Error comparison after improvement:
, brought into the above type, the result is:
Because , then
Therefore, after the algorithm improved, the error is reduced by at least times. This means that when Taylor is expanded to 2, the calculation accuracy is increased by 8 times; when 3, the calculation accuracy is improved by 16 times; when 5, the calculation accuracy is improved by 64 times. Therefore, this improvement improves the accuracy of the calculation.
Algorithm simulation
The above three algorithms are simulated by MATLAB. Taylor Expansion were expanded to 2 ( 2). In the simulation, the interval is divided into 8 segments, as shown in Fig. 9.
The [0, 1] Interval is divided into 8 segments.
Algorithm simulation result schematic drawing.
The simulation results are shown in Fig. 10. Algorithm 1 is uniform segmentation algorithm, which named Digit-Recurrence Algorithms for Division and Square Root with Limited Precision Primitives [2]. Algorithm 2 is a non-uniform segmentation algorithm, which named a radix-16 combined division and square root unit obtained by overlapping two radix-4 stages [5]. Algorithm 3 is an improved non-uniform segmentation algorithm expands 2 items comparison of three algorithms, which is our improved algorithm.
As can be seen from Fig. 10 and Table 4, the effect of non-uniform segment improvement algorithm is very ideal. Take 8 paragraphs as an example, when it is expanded to 5 times, the error does not exceed 1.5*10, this precision is sufficient for the general embedded device.
If it needs to further improve the accuracy of the calculation, it may increase the number of segments to further reduce the value. See Table 4, if is reduced to less than 0.01, the error can reach the level of 10. After increasing the number of segments, the amount of computation increases little, and only some judgments are added (which cell is the in).
Maximum relative error
Expansion number
Evenly divided
Non-uniformly divided
Non-uniform 8-segment
into 8 segments
into 8 segments
improved algorithm
2
1.07*10
4.20*10
5.33*10
3
8.26*10
2.36*10
1.45*10
4
7.19*10
1.49*10
4.40*10
5
6.71*10
1.01*10
1.43*10
The non-uniform segment ratio is higher than the uniformity of the segmentation accuracy
Non-uniform section improved accuracy is enhanced compared that before improvement
Expansion number
error before improvement/improved error
2
7.88
3
16.32
4
33.89
5
70.51
The effect of the improved algorithm is shown in Tables 5 and 6. As can be seen from the table, the more the number of Taylor Expansion items, the higher the accuracy of the algorithm to improve the multiple. Taking 5 as an example, the improved algorithm is 70 times higher than that before improvement, which is about 470 times higher than that of the uniform 8 segments algorithm. The effect is obvious. Compared with the reference [15] algorithm, the proposed algorithm can reduce the computational complexity in the case of better accuracy. In reference [16], the author compared the digit-recurrence approach for division and square root to the Newton-Raphson approach. The results of the comparison, in terms of energy consumption and power dissipation, indicate that units based on the digit-recurrence algorithm provide the lowest power solution. In this paper, based on above the Newton-Raphson approach, we prove that the best segment value is perfect for piecewise.
Conclusions
For a given function , a simple approximation function is used to perform function approximation, and there are many evaluation criteria. For the embedded device, is usually used, that is, maximum error within 0 rang. In this paper, the error characteristics of are approximated by the Taylor Expansion method, that is, the error increases sharply with the increase of . Therefore, in order to reduce the maximum error, the key to the algorithm is to minimize .
This paper reduces the by the method of segmentation. The uniform segmentation method will make the maximum value of the number of square meters of each cell uniform, so that the relative error is not uniform, resulting in a greater maximum error. The non-uniform segmentation method has been improved, and the equations are established according to the principle that the number of equations is equal. The value of each segment node is solved. The error of the non-uniform segmentation method is greatly improved, but the error is always positive or negative. Further improve the non-uniform segmentation method, making the error positive and negative symmetry, greatly improving the accuracy of the calculation. MATLAB simulation shows that, in the case of 8 segments, for example, when the power is expanded to 5 times, improved algorithm error is lower than 1.5*10. This precision is sufficient for the general embedded device. This paper analyzes in detail the error of the Taylor Expansion partial sum, segmentation method and its error. This part has some reference value for other algorithms using Taylor Expansion partial sum operation, it also has some reference value for other algorithms that use segmentation.
Footnotes
Acknowledgments
This work was supported in part by the following projects: the National Natural Science Foundation of China through the Grants 61571318, the Guangxi Nature Science Fund (2015GXNSFAA139298, 2016GXNSFAA380226), Guangxi Science and Technology Project (AC16380094, 1598008-29), Guangxi Nature Science Fund Key Project (2016GXNSFDA380031), and Guangxi University Science Research Project (ZD 2014146), supported in part by Open Foundation of Guangxi Experiment Center of Information Science LD15030X, Supported by Natural science fund of Guangxi 2015GXNSFAA139298.
References
1.
TangJ.DongJ. and ZhuQ.-C., Fast SQRT algorithm of microcomputer protection, Power System Protection and Control38(23) (2010), 1–5.
2.
ErcegovacM.D. and MullerJ.M., Digit-recurrence algorithms for division and square root with limited precision primitives, in: Conference on Signals, Systems and Computers, 2004.
3.
WangL.DongJ. et al., A high-precision square root algorithm for microcomputer protection, Power System Protection and Control39(19) (2011), 58–62.
4.
ShiY.-H.YiP. and ZhangC.-X., The realization of the rapid extraction algorithm on the microcontroller, Computer Technology and Development24(3) (2007), 30–34.
5.
NannarelliA., in: IEEE 2011 IEEE 20th Symposium on Computer Arithmetic (ARITH) – Radix-16 Combined Division and Square Root Unit, Tuebingen, Germany (2011.07.25–2011.07.27) 2011, pp. 169–176.
6.
JiangH.-W.LiangF. and LiuJ.G., The quick square root method of microprocessor, Electronic Science and Technology Nov 15, (2014), 35–36.
7.
WangS. and ZhangY.-Y., Analysis and Comparison of Microcomputer Protection Algorithms Technology Wind2013/14, pp. 34–35.
8.
ZhangJ.R., Review on the Simulation Algorithms of the Digital Relay ProtectionThe World of Inverters2016/11, pp. 89–9194.
9.
XueC.-X., Research on AC Sampling Algorithm for Relay Protection of Microcomputer Relay in Power System. Xi’an University of Electronic Science and Technology, 2012.3.
10.
ZhangX.-M. and LiY.-X., High precision and fast extraction algorithm based on the newton iteration method, Electric Power Automation Equipment (3) (2008).
11.
ChenL.-Y.LiangX.-D. and DingC.-B., Based on Look-up table method of fast floating-point Number Square Root Method, Microcomputer Information25(2–3) (2009), 205–206.
12.
ZhangL.-P. and YangF.-W., The iterative learning algorithm based on Taylor series, Control and Decision (4) (2005), 444–447.
13.
AbrateM.BarberoS.CerrutiU. and MurruN., Periodic representations and rational approximations of square roots, Journal of Approximation Theory175 (2013).
14.
ErcegovacM.D. and LangT., Division and Square Root: Digit Recurrence Algorithms and Implementations, Kluwer: Boston; 1994.
15.
KwonT.J. and DraperJ., Floating-point division and square root using a Taylor-series expansion algorithm, Microelectronics Journal40 (2009), 1601–1605.
16.
WalczykC.J.MorozL.V. and CieslinskiJ.L., Improving the accuracy of the fast inverse square root algorithm, arXiv:1802.06302 [cs.NA], 2018.