# Demystifying DFT-Based Harmonic Phase Estimation, Transformation, and Synthesis
## 2 Robust DFT-Based Phase Estimation of Individual Sinusoids
### ODFT and the Sine and Shifted Hanning Windows  
When we compute the N-point ODFT (Equation (18)) of the sinusoid (5) and take for \(w[n]\) the sine window (Equation (12)), a relevant local maximum exists in the magnitude spectrum \(|X[k_{\ell}]|\) at \(k=k_{\ell}\) whose spectral coefficient can be approximated by the following:  
\[X[k_{\ell}]\approx\frac{A}{4}e^{i\big{(}\phi_{\ell}-\frac{\pi}{2}+\pi\big{(} \Delta_{\ell}-\frac{1}{2}\big{)}\big{(}1-\frac{1}{N}\big{)}\big{)}}R(\Delta_{ \ell})\, \tag{22}\]  
where we have the following:  
\[R(\Delta_{\ell})=\frac{\sin\pi\Delta_{\ell}}{\sin\frac{\pi}{2}\Delta_{\ell}}+ \frac{\sin\pi(\Delta_{\ell}-1)}{\sin\frac{\pi}{2}(\Delta_{\ell}-1)}. \tag{23}\]  
Figure 8: Cumulative phase estimation error as a function of the fractional frequency \(\Delta_{\ell}\), when the ODFT and the rectangular window are used. In the illustrated cases, \(N=128\), \(\ell=13\), SNR = 30 dB (**left**) and SNR = 10 dB (**right**).  
In the case of the shifted Hanning window, the local maximum in the magnitude spectrum can be approximated by the following:  
\[X[k_{\ell}]\approx\frac{A}{4}e^{j\left(\phi_{\ell}-\frac{\pi}{2}+\pi\left(\Delta _{\ell}-\frac{1}{2}\right)\left(1-\frac{1}{N}\right)\right)}S(\Delta_{\ell})\, \tag{24}\]  
where we have the following:  
\[S(\Delta_{\ell})=2\frac{\sin\pi\left(\Delta_{\ell}-\frac{1}{2}\right)}{\sin \frac{\pi}{N}\left(\Delta_{\ell}-\frac{1}{2}\right)}+\frac{\sin\pi\left(\Delta _{\ell}+\frac{1}{2}\right)}{\sin\frac{\pi}{N}\left(\Delta_{\ell}+\frac{1}{2} \right)}+\frac{\sin\pi\left(\Delta_{\ell}-\frac{3}{2}\right)}{\sin\frac{\pi}{N }\left(\Delta_{\ell}-\frac{3}{2}\right)}. \tag{25}\]  
Given that both (23) and (25) are always positive when \(\Delta_{\ell}\in[0.0,1.0[\), they do not affect phase in this range of \(\Delta_{\ell}\).  
Equations (22) and (24) show that the phase of the ODFT spectral line corresponding to the local maximum in the magnitude spectrum is the same as that already found for the ODFT and rectangular window combination. As noted previously, this is expected given that all three windows share the same linear-phase property and the same group delay. As a consequence, the phase can be estimated using Equation (21) although it remains true that the quality of the phase estimation depends on the specific near-end and far-end leakage characteristics of each window.  
Taking the sine window as an example, Figure 9 shows the cumulative phase estimation error arising from phase estimation according to (21) and taking into consideration the processing conditions in this section.  
When the results in Figure 9 are compared to the results in Figure 7, our results here are slightly better despite the fact that both relate to the same window. As pointed out in the previous section, this is due to the fact that the ODFT promotes a wider separation between Dirichlet kernels, which means that leakage effects become weaker. Results for the shifted Hanning window do not differ significantly.  
Matlab code is available (estimatePHASE_ODFT_sine.m), which generates results and displays Figure 9.