# Matched filter chiprate issue

Started by February 14, 2018
```Hi all,

I have received a transmission which consists of a series of PN sequences.
I recorded at 8*10^6 SPS (8 MSPS) and wish to perform a matched filter on it.

The transmission binary sequence is 1*10^6 bits long and I have just been informed
that it was transmitted at a rate of 1,016,118.24682 bits/sec which seems like a
very strange chip rate to pick but unfortunately this is beyond my control.

So my question is: how can I accurately match the sample rates to be able to perform
a matched filter?

If I use MATLABs rat function then I can get upsample/downsample ratios which are
very large requiring a lot of processing power and anyway this only approximates a
solution as over time the error becomes large and the matched filter looses sync.

Here I'm trying to upsample the 'template' to match the recorded signal:

[n, k] = rat(8e6 / 1016118.24682, 1.e-9); % gives k=23743, n=186931
resamped_template = resample(template, n, k );

Any help appreciated!

Enda
```
```Enda McKenna  <endatheworld@gmail.com> wrote:

>So my question is: how can I accurately match the sample rates to be
>able to perform a matched filter?

I'd try a four point Lagrangian interpolator, which in Matlab
may be called a "cubic" interpolator.

Steve
```
```On 14.02.2018 20:11, Steve Pope wrote:
> Enda McKenna  <endatheworld@gmail.com> wrote:
>
>> So my question is: how can I accurately match the sample rates to be
>> able to perform a matched filter?
>
> I'd try a four point Lagrangian interpolator, which in Matlab
> may be called a "cubic" interpolator.
>
> Steve
>

There are two possible solutions, either of which would work. One, as
Steve has suggested, involves the use of a Lagrangian interpolator. If
you need more context, a more detailed discussion can be found e.g. in
F.M. Gardner's 1993 article "Interpolation in digital modems" (which
consists of Part I and Part II).

The second option is to use an arbitrary rate polyphase filter. IMO,
it's best described in a book "Multirate Signal Processing" by Harris.
Alternatively, you can go for the 2001 article "Multirate digital
filters for symbol timing synchronization in software defined radios" by
Harris and Rice.

The difference between the two options is that the Lagrangian
interpolator would be typically followed by a matched filter. While you
can incorporate the matcher filter inside a polyphase filter, so the
latter has the potential to be a two-in-one option.

Gene

```
```On Thursday, 15 February 2018 10:26:27 UTC, Evgeny Filatov  wrote:
> On 14.02.2018 20:11, Steve Pope wrote:
> > Enda McKenna  wrote:
> >
> >> So my question is: how can I accurately match the sample rates to be
> >> able to perform a matched filter?
> >
> > I'd try a four point Lagrangian interpolator, which in Matlab
> > may be called a "cubic" interpolator.
> >
> > Steve
> >
>
> There are two possible solutions, either of which would work. One, as
> Steve has suggested, involves the use of a Lagrangian interpolator. If
> you need more context, a more detailed discussion can be found e.g. in
> F.M. Gardner's 1993 article "Interpolation in digital modems" (which
> consists of Part I and Part II).
>
> The second option is to use an arbitrary rate polyphase filter. IMO,
> it's best described in a book "Multirate Signal Processing" by Harris.
> Alternatively, you can go for the 2001 article "Multirate digital
> filters for symbol timing synchronization in software defined radios" by
> Harris and Rice.
>
> The difference between the two options is that the Lagrangian
> interpolator would be typically followed by a matched filter. While you
> can incorporate the matcher filter inside a polyphase filter, so the
> latter has the potential to be a two-in-one option.
>
> Gene

Thank you for the advice. I'm trying to implement a cubic spline interpolator in
Matlab but with limited results so far. I'm finding that the fractional chipping
rate will put the sequence out of sync within a few sequence lengths since obviously
it's impossible to have a fraction of a sample leaving me with the possibility of
having to insert a 'leap' sample periodically... Really struggling with this!

Enda
```
```On 19.02.2018 17:12, Enda McKenna wrote:

>
> Thank you for the advice. I'm trying to implement a cubic spline
> interpolator in Matlab but with limited results so far. I'm finding
> that the fractional chipping rate will put the sequence out of sync
> within a few sequence lengths since obviously it's impossible to have
> a fraction of a sample leaving me with the possibility of having to
> insert a 'leap' sample periodically... Really struggling with this!
>
> Enda
>

You are welcome!

Of course, the output sequence will have fewer or more samples than the
input sequence. If you do your own implementation, you will have to
account for that.

One way to think of it is to get a counter which increments with
F_in/F_out for each output sample, where F_in is the input sampling
frequency and F_out is the output sampling frequency. Then the integer
part of the counter will point to the first sample of the set of four
input samples, and the fractional part of the counter will have the
meaning the point in the [0; 1) interval (positioned between some two
fixed samples within the set of four input samples) for which you
calculate the interpolated value.

Three considerations:

(1) Before you do your own implementation, learn to use the interp1
function of Matlab:
https://www.mathworks.com/help/matlab/ref/interp1.html

Even if it doesn't account for all your needs, at the very least it
helps to be able to test your own implementation against the existing one.

(2) You might want to implement a linear interpolator before you do a
more complicated design. And actually it will provide quite good results

(3) Arbitrary rate interpolators are a bit hard to grasp, and studying
the literature really helps. Reading the references I provided takes a
fair amount of time and effort, but it's worth it.

HTH,
Gene
```
```Enda McKenna  <endatheworld@gmail.com> wrote:

>Thank you for the advice. I'm trying to implement a cubic spline
>interpolator in Matlab but with limited results so far. I'm finding that
>the fractional chipping rate will put the sequence out of sync within a
>few sequence lengths since obviously it's impossible to have a fraction
>of a sample leaving me with the possibility of having to insert a 'leap'
>sample periodically... Really struggling with this!

It can be made to work.

One visualization is that you feed the interpolator's input stream
into a circular buffer.  Each time you feed a new input value into the
buffer, check whether the buffer now contains the set of four
consecutive values needed to form one or more new outputs.  Emit those
new outputs to an output stream.  Then discard the oldest value
in the buffer.

This is analogous to how you'd have to do it in hardware.

Steve
```
```spope384@gmail.com (Steve Pope) writes:

> Enda McKenna  <endatheworld@gmail.com> wrote:
>
>>Thank you for the advice. I'm trying to implement a cubic spline
>>interpolator in Matlab but with limited results so far. I'm finding that
>>the fractional chipping rate will put the sequence out of sync within a
>>few sequence lengths since obviously it's impossible to have a fraction
>>of a sample leaving me with the possibility of having to insert a 'leap'
>>sample periodically... Really struggling with this!
>
> It can be made to work.
>
> One visualization is that you feed the interpolator's input stream
> into a circular buffer.  Each time you feed a new input value into the
> buffer, check whether the buffer now contains the set of four
> consecutive values needed to form one or more new outputs.  Emit those
> new outputs to an output stream.  Then discard the oldest value
> in the buffer.
>
> This is analogous to how you'd have to do it in hardware.

simply resample the sync sequence at the operational sample rate? You
could do the converse: resample the operational sample rate to match the
sync sequence, but that would be computationally stupid since the sinc
resampling only has to be done one at system design time.
--
Randy Yates, Embedded Linux Developer
Garner Underground, Inc.
http://www.garnerundergroundinc.com
```
```Randy Yates  <randyy@garnerundergroundinc.com> wrote:

>spope384@gmail.com (Steve Pope) writes:
>
>> Enda McKenna  <endatheworld@gmail.com> wrote:
>>
>>>Thank you for the advice. I'm trying to implement a cubic spline
>>>interpolator in Matlab but with limited results so far. I'm finding that
>>>the fractional chipping rate will put the sequence out of sync within a
>>>few sequence lengths since obviously it's impossible to have a fraction
>>>of a sample leaving me with the possibility of having to insert a 'leap'
>>>sample periodically... Really struggling with this!
>>
>> It can be made to work.
>>
>> One visualization is that you feed the interpolator's input stream
>> into a circular buffer.  Each time you feed a new input value into the
>> buffer, check whether the buffer now contains the set of four
>> consecutive values needed to form one or more new outputs.  Emit those
>> new outputs to an output stream.  Then discard the oldest value
>> in the buffer.

>> This is analogous to how you'd have to do it in hardware.

>simply resample the sync sequence at the operational sample rate?

Are you saying you could save computation by resampling the sync
pattern and not the data stream?

The answer is yes, sometimes, but this is not how the OP posed
their question.

Whether this would work well depends on scenario.

Steve
```
```spope384@gmail.com (Steve Pope) writes:

> Randy Yates  <randyy@garnerundergroundinc.com> wrote:
>
>>spope384@gmail.com (Steve Pope) writes:
>>
>>> Enda McKenna  <endatheworld@gmail.com> wrote:
>>>
>>>>Thank you for the advice. I'm trying to implement a cubic spline
>>>>interpolator in Matlab but with limited results so far. I'm finding that
>>>>the fractional chipping rate will put the sequence out of sync within a
>>>>few sequence lengths since obviously it's impossible to have a fraction
>>>>of a sample leaving me with the possibility of having to insert a 'leap'
>>>>sample periodically... Really struggling with this!
>>>
>>> It can be made to work.
>>>
>>> One visualization is that you feed the interpolator's input stream
>>> into a circular buffer.  Each time you feed a new input value into the
>>> buffer, check whether the buffer now contains the set of four
>>> consecutive values needed to form one or more new outputs.  Emit those
>>> new outputs to an output stream.  Then discard the oldest value
>>> in the buffer.
>
>>> This is analogous to how you'd have to do it in hardware.
>
>>simply resample the sync sequence at the operational sample rate?
>
> Are you saying you could save computation by resampling the sync
> pattern and not the data stream?

Yes, exactly.

> The answer is yes, sometimes, but this is not how the OP posed
> their question.

Understood.

> Whether this would work well depends on scenario.

All I can think of is that the "operational" sample rate must be higher
than the original sample rate. Are there other issues?
--
Randy Yates, Embedded Linux Developer
Garner Underground, Inc.
http://www.garnerundergroundinc.com
```