# Matched Filter Confusion

I have seen some youtube explanations where matched filtering is explained as taking the input signal time reverse version with delay and then we do convolution of the input with this filter. But in many other references I have seen that match filtering is taking a template and sliding it over the input signal and looking for a maximized SNR, I do not understand how are these two related

The YouTuber reverses and time delays the (expected) input signal $$x(t)$$ to get $$h(t) = x(T-t)$$ which the YouTuber then pretends is the impulse response of the matched filter for signal $$x(t)$$. The YouTuber then computes the response of the matched filter to the signal $$x(t)$$ which everybody knows is given by the dreaded convolution integral. Specifically, at any given time $$\tau$$, the matched filter output $$y(\tau)$$ is given by \begin{align}y(\tau) &= x\star h\big |_\tau\\ &= \int_{-\infty}^\infty x(t)h(\tau-t) \,\mathrm dt\\ &= \int_{-\infty}^\infty x(t)x(t+T-\tau)) \,\mathrm dt\tag{1} \end{align} which, if you think about it a little bit, is just the autocorrelation function $$R_x(\cdot)$$ of $$x(t)$$ evaluated at offset $$T-\tau$$. More succinctly, $$y(\tau) = R_x(T-\tau).$$ Now, autocorrelation functions have a maximum value at $$0$$, and so we see that the matched filter output $$y(\tau)$$ peaks at $$\tau = T$$. If the YouTuber had wanted the output to peak at $$T^\prime$$, she would have chosen the matched filter impulse response to be $$h(t) = x(T^\prime - t)$$ and no one would have been the wiser. All this is explained in gory detail here on dsp.SE.

Turning to the other references (presumably not on YouTube) that talk of sliding a template over the input signal and seeing where the SNR is maximized, note that unless you specify how the SNR value is found during the sliding, the notion is meaningless. "Sliding a template" over the signal while keeping an eye on the "SNR meter" is essentially an anthropomorphic activity; we mere DSPers must work differently. If the input is $$x(t)$$ and the template is $$g(t)$$, then in the usual case of an AWGN channel, the SNR is maximized at the $$\tau$$ such that $$w(\tau) = \int_{-\infty}^\infty x(t)g(t-\tau) \,\mathrm dt\tag{2}$$ has maximum value. And no, for arbitrary templates $$g(t)$$, it is not possible determine the value of $$\tau$$ where $$w(t)$$ has maximum value by pure thought; we need to compute $$(2)$$ for every $$\tau$$ and then find the location of the maximum value. Life is a lot easier when the template $$g(t)$$ is $$x(t)$$ itself (or a delayed version of $$x(t)$$ as in $$(1)$$) and of course in hindsight, this makes the most sense. Why on earth would one want to try and match up $$x(t)$$ with an arbitrary template wholly unrelated to $$x(t)$$?

A matched filter is set up as a filter, in that it generates an output sample for each input sample applied to the filter. A correlation processor examines the correlation at set points, usually at a rate less than the sampling rate.

In the following analysis I've used the continuous time version of filtering.

You can see that applying the matched filter via convolution produces the same result as a correlation. Let $$x(t)$$ be the input sequence and $$h(t)$$ be the filter and let $$y(t)$$ denote the output sequence given by convolution. Setting the filter $$h(t)=x^*(-t)$$ (the time reversed conjugate or matched filter) then gives:

$$\begin{eqnarray} y(t) &=& \int h(\tau)x(t-\tau)d \tau\\ &=&\int x^*(-\tau)x(t-\tau)d \tau\\ &=&\int x^*(\tau)x(t+\tau)d \tau,\\ \end{eqnarray}$$ where the last line comes from a simple variable substitution for the variable $$\tau$$.

Evaluating the output at time $$t=0$$ gives $$y(0) = \int x^*(\tau)x(\tau)d \tau\\$$ which is the definition of the correlation.