# How MATLAB calculates matched filter gain

Here is a bunch of code from MATLAB documentation: Designing a Basic Monostatic Pulse Radar:

wav = phased.RectangularWaveform(...
'PulseWidth',1/pulseBandwidth,...
'PRF',PRF,...
'SampleRate',Fs);
matchingcoeff = getMatchedFilter(wav);

hmf = phased.MatchedFilter(...
'Coefficients',matchingcoeff,...
'GainOutputPort',true);

[rx_pulses, mfgain] = step(hmf,rx_pulses);


How MATLAB calculates the mfgain (matched filter gain)? Any formula for that?

Matched filter gain is calculated as (in dB):

• $G_{dB} = 10 \cdot \log_{10}(L)$,

where $L$ - is filter length. It's maximum possible SNR improvement that filter can provide.

Try this formula and compare result with MATLAB one. I suppose it will be the same.

Actually, if you dig into the code you'll find that MATLAB calculates the gain with the following:

obj.pMFGain = pow2db(real(obj.Coefficients'*obj.Coefficients));

Here obj is the AbstractMatchedFilter object and Coefficients are the matched filter coefficients, which, in the simplest form, is the model of your waveform sampled at the same rate as your input signal. When MATLAB calculates the matched filter, these coefficients are complex.

Note the '* in the line above, which makes this a dot-product. (sum of squares).