# GRC, Recording chunks of spectrum triggered on input signal level

**URL:** <https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036>\
**Category:** GNU Radio\
**Created:** [November 12, 2014, 8:55pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036 "2014-11-12T20:55:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [November 12, 2014, 8:55pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/1 "2014-11-12T20:55:55Z")

</div>

Hello,

Being limited in my programming skills, I would very much like to do the  
following in Gnuradio Companion:

- Sample an input stream (from RTL-SDR)
- Generate a trigger signal based on the input stream
- If a trigger criterion is met, save/sink the data stream for a preset  
time and give the file a name based on time of acquisition (or similar)
- Reset the flow and start all over.

Getting the input stream is no problem and I believe I know how to  
generate the trigger signal, but starting a sink (with a new filename)  
for a preset time (number of samples is fine) based on this signal seems  
tricker (not to mention the file naming part).

If anyone can provide suggestions for how to

- start a new sink (new file) based on an integer signal shifting from 0  
to 1
- automatically name each file sequence, sequential numbering is OK

this would be very much appreciated!

Many thanks in advance!

Regards,  
Staffan

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 12, 2014, 9:56pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/2 "2014-11-12T21:56:12Z")

</div>

Hi Staffan,

I think that you’ll find the things you describe can be best noted more  
or less algorithmically (which you have already done!); and thus, I’d  
think it’s easier to actually write that specific sink you need than to  
do what you want to do in GRC (I must admit I can’t think of a way of  
doing that in GRC… it’s just so un-graphically-clickable 😉 ).

Now, this might sound like bad news to you, but I assure you that  
writing a python block is not as hard as it might sound to you; just  
follow the first few of our new guided tutorials [1] and you might write  
your own sink that writes each chunk of samples – as your detector  
tagged it – to a new file.

Greetings, and happy hacking,  
Marcus

[1][http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorials](http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorials)

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 12, 2014, 11:51pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/3 "2014-11-12T23:51:26Z")

</div>

See my note about dynamic recording of file names:

> **[GNU Radio – RF Power Amp](https://rfpoweramp.com/category/sdr/gnu-radio/)**
>
> Posts about GNU Radio written by rfengr00

The file sink is either being directed to “filename” or “/dev/null”.  
You  
can dynamically change that during the flow with a boolean check box.  
In  
your case, instead of the check box, you would setup a probe to monitor  
your  
integer, and maybe probe at 10 times a second, which would change the  
file  
name.

The actual “filename” is a python statement that concatenates the system  
time and other info into a formatted string.

I’ll post an example GRC file tonight that shows the dynamic recording  
with  
time stamped file. I’m going to try the ARRL Frequency Measurement test  
tonight, and wrote a GRC flow with that functionality (not the probe  
part,  
but I’m using probes to display the channel power).

Lou  
KD4HSO

Staffan Bruce wrote

> this would be very much appreciated!
> 
> Many thanks in advance!
> 
> Regards,  
> Staffan
> 
> * * *
> 
> Discuss-gnuradio mailing list

> Discuss-gnuradio@

> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51305.html](http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51305.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 13, 2014, 5:26am UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/4 "2014-11-13T05:26:19Z")

</div>

Here is the file:

[https://dl.dropboxusercontent.com/u/49570443/fmt.grc](https://dl.dropboxusercontent.com/u/49570443/fmt.grc)

Lou

madengr wrote

> I’ll post an example GRC file tonight that shows the dynamic recording  
> with time stamped file. I’m going to try the ARRL Frequency Measurement  
> test tonight, and wrote a GRC flow with that functionality (not the probe  
> part, but I’m using probes to display the channel power).

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51309.html](http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51309.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 13, 2014, 8:53pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/5 "2014-11-13T20:53:47Z")

</div>

Hello all,

## Many, many, thanks for the suggestions! I just tried the example by Lou

very good way to update the filename - didn’t realize the variable  
statement  
was that powerful.  
I will also test the tagged file sink and - indeed - I have started  
reading  
the HOWTOs.

Again, many thanks for the very fast response from you all!

Regards,  
Staffan

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51317.html](http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51317.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 13, 2014, 9:49pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/6 "2014-11-13T21:49:27Z")

</div>

You can refer “uhd\_burst\_detector.py” in “gnuradio/examples/tags” as a  
starting point.

Regards  
Sreeraj Rajendran

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 13, 2014, 1:37am UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/7 "2014-11-13T01:37:36Z")

</div>

On 11/12/2014 02:54 PM, Staffan Bruce wrote:

> Hello,  
> Being limited in my programming skills, I would very much like to do the  
> following in Gnuradio Companion:
> 
> - Sample an input stream (from RTL-SDR)
> - Generate a trigger signal based on the input stream
> - If a trigger criterion is met, save/sink the data stream for a preset  
> time and give the file a name based on time of acquisition (or similar)
> - Reset the flow and start all over.

The Tagged File Sink does most of what you’re looking for.  
src → trigger → tagged file sink → “timestamped” files

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 17, 2014, 8:57am UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/8 "2014-11-17T08:57:36Z")

