# How do you calculate the gain of a matched filter?

I know that you can calculate the gain of a low-pass filter by summing the filter coefficients. I don't know how to calculate the gain of an arbitrary matched filter.

For instance, I have created a matched filter for an 802.11a long training symbol (for the purposes of this question that detail doesn't matter- just thought some of you might be curious). My MATLAB code for creating the filter is:

longSymFreq = [0 1 -1 -1 1 1 -1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 1 -1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 ...
1 1 -1 -1 1 1 -1 1 -1 1 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 1 1 1];
longSymTime = ifft(longSymFreq);
intentionalTimeOffset = 4;
% Barrel shift by intentionalTimeOffset to avoid the corruption of the early data samples.  Due to the
% cyclic prefix doing this is not a problem.
longSymTime = [longSymTime(end-(intentionalTimeOffset-1):end) longSymTime(1:end-intentionalTimeOffset)];
longSymFilter = conj(fliplr(longSymTime));


The sum of this filter is 6.938893903907228e-018 +3.122502256758253e-017i. The average of the absolute value of the taps, though, is 0.107538417337840, so clearly the sum is not giving me any information on what kind of gain I will get when the filter gets the matched signal.

• How do I calculate that gain? The reason I care is because my final filter will be fixed-point, and I can't have an overflow when I get the signal that I'm looking for.

• Is the gain the energy of the filter?

$$H(0) = \sum_{n=0}^{N-1} h[n] e^0 = \sum_{n=0}^{N-1} h[n]$$
where $H(\omega)$ is the frequency response of the filter at angular frequency $\omega \in [-\pi, \pi)$. What you are concerned about is how large the peak can possibly be when your matched filter lines up perfectly with your signal of interest. That's easy to calculate for a constant-envelope signal like yours:
$$P = G \sum_{n=0}^{N-1} |h[n]|^2$$
If the matched filter lines up perfectly with the signal you're looking for (both in time and in phase, which is the worst case for this analysis), you're effectively calculating the squared magnitude of each sample and summing them all up. Now, in any practical system, there will be some gain or loss factor $G$ that is not known a priori; this reflects the fact that you won't know the exact power level of the input signal as it hits your ADC. If you have an automatic-gain-control (AGC) loop, you could use its nominal output level to decide what $G$ is and therefore calculate the maximum peak $P$. Otherwise, you can design for worst-case values of $G$ to ensure that you don't overflow with the resulting value of $P$.