# Design and Implementation of a System-on-Chip for Self-Calibration of an Angular Position Sensor
## 3 Calibration Method Design
### Theoretical Analysis and Implementation Details of the LMSED Module  
The LMSED uses an adaptive algorithm to extract signal amplitude information, which is commonly used in the signal analysis [22; 23; 24]. This method is simple, does not require complicated mathematical operations, and is easy to implement in digital circuits. The designed LMSED module processes signals with the following expressions:  
\[ \begin{array}{l}d(k)=s(k)+n(k),\\ s(k)=a_{1}\cdot\sin(\omega_{c}k)+b_{1}\cdot\cos(\omega_{c}k)+c_{1}.\end{array}  \tag{13}\]  
where \(n(k)\) indicates signal noise, \(\omega_{c}\) is the signal frequency, and \(k\) represents the sampling time. The coefficient vector is used to represent the signal's DC components, sine and cosine components, and it is iteratively solved during the demodulation process using Equation (14):  
\[ \begin{array}{l}W=(W_{1},W_{2},W_{3})^{T},\\ W_{1}=a_{1},W_{2}=b_{1},W_{3}=c_{1}.\end{array}  \tag{14}\]  
The vector representation of the reference signals is  
\[r(k)=(\sin(\omega_{c}k),\cos(\omega_{c}k),1)^{T}. \tag{15}\]  
The reference sine and cosine signals are generated by a signal generator based on a Cordic algorithm [25], with a bit width of 32 and a pipeline depth of 28, achieving 24-bit precision. The driving frequency of the Cordic calculation module is also 32 times the main clock. The first clock cycle is used to latch the operands, the 28 clock cycles are used to complete the pipeline calculation, the 30 th clock cycle is used for quadrant judgment and symbol correction, and the 31 st clock cycle is used to obtain the exact signal. In order to reduce the number of drive clocks in the entire system, the clock is used 32 times and data latching continues in the 32 nd clock cycle. The working principle of the LMSED scheme is shown in Figure 5. The component in the prediction matrix \(W\) is the parameter to be identified in Equation (7). The reference signal \(r(k)\) and prediction matrix are used to calculate the inner product and obtain the estimated value of the input signal. The estimated value is compared with the input signal to obtain the error between the estimated and true values. The prediction matrix is adjusted iteratively to minimize the expected value of the squared error. In the algorithm implementation process, there are two types of error models:  
\[ \begin{array}{l}\eta(k)=s(k)-W^{T}\cdot r(k),\\ err(k)=d(k)-W^{T}\cdot r(k),\end{array}  \tag{16}\]  
The identification process adjusts parameter values by iteration. The optimization function of the iterative process is \(\min\{E\big{[}\eta^{2}(k)\big{|}W\big{]}\}\) while only the \(err(k)\) can be calculated in the demodulation process. For theoretical analysis, if the noise data follow a normal distribution with a mean of 0 and a variance of \(\sigma^{2}\), Equation (17) is established:  
\[E\Big{[}err^{2}(k)\big{|}W\Big{]}=E\Big{[}(\eta(k)+n(k))^{2}\Big{|}W\Big{]}=E \Big{[}\eta^{2}(k)\big{|}W\Big{]}+\sigma^{2}. \tag{17}\]  
Based on Equation (17), the optimization function can also be set to  
\[\min\{E\Big{[}err^{2}(k)\big{|}W\Big{]}\}. \tag{18}\]  
With the optimization function mentioned above, the parameter adjustment rule of the iterative process is performed based on the gradient descent method [26]. To simplify the number of calculations in the iterative process, the squared error is used as the optimization function to replace the expected value of the error. The gradient formula is as follows:  
\[\frac{\partial err^{2}(k)}{\partial W}=2\cdot err(k)\cdot\frac{\partial err( k)}{\partial W}=-2\cdot err(k)\cdot r(k). \tag{19}\]  
Based on Equation (19), the update formula of the parameters is  
\[W(k+1)=W(k)+2\cdot err(k)\cdot\mu\cdot r(k). \tag{20}\]  
where \(\mu\) is the step factor used to adjust the parameters' update speed. As the iteration progresses, the parameters gradually converge to the true value. In the implementation process, the operations and operations involved are implemented by combinatorial logic.