## 3 Hybrid Computing Architecture of MSD Algorithm
### Correlation Calculation Based on SC
#### 3.1.3 Adder with Flexible Scaling Factor  
Assuming that the adder has N inputs and a scaling factor of k, and taking into account the scaling and bias in the domain conversion, the calculation equation for the adder can be expressed as  
Figure 5: The circuit of the stochastic complex multiplier.  
\[P_{y} =\frac{\frac{X_{1}+X_{2}+\cdots+X_{N}}{k}+1}{2}\] \[=\frac{1}{k}\bigg{(}\frac{X_{1}+X_{2}+\cdots+X_{N}+k}{2}\bigg{)}\] \[=\frac{1}{k}\bigg{(}\frac{X_{1}+1}{2}+\frac{X_{2}+1}{2}+\cdots+ \frac{X_{N}+1}{2}-\frac{N-k}{2}\bigg{)}\] \[=\frac{1}{k}P_{x_{1}}+\frac{1}{k}P_{x_{2}}+\cdots+\frac{1}{k}P_{ x_{N}}-\frac{N-k}{2k} \tag{28}\] \[=\frac{1}{k}(P_{x_{1}}+P_{x_{2}}+\cdots+P_{x_{k}})+\frac{1}{k}(P_ {x_{k+1}}+P_{x_{k+2}}+\cdots+P_{x_{k}})+\cdots\] \[+\frac{1}{k}(P_{x_{Mk+1}}+P_{x_{Mk+2}}+\cdots+P_{x_{N}})-\frac{N- k}{2k}\] \[=P_{x_{0}}+P_{x_{1}}+\cdots+P_{x_{M}}-\frac{N-k}{2k}\]  
where \(P_{x_{i}}=\frac{1}{k}(P_{x_{k+1}}+\frac{1}{k}P_{x_{k+2}}+\cdots+\frac{1}{k}P_ {x_{k+k}})\), \(M=\lfloor\frac{N}{k}\rfloor\), and \(\lfloor\cdot\rfloor\) denotes the floor operation.  
In the stochastic adders, when the scaling factor k is excessively large, the output becomes too small, necessitating longer random sequences to ensure the computational accuracy. For adders with N inputs, a scaling factor of up to N can guarantee that the result will not overflow. Therefore, it suffices that the scaling factor k in the adder is less than N.  
As observed in Equation (28), during the stochastic addition computations, the probability value of the input data is first subjected to a scaling operation. Subsequently, as the scaled sequence is summed, a correction factor--which is dependent on both the scaling factor and the number of inputs--is subtracted from the cumulative sum.  
The truth table for the adder is shown in Table 2. To simplify the discussion, the scaling process has been omitted from the table. Within the table, \(P_{\frac{N-k}{2k}}\) is the random sequence with a probability value of \(\frac{N-k}{2k}\), \(state_{n}\) is the current state, \(P_{y}\) is the output of the adder, and \(state_{n+1}\) is the updated state after the output. The state register and \(P_{\frac{N-k}{2k}}\) are utilized to perform the required subtraction operation.  
Figure 6 illustrates the hardware architecture of the proposed adder. In the comprehensive adder circuit, the N input signals are initially partitioned into groups of k, and a k-input multiplexer is employed to scale these signals. In the case where the last group of inputs comprises fewer than k elements, zeros are appended to ensure the completeness of the set. After scaling the input data, a subtraction unit is used to subtract the correction factor \(P_{\frac{N-k}{2k}}\). Subsequently, the output of the adder is determined based on the subtraction result and the current state value. Finally, the state value is updated in accordance with the adder's output.  
Figure 6: The circuit of the stochastic adder.  
When \(k=N\), the entire adder circuit simplifies to a multiplexer. When \(k=1\), the adder circuit constitutes a full adder. If \(N-k>2k\), the correction factor is greater than 1. In such a case, the probabilistic value of the random sequence \(P_{\frac{N-k}{2k}}\) within the adder is modified from \(\frac{N-k}{2k}\) to \(\frac{N-3k}{2k}\), while an extra constant decrement of 1 is applied during the subtraction computation process. As the scaling factor is generally not too small during the summation of multiple data, this particular circuit adjustment is not graphically depicted in Figure 6.