# FPGA-Based Methodology for Detecting Positional Accuracy Degradation in Industrial Robots
## 2 Materials and Methods
### Positional Accuracy Degradation FPGA Implementation
#### 2.6.2 Statistics Soft-Core FPGA Module  
The Statistics soft-core module calculates a discrete input signal's RMS and variance features. The module comprises a single structure, and different indicators can be calculated by changing the data path. Figure 12a shows the general diagram of the architecture of the statistics module. It comprises three blocks: a first-input first-output memory storage block, the Datapath block where the index calculation is carried out, and an FSM block that conducts the operation of the process.  
Figure 11: Architecture diagram of the DWT soft-core.  
In the initial process, when the STR signal is activated in the FSM, the choice of the statistical indicator to be calculated is made with the OPC signal. At the end of the calculation, the RDY flag is activated. The input data to the module (Din) is stored in memory in the FIFO block to enter the Datapath block later, and the Do1 and Do2 outputs obtain the calculation of the index.  
The process carried out within the datapath block is shown in a general way in Figure 12b; it consists of four sections: subtraction, powers, accumulation, and adjustment. A subtraction is performed between the sample \(x_{i}\), or the absolute value of the sample \(|x_{i}|\), and the mean of the input signal \(\bar{x}\). Subsequently, in the powers section, the result obtained in the subtraction is raised to different powers, as the case may be, from the first to the fourth power. The accumulated value of the previous operation is stored in the accumulator and divided by the number of samples N. Finally, the result is saturated to adjust the required bit size and is output by \(y_{1}\); if it is necessary to apply the square root, the output is made by \(y_{2}\).  
Figure 13a shows the module Datapath configured to calculate the variance for an input signal \(x\); the connection is highlighted in red, and the operation's progress is observed in the different sections of the module.  
Figure 12: Architecture Statistics soft-core. (**a**) General core diagram. (**b**) Datapath module.  
Figure 13: Statistical features modules. (**a**) Variance module operation path. (**b**) RMS module operation path.  
First, the difference between the sample and the mean of the signal is calculated; second, it is squared in the powers section, the accumulation is divided by the number of samples, and after saturation, the indicator completed by the output \(y_{1}\) is obtained. To calculate the RMS index, the process is presented in Figure 13b, wherein the subtraction section of the IPcore of the sample \(x_{i}\) is subtracted with a zero, which does not modify the value of the sample, then it is squared. In the powers section, the accumulated value is divided by the number of samples; at saturation output, the square root is calculated, and the result is delivered by \(y_{2}\). When the indicators of the approximation and detail frequency bands of levels three and four have been calculated (eight indicators), they are moved to the neural network-based classifier module.