# Simplified Welch Algorithm for Spectrum Monitoring
## 3 Modified Welch Algorithm  
### Proposed Algorithm  
As presented before, the Welch samples are an estimation of the power spectral density based on the arithmetic average of multiple FFT [20] scans. The modified version replaces the running average by weighted averaging to simplify and allow for real-time calculation. To better explain this concept, let us consider the moving average over an input data stream by a window with the size of \(N_{p}\). The result can be expressed by the following Equation (9):  
\[y_{i}=\frac{1}{N_{p}}\sum_{m=0}^{N_{p}-1}x_{i-m} \tag{9}\]  
where \(y_{i}\) is the moving average at sample time \(i\) and \(x_{i}\) is the input data stream. The Welch algorithm uses averaging (or arithmetic averaging) in order to achieve two important goals:  
* SNR improvement: averaging over more samples can reduce the noise power level and enhance the SNR of desired signal. * Precise estimation: by utilizing FFT samples from the past, each frequency component can be estimated with more precision. However, arithmetic averages of past samples have the following consequences [21]:
* Implementing arithmetic averaging of \(N\) order, requires \(N\) RAM components and massively increases the complexity for real time implementation. * All the previous samples are weighted by the same coefficient. For example, the sample with distance of 10 time intervals from the current sample is weighted by the same gain as the sample with the distance of 100 time intervals. However, in many systems, it is suitable to weight the samples based on their distance from current samples. Weighted averaging is widely used in the digital signal processing domain, especially in image processing for noise reduction and signal enhancement [22; 23]. In the image processing area, weighted averaging helps greatly with the noise reduction while preserving the fast variations in image edge. In such filtering scenarios, pixels in filtering windows are weighted based on their distance from the central pixel. This paper tries to replace the arithmetic averaging by the weighted averaging to target two important points:  
* Weighting each FFT packet based on its distance from the current packet, this idea helps to preserve the fast variable frequency component in spectrum. * A recursive and simple algorithm can replace the required memories for the arithmetic averaging. It means that the system should weight samples based on their distance from the current time instance:  
\[y^{\prime}_{i}=\frac{1}{G}\sum_{m=0}^{N_{p}-1}\alpha_{m}x_{i-m}\ \,\ \alpha_{0}> \alpha_{1}>\alpha_{2}\ldots>\alpha_{N_{p}-1} \tag{10}\]  
where \(G=\sum_{m=0}^{N_{p}-1}a_{m}\) is normalization gain, \(y^{\prime}_{i}\) is calculated weighted average in \(i\)th interval, and \(\left\{a_{0},\alpha_{1},\alpha_{2}\ldots\alpha_{N_{p}-1}\right\}\) are utilized weighting coefficients. The dependency degree for each input sample is determined by selected weighting coefficient \(\alpha_{m}\). Now, the dependency of \(y^{\prime}_{i}\) is extended to the past by replacing all the independent weights by exponential weights. \[y^{\prime}_{i}=\frac{1}{G}\sum_{m=0}^{N_{p}-1}\alpha^{m}x_{i-m}\ \,\ 0<\alpha<1\ and\ G=\sum_{m=0}^{N_{p}-1}a^{m} \tag{11}\]  
To make the averaging simple and recursive, we first extend the dependency to all previous input samples:  
\[y^{\prime\prime}_{i}=\where \(G=\sum\limits_{m=0}^{\infty}\alpha^{m}\) and \(x_{i}=0\) for \(i<0\) and \(y_{i}^{\prime\prime}\) is the weighted averaging of all the past input samples. Now, a recursive algorithm can be extracted:  
\[ \begin{array}{c}y_{0}^{\prime\prime}=\ x_{0}\\ y_{i}^{\prime\prime}=\ x_{1}+\alpha x_{0}=\ x_{1}+\ ay_{0}^{\prime\prime}\\ y_{2}^{\prime\prime}=\ x_{2}+\alpha x_{1}+\alpha^{2}x_{0}=\ x_{2}+\ ay_{1}^{ \prime\prime}\\ y_{3}^{\prime\prime}=\ x_{3}+\alpha x_{2}+\alpha^{2}x_{1}+\alpha^{3}x_{0}=\ x_{3}+\ ay_{2}^{\prime\prime}\\ \Rightarrow y_{i}^{\prime\prime}=a\times y_{i-1}^{\prime\prime}+x_{i}\ \ \,\ 0< \alpha<1\end{array}