Probability distribution of windowed cross-correlation This question is in the context of time-delay estimation. Say I have a stationary Gaussian stochastic process $g$, and I know its autocorrelation function $R_g(\tau)$. To do time-delay estimation, I'm computing a windowed cross correlation between $g$ and a delayed version of it. In other words,
$$
g_1 = g(x-D) \\
\phi(\tau) = \int_{-T/2}^{T/2} g(x) g_1(x + \tau)
$$
and I'm going to determine the delay by finding the maximum of $\phi$. 
My question is, is it possible to get an expression for the probability distribution of $\phi$? 
 A: If $g_1$ and $g$ are discretized vector representations of analog signals that are each normalized, $\phi$ is the normalized cross correlation function. Then the density function for $\phi$, at fixed time $\tau$, is a transform of the noncentral Beta distribution. You can compute this density function from the relative error in approximating the vectorized representation of $g$ with $g_{1}$. 
In what follows, I'll change your notation: I am going to call the digital form of $g$ vector $\mathbf{x}$ and the digital form of $g_{1}$ vector $\mathbf{w}$. I will also assume $\mathbf{w}$ is a reference, or template signal with effectively infinite SNR. I will assume $g$ is noisy. Unless $g$ is entirely noise, it will include a signal $\mathbf{u}$ immersed in noise $\mathbf{n}$. In general, $\mathbf{u}$ is partially correlated with $\mathbf{w}$, and is not necessarily an "amplitude scaled copy of $\mathbf{w}$" (e.g., the matched filtering hypothesis is somewhat erroneous). Call the deterministic correlation between the signals (I'll get to noise shortly) $\rho_{\infty}$. The $\infty$ indicates the "infinite" SNR of the deterministic portion of the signals. The total correlation coefficient (your $\phi$) is my $r$.
Using these definitions, the relative square error in approximating a data stream $\mathbf{x}$ $=$ $\mathbf{u}+\mathbf{n}$ with a waveform template $\mathbf{w }$, is the ratio of the least-squares  error $\vert\vert \mathbf{e} \vert\vert^{2}$ to measured signal energy $ \vert \vert \mathbf{x} \vert \vert^{2}$. This error may be re-written as a ratio of quadratic forms:
\begin{equation}
\begin{split}
\cfrac{\vert \vert \mathbf{e} \vert \vert^{2}}{\vert \vert \mathbf{x} \vert \vert^{2}} &= \cfrac{\vert \vert  \mathbf{x} - \hat{A} \mathbf{w }  \vert \vert^{2} }{ \vert \vert \mathbf{x} \vert \vert^{2}}
\\ 
&=  \cfrac{ \Vert  \mathbf{x} - \cfrac{\langle   \mathbf{x},\,  \mathbf{w} \rangle}{ \Vert \mathbf{w }  \Vert^{2}} \mathbf{w } \Vert^{2}} {\vert \vert \mathbf{x} \vert \vert^{2}}
\\
&=
1- \cfrac{\langle   \mathbf{x},\,  \mathbf{w} \rangle^{2} }{ \vert \vert \mathbf{w }  \vert \vert^{2} \vert \vert \mathbf{x }  \vert \vert^{2}}
\\
&=
1 - r^{2}\left( \mathbf{x}\right)
\end{split}
\label{eq:betaRelError}
\end{equation}
where $\hat{A}$ is the maximum likelihood estimate for template waveform amplitude. I will rewrite the right hand side of the second equality in the preceding Equation as a ratio of subspace projections:
\begin{equation}
\begin{split}
 \cfrac{ \Vert  \mathbf{x} - \cfrac{\langle   \mathbf{x},\,  \mathbf{w} \rangle}{ \Vert \mathbf{w }  \Vert^{2}} \mathbf{w } \Vert^{2}} {\vert \vert \mathbf{x} \vert \vert^{2}}
=  \cfrac{ \Vert  P_{W}^{\perp} \left( \mathbf{x} \right) \Vert ^{2}} { \Vert P_{W}^{\perp}\left( \mathbf{x} \right) \Vert ^{2} + \vert \vert P_{W} \left( \mathbf{x} \right) \vert \vert ^{2}}
%
\end{split}
\label{eq:betaSubspace}
\end{equation}
where $W$ is the subspace $\text{span}\left( \mathbf{w} \right)$, $W^{\perp}$ is the orthogonal complement to $W$, $P_{W}$ is the projector onto $W$ and $P^{\perp}_{W}$ is the projector onto $W^{\perp}$. The denominator follows from the Pythagorean identity for Hilbert Spaces.  I define two noncentrality parameters from these terms:
\begin{equation}
\begin{split}
\lambda &=  \cfrac{  \Vert P_{W}^{}\left( \mathbb{E} \left\{  \mathbf{x} \right\}  \right) \Vert ^{2}   }{\sigma^{2}} = \cfrac{\vert \vert P_{W} \left( \mathbf{u} \right) \vert \vert ^{2}}{\sigma^{2}} = \rho_{\infty}^{2}\cfrac{\Vert  \mathbf{u} \Vert ^{2}}{\sigma^{2}}
\\
\lambda^{\perp}  &= \cfrac{   \Vert P_{W}^{\perp}\left(  \mathbb{E} \left\{  \mathbf{x} \right\}   \right) \Vert ^{2}   }{\sigma^{2}} =  \cfrac{\vert \vert P_{W}^{\perp} \left( \mathbf{u} \right) \vert \vert ^{2}}{\sigma^{2}} = \left(1 - \rho_{\infty}^{2}\right)\cfrac{\Vert  \mathbf{u} \Vert ^{2}}{\sigma^{2}}
\label{eq:lambdaDefs}
\end{split}
\end{equation}
where the expected value and linear-projection operators commute. Now combine the previous three equations to rewrite $r^{2}\left(\mathbf{x} \right)$:
\begin{equation}
\begin{split}
1-\left(1 - r^{2}\left(\mathbf{x} \right)\right) &=  
\frac{\Vert P_{W}^{\perp}\left( \mathbf{x} \right) \Vert ^{2} + \vert \vert P_{W} \left( \mathbf{x} \right) \vert \vert ^{2}}{\Vert P_{W}^{\perp}\left( \mathbf{x} \right) \Vert ^{2} + \vert \vert P_{W} \left( \mathbf{x} \right) \vert \vert ^{2}}
\\
&\quad -\cfrac{ \Vert  P_{W}^{\perp} \left( \mathbf{x} \right) \Vert ^{2}} { \Vert P_{W}^{\perp}\left( \mathbf{x} \right) \Vert ^{2} + \vert \vert P_{W} \left( \mathbf{x} \right) \vert \vert ^{2}}
\\
&= \cfrac{ \Vert  P_{W}\left( \mathbf{x} \right) \Vert ^{2}} { \Vert P_{W}^{\perp}\left( \mathbf{x} \right) \Vert ^{2} + \vert \vert P_{W} \left( \mathbf{x} \right) \vert \vert ^{2}}
\\
&\overset{d}{=}  \cfrac{ \chi_{1}^{2}( \lambda )} { \chi_{1}^{2}( \lambda ) +  \chi_{N_{E} - 1}^{2}( \lambda^{\perp} ) } 
\end{split}
\end{equation}
where $\overset{d}{=}$ is distributional equality, $\chi_{N_{E}-1}^{2}( \lambda^{\perp} )$ is the noncentral Chi-square distribution with $N_{E} -1$ degrees of freedom and noncentrality parameter $\lambda^{\perp}$, and $\chi_{1}^{2}( \lambda )$ is the noncentral Chi-square distribution with one degree of freedom and noncentrality parameter $\lambda$. From the definition of the Beta distribution:
\begin{equation}
\begin{split}
%
r^{2}\left(\mathbf{x} \right) \sim \text{B} \left(t, \frac{1}{2}, \frac{1}{2}(N_{E}-1) ; \lambda, \lambda^{\perp} \right)
\end{split}
\end{equation}
where $\text{B}\left(t, N_{1}, N_{2}, \alpha, \beta \right)$ is the doubly noncentral Beta distribution function. It is evaluated at $t$ (with the same domain as $r^{2}$), has $N_{1}$ and $N_{2}$ degrees of freedom, and noncentrality parameters $\alpha$ and $\beta$. The scalar $N_{E}$ denotes the effective number of independent samples within $\mathbf{x}$.  
Now derive the PDF $f_{R}\left(r  ; \tau \right)$ for $r$ from the density of $r^{2}$ use a variable transformation; additionally consider values $r<0$, but fix $\tau$:
\begin{equation}
\begin{split}
f_{R}\left(r  ; \tau \right) &=  \lvert r \left( \mathbf{x} \right) \rvert \left[ \text{B}\left( r^{2}\left(\mathbf{x}\right); \,\frac{1}{2}, \,\frac{1}{2}\left( N_{E}-1\right), \,\lambda,\,\lambda^{\perp}\right) + \text{B}\left( -r^{2}\left(\mathbf{x}\right); \,\frac{1}{2}, \,\frac{1}{2}\left( N_{E}-1\right),\, \lambda,\, \lambda^{\perp}\right) \right].
%\nonumber
\label{eq:rBetaDist}
\end{split}
\end{equation}
Remember, your $\phi$ is my $r$.
One minor self promotional note: there is a seismology paper in press with this derivation in it; please cite if you use (Bulletin of the Seismological Society of America, ''A Waveform Detector that Targets Template-Decorrelated Signals and Achieves its Predicted Performance: Demonstration with IMS Data (Part I)''; Vol 106, Issue 5. I'll omit my name).