</div>

Hello,

After some weekend experimenting I believe I have most (most…) of it  
working. Sinking to a USB stick is not working so well by the way…  
One thing that is still a challenge is how to set the filename. You  
provided  
a very good way of timestamping, but when I try this, it only evaluates  
once - when I start the script. Is there any way to force re-evaluation  
of a  
variable?  
In addition, it would be great to have some kind of a counter (variable,  
x =  
x + 1) that can be updated depending on a state change - for example  
when a  
trigger event occurrs. I tried some different versions, but mainly ended  
up  
in circular references…

Any suggestions would be highly appreciated!

Regards,  
Staffan

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 17, 2014, 7:05pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/9 "2014-11-17T19:05:48Z")

</div>

If you are using an “if” statement to switch between filename and  
/dev/null,  
try putting the filename construction in the “if” statement, instead of  
a  
separate variable. That may make it evaluate every time the “if”  
statement  
is called.

My example used the LO frequency as part of the filename, and every time  
the  
QT GUI slider changed the LO, it probably updated the filename.

If that does not work, maybe you can use a probe to examine a signal,  
say  
10x a second. Then the probe level() function could be used as part of  
the  
filename. That would at least change it 10x a second.

For the counter, maybe you could also use a probes to look at a signal  
before and after a N sample delay, where delay and sample rate is about  
the  
same time as your probe rate; then this pseudocode:

if now.level() != delayed.level() then count = count +1

At this point though you ought to delve into the Python. As long as you  
are  
not using the QT GUI, the code is pretty straight forward. You can use  
probes to pull values out of the flow and evaluate them in Python.

Thanks,  
Lou  
KD4HSO

Staffan wrote

> In addition, it would be great to have some kind of a counter (variable, x  
> Staffan  
> –  
> View this message in context:  
> [http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51339.html](http://gnuradio.4.n7.nabble.com/GRC-Recording-chunks-of-spectrum-triggered-on-input-signal-level-tp51302p51339.html)  
> Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 19, 2014, 11:47pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/10 "2014-11-19T23:47:15Z")

</div>

All these workarounds seems hacky  
Is there a paradigm that can handle this.

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 18, 2014, 10:18pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/11 "2014-11-18T22:18:43Z")

</div>

It works, many thanks!

It seems like the changing of a variable in itself does not trigger an  
update of other variables (that are depending on the first one), but  
using a  
button or probe will trigger an update of the variables that are  
depending  
on them. Could this be something to consider for GnuRadio/Companion,  
i.e.,  
dependencies between variables and assuring that they are updated when a  
change is occurring in one of them?

Still, file sink notices the change of the variable it is depending on  
and  
that is enough. Now I have a good way of making separate recordings -  
great!

…and yes - time to start learning how to code.

Regards,  
Staffan

---

<div class="post-metadata">

**Author:** ![Staffan\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Staffan\_Bruce](https://www.ruby-forum.com/u/Staffan_Bruce)\
**Post date:** [November 19, 2014, 11:56pm UTC](https://www.ruby-forum.com/t/grc-recording-chunks-of-spectrum-triggered-on-input-signal-level/233036/12 "2014-11-19T23:56:55Z")

</div>

On 11/18/2014 04:17 PM, Staffan Bruce wrote:

> It works, many thanks!
> 
> It seems like the changing of a variable in itself does not trigger an  
> update of other variables (that are depending on the first one), but  
> using a button or probe will trigger an update of the variables that  
> are depending on them. Could this be something to consider for  
> GnuRadio/Companion, i.e., dependencies between variables and assuring  
> that they are updated when a change is occurring in one of them?  
> The dependency tree in GRC _does_ work, but not “backwards”. If b  
> depends on a, and a changes, b will be updated, but not the other way  
> around.

> Still, file sink notices the change of the variable it is depending on  
> and that is enough. Now I have a good way of making separate  
> recordings - great!
> 
> …and yes - time to start learning how to code.  
> I will point out, gently, that this is _software_ defined radio, rather  
> than, for example, interpretive-dance defined radio. So going into it  
> expecting  
> to never have to actually “code” anything is a rather naive. The GRC  
> “Lego™-like” model can, realistically, only take you so far. For  
> one, it has  
> a data-flow model, so doing “algorithmic” things requires that you  
> escape from that model, which lands you smack in the middle of  
> fairly-conventional  
> software development…

> If you are using an “if” statement to switch between filename and  
> If that does not work, maybe you can use a probe to examine a signal, say
> 
> > re-evaluation of  
> > in circular references…  
> > –  
> > Discuss-gnuradio mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

–  
Marcus L.  
Principal Investigator  
Shirleys Bay Radio Astronomy Consortium

> **[Live Draw HK Tercepat | Result HK | HK Pools | Live HK | HK Prize Hari Ini](https://www.sbrac.org/)**
>
> Temukan live draw hk tercepat melalui halaman hk pools yang resmi dan dapatkan result hk prize melalui live hk secara langsung di situs kami.
