# Sampling rate of a customized signal source

**URL:** <https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108>\
**Category:** GNU Radio\
**Created:** [May 30, 2014, 10:19pm UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108 "2014-05-30T22:19:55Z")\
**Posts on this page:** 7\
**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:** [May 30, 2014, 10:19pm UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/1 "2014-05-30T22:19:55Z")

</div>

Hi All,

How to determine the sampling rate of a customized signal source?

I designed a customized signal source which should output two 1ms pulses  
every 10ms. If I do not know the sampling rate of the customized module,  
I  
do not know how many elements I should put into the out\* buffer for  
generating the two 1ms pulses.

Pengyu

---

<div class="post-metadata">

**Author:** ![Pengyu\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@Pengyu\_Z](https://www.ruby-forum.com/u/Pengyu_Z)\
**Post date:** [May 31, 2014, 6:17am UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/2 "2014-05-31T06:17:30Z")

</div>

Hi Pengyu,  
There are few considerations:

On Sat, May 31, 2014 at 4:19 AM, Pengyu Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi All,  
> How to determine the sampling rate of a customized signal source?
> 
> I designed a customized signal source which should output two 1ms pulses  
> every 10ms. If I do not know the sampling rate of the customized module, I  
> do not know how many elements I should put into the out\* buffer for  
> generating the two 1ms pulses.

To make the discussion easy, let’s assume there is rate-limiting block  
(eg.  
throttle, USRP etc) in your flowgraph.

1). When your parameters above are described in time (example 1ms, 10ms  
etc), it is very likely that you will need to configure “Sample Rate”  
(which is samp\_rate) as one of the variables of your custom block  
setting.

2). If you need 1ms pulses, this means your samp\_rate must not be lower  
than 1kHz.  
In fact your samp\_rate must be multiple of 1kHz.  
You may want to put a runtime check on this.

3). When you say “should output two 1ms pulses every 10ms”, does it  
mean  
it output one 1ms pulse every 5ms ?  
Let me assume yes to proceed with the discussion.

Says, the amplitude of the pulse is 1V.

4). When samp\_rate=1kHz, then your custom block will output one 1V and  
four 0V in every five outputs.  
This means you need to “set\_output\_multiple(5)”

5). When samp\_rate=10kHz, then your custom block will output ten 1V and  
forty 0V in every fifty outputs.  
This means you need to “set\_output\_multiple(50)”.

6). To generalize item 4 and 5 above, you need to  
“set\_output\_multiple( samp\_rate / 200 );”

… (many more)

This gives you some idea to start with, the rest is up to you to figure  
out.  
Good luck.

---

<div class="post-metadata">

**Author:** ![Pengyu\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@Pengyu\_Z](https://www.ruby-forum.com/u/Pengyu_Z)\
**Post date:** [May 31, 2014, 11:46am UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/3 "2014-05-31T11:46:15Z")

</div>

Hi Pengyu, Activecat!

These are very good considerations!  
I just wanted to add, since this comes up rather frequently, that in  
digital signal processing like GNU Radio,  
there is no “factual” sampling rate. So if you “calculate” a signal,  
it’s frequency can only be measured by the number of samples a period of  
that signal takes.

So I’m a little confused about your customized module, either it is pure  
software, in which case you, Pengyu, set the sampling rate,  
calculate how many samples equal 1ms etc (like Activecat explained), or  
it is a hardware source, in which case there should be some driver etc  
to tell you about  
your sampling rate. Samples do not carry any “additional” information  
such as sampling rate, they are just numbers.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Pengyu\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@Pengyu\_Z](https://www.ruby-forum.com/u/Pengyu_Z)\
**Post date:** [May 31, 2014, 5:04pm UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/4 "2014-05-31T17:04:09Z")

</div>

Hi Activecat,

Thanks for your detailed examples. I will try set\_output\_multiple() and  
tell you my user experiences 🙂

I still have a question which was posted at the beginning of my previous  
email. How to configure the “Sample Rate” (which is samp\_rate) as one of  
the variables of my custom block? For blocks provided by GRC, you can  
click  
the GUI block and see an option of setting the sample rate. For  
customized  
block, how to integrate this variable in the c++ code? Is there an  
example  
that I can follow? Thanks.

Pengyu

---

<div class="post-metadata">

**Author:** ![Pengyu\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@Pengyu\_Z](https://www.ruby-forum.com/u/Pengyu_Z)\
**Post date:** [May 31, 2014, 5:48pm UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/5 "2014-05-31T17:48:56Z")

</div>

On Sat, May 31, 2014 at 11:03 PM, Pengyu Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> that I can follow? Thanks.
> 
> Pengyu

I’ve created a sample for you at [GitHub - activecat/gr-test1: GNU Radio: Examples of how to use "Sample Rate" for gnuradio out-of-tree module · GitHub](https://github.com/activecat/gr-test1)  
You could run the flowgraph found in the “examples” directory.  
Try to change the samp\_rate of the flowgraph from 32kHz to different  
values  
(64kHz, 200kHrz etc).  
You will observe via the GUI Scope Sink, that the block consistently  
produces two 1ms pulse for every 10ms.

---

<div class="post-metadata">

**Author:** ![Pengyu\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@Pengyu\_Z](https://www.ruby-forum.com/u/Pengyu_Z)\
**Post date:** [June 2, 2014, 8:54pm UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/6 "2014-06-02T20:54:18Z")

</div>

Hi Activecat,

Thanks for providing the flowgraph\_01.grc example. Now I understand that  
how to set sample rate of a customized block. For others, sample rate of  
a  
customized block can be initialized in the make() function of the block.  
Details of setting the sample rate can be found in Activecat’s example.  
Thanks.

make(float samp\_rate)  
{  
return gnuradio::get\_initial\_sptr  
(new reader\_impl(samp\_rate));  
}

Pengyu

---

<div class="post-metadata">

**Author:** ![Pengyu\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@Pengyu\_Z](https://www.ruby-forum.com/u/Pengyu_Z)\
**Post date:** [June 1, 2014, 7:32am UTC](https://www.ruby-forum.com/t/sampling-rate-of-a-customized-signal-source/230108/7 "2014-06-01T07:32:04Z")

</div>

On Sat, May 31, 2014 at 11:47 PM, Activecat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve created a sample for you at [GitHub - activecat/gr-test1: GNU Radio: Examples of how to use "Sample Rate" for gnuradio out-of-tree module · GitHub](https://github.com/activecat/gr-test1)  
> You could run the flowgraph found in the “examples” directory.  
> Try to change the samp\_rate of the flowgraph from 32kHz to different  
> values (64kHz, 200kHrz etc).  
> You will observe via the GUI Scope Sink, that the block consistently  
> produces two 1ms pulse for every 10ms.

Try to run gr-test1/examples/flowgraph\_02.grc, you may try setting  
different values to samp\_rate of the flowgraph.  
The outcomes indicates that this “pulse1” block is very consistent with  
the  
built-in Signal Source block, in term of how it works respecting to the  
samp\_rate variable.

> **[GitHub - activecat/gr-test1: GNU Radio: Examples of how to use "Sample Rate"...](https://github.com/activecat/gr-test1)**
>
> GNU Radio: Examples of how to use "Sample Rate" for gnuradio out-of-tree module
