# [Back to basics] Detection - matched filter

Started by March 4, 2004
```Hi All.

I need to detect a 1kHz square wave sampled at 48kHz.
I have no idea of what the SNR will be.

I remember that the optimal solution to detect a known waveform in
the presence of white noise is the matched filter.

To reduce computation cost , I downsample by 12
And the 32-bits input buffer is converted into a full scale 16-bits
buffer.
I compute mean(x) , and center the buffer (x = x-mean(x))

Now I compute  correlation with the square waveform [ __|&#2013266095;&#2013266095;|__ ]
I take the max of the correlation vector and use it as a statistical
detection threshold..

I think this could be safer and simplier

```
```Curl wrote:

> Hi All.
>
> I need to detect a 1kHz square wave sampled at 48kHz.
> I have no idea of what the SNR will be.
>
> I remember that the optimal solution to detect a known waveform in
> the presence of white noise is the matched filter.
>
> To reduce computation cost , I downsample by 12
> And the 32-bits input buffer is converted into a full scale 16-bits
> buffer.
> I compute mean(x) , and center the buffer (x = x-mean(x))
>
> Now I compute  correlation with the square waveform [ __|&#2013266095;&#2013266095;|__ ]
> I take the max of the correlation vector and use it as a statistical
> detection threshold..
>
> I think this could be safer and simplier
>

Only this for now: The waveform won't (better not be!) be as square as
you seem to imagine it. You will need to filter out harmonics above the
23rd. That will round corners and may tilt the flat parts. In order to
downsample by 12 (giving an effective sample rate of 4 KHz), you will
need to remove components at and above 2 KHz. Since the square wave
consists of odd harmonics, only the fundamental will be left. The good
news is that noise is removed too.

Jerry
--
Engineering is the art of making what you want from things you can get.
&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;

```