# Proper setting for sample delay for polyphase arbitrary resampler?

**URL:** <https://www.ruby-forum.com/t/proper-setting-for-sample-delay-for-polyphase-arbitrary-resampler/230574>\
**Category:** GNU Radio\
**Created:** [June 24, 2014, 8:16pm UTC](https://www.ruby-forum.com/t/proper-setting-for-sample-delay-for-polyphase-arbitrary-resampler/230574 "2014-06-24T20:16:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 24, 2014, 8:16pm UTC](https://www.ruby-forum.com/t/proper-setting-for-sample-delay-for-polyphase-arbitrary-resampler/230574/1 "2014-06-24T20:16:59Z")

</div>

Hi,

I have a Polyphase Arbitrary Resampler block in a flow graph and I want  
to set the “Sample Delay” parameter so GnuRadio delays tags properly.

With the following parameters:

Input Sample Rate: Fs  
Resampling Rate: r = output\_rate / Fs  
Number of Filters: N  
Taps: taps=firdes.low\_pass\_2(N, N\*Fs, …, …, …,)

The best I can figure is to set:

Sample Delay: int(round((math.ceil(len(taps)/N) - 1.0)/2.0))

because GnuRadio applies this “Sample Delay” as offset to the tags  
before scaling the tag offsets by the resampling rate r.

Can anyone confirm this is correct, or is there something I’m missing?

Thank you.

Regards,  
Andy

---

<div class="post-metadata">

**Author:** ![andywatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@andywatts](https://www.ruby-forum.com/u/andywatts)\
**Post date:** [June 25, 2014, 4:12pm UTC](https://www.ruby-forum.com/t/proper-setting-for-sample-delay-for-polyphase-arbitrary-resampler/230574/2 "2014-06-25T16:12:39Z")

</div>

On Tue, Jun 24, 2014 at 2:15 PM, Andy W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Taps: taps=firdes.low\_pass\_2(N, N\*Fs, …, …, …,)  
> Thank you.
> 
> Regards,  
> Andy

Andy,

Take a look at pfb\_arb\_resampler.cc. In the constructor, it calculates  
the  
sample delay. It’s close to what you’re thinking, but scaled for the  
polyphase filterbank partitioning.

Tom

---

<div class="post-metadata">

**Author:** ![andywatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@andywatts](https://www.ruby-forum.com/u/andywatts)\
**Post date:** [June 26, 2014, 9:54pm UTC](https://www.ruby-forum.com/t/proper-setting-for-sample-delay-for-polyphase-arbitrary-resampler/230574/3 "2014-06-26T21:54:10Z")

</div>

On Wed, 2014-06-25 at 10:09 -0400, Tom R. wrote:

> ```
> Resampling Rate: r = output_rate / Fs
> Can anyone confirm this is correct, or is there something I'm missing?
> 
> ```
> 
> Take a look at pfb\_arb\_resampler.cc. In the constructor, it calculates  
> the sample delay. It’s close to what you’re thinking, but scaled for  
> the polyphase filterbank partitioning.

Hi Tom,

Thanks for the response.

Yes, I did look at the pfb\_arb\_resampler.cc for my starting point. 🙂  
The ‘N’ above takes into account the scaling for the polyphase banks  
(N=32 filters in my specific case).

I verified by inspection that  
gnuradio/gnuradio-runtime/lib/block\_executor.cc:propagate\_tags() does  
take care of the multiplication by rrate (my ‘r’ above), so that should  
not be in the sample delay expression.

I built a test flowgraph to check my equation, using an input sawtooth  
and peak detectors and burst taggers on each side of the  
pfb\_arb\_resampler block. (See attached PNG.) The tags lined up to within  
4 samples on the output side, and given that I didn’t heavily tune the  
peak detector configuration, I think I’m good. 🙂

Regards,  
Andy

---

<div class="post-metadata">

**Author:** ![andywatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@andywatts](https://www.ruby-forum.com/u/andywatts)\
**Post date:** [June 26, 2014, 10:10pm UTC](https://www.ruby-forum.com/t/proper-setting-for-sample-delay-for-polyphase-arbitrary-resampler/230574/4 "2014-06-26T22:10:49Z")

</div>

On Thu, Jun 26, 2014 at 3:52 PM, Andy W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ```
> > With the following parameters:
> > 
> > ```
> 
> 1.0)/2.0))
> 
> > ```
> > Regards,
> > 
> > ```
> 
> Hi Tom,
> 
> Thanks for the response.
> 
> Yes, I did look at the pfb\_arb\_resampler.cc for my starting point. 🙂  
> The ‘N’ above takes into account the scaling for the polyphase banks  
> (N=32 filters in my specific case).

Oops, overlooked that.

> I verified by inspection that  
> gnuradio/gnuradio-runtime/lib/block\_executor.cc:propagate\_tags() does  
> take care of the multiplication by rrate (my ‘r’ above), so that should  
> not be in the sample delay expression.

Yep.

> I built a test flowgraph to check my equation, using an input sawtooth  
> and peak detectors and burst taggers on each side of the  
> pfb\_arb\_resampler block. (See attached PNG.) The tags lined up to within  
> 4 samples on the output side, and given that I didn’t heavily tune the  
> peak detector configuration, I think I’m good. 🙂
> 
> Regards,  
> Andy

Great! Yes, getting exact peak detection is always hard. Glad things are  
working as well as they are, though.

Tom
