Sampling rate of a customized signal source

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

Hi Pengyu,
There are few considerations:

On Sat, May 31, 2014 at 4:19 AM, Pengyu Z. [email protected]
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.

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

Hi Activecat,

Thanks for your detailed examples. I will try set_output_multiple() and
tell you my user experiences :slight_smile:

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

On Sat, May 31, 2014 at 11:03 PM, Pengyu Z. [email protected]
wrote:

that I can follow? Thanks.

Pengyu

I’ve created a sample for you at 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.

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

On Sat, May 31, 2014 at 11:47 PM, Activecat [email protected] wrote:

I’ve created a sample for you at 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.

https://github.com/activecat/gr-test1

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs