# Help accessing fft bins in python script

**URL:** <https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586>\
**Category:** GNU Radio\
**Created:** [October 16, 2014, 7:38pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586 "2014-10-16T19:38:17Z")\
**Posts on this page:** 9\
**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:** [October 16, 2014, 7:38pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/1 "2014-10-16T19:38:17Z")

</div>

Using qa\_fft.py for inspiration[1], I’m trying to feed a raw capture  
file into an fft of size 32 and then review the 32 fft bins at an  
instantaneous point in time[2]. I must be doing something wrong however  
because when I review the vector sink’s data() method, it returns a  
rather large array (compared to the 32-element array I am expecting).  
data() seems to return an array with the same number of elements as  
samples fed into the fft. I just want an array of the 32 fft bins so I  
can calculate the relative power in the given band.

Any help/pointers appreciated!  
Thanks

[1]  
[http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/master/entry/gr-fft/python/fft/qa\_fft.py](http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/master/entry/gr-fft/python/fft/qa_fft.py)  
[2]  
[https://github.com/regulatre/grfun/blob/9dbbf676d2fea013787720273af0b419699c75a4/hello-fft/decodeDump162.py](https://github.com/regulatre/grfun/blob/9dbbf676d2fea013787720273af0b419699c75a4/hello-fft/decodeDump162.py)

[Brad H.]

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 16, 2014, 7:46pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/2 "2014-10-16T19:46:02Z")

</div>

The vector sink is for debugging only. Don’t use it in production code,  
because there’s no convenient way to

vacuum it out, so it grows without bound.

When I’ve had this problem, I use a vector-probe block, and have a  
function probe running at a couple of Hz,

and then leverage the dependency-tree evaluator to have my own function  
called with the result of the

function probe. There are other ways, that’s the one I personally find  
most convenient. But there are message

queues and sundry other methods as well.

On 2014-10-16 13:36, Brad H. wrote:

> * * *
> 
> 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) [1]

Links:

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 16, 2014, 8:03pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/3 "2014-10-16T20:03:18Z")

</div>

A very simple way would just be to write your block downstream of the  
FFT in Python. You can then operate on the vectors in the work function.

M

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 17, 2014, 7:51am UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/4 "2014-10-17T07:51:34Z")

</div>

Sometimes when I want to grab samples and perform some periodic  
operation  
like CNR estimation, or fine-frequency estimation I sometimes use a  
vector\_sink, and then two function probe blocks - one to read the data  
and  
one to reset it (yes I call the reset function from the function probe).  
This seems to work wonderfully for certain corner cases where a vector  
sink  
doesn’t work well. And I mostly use this technique when I want to  
prototyping something quickly before writing a block. But am I asking  
for  
trouble with memory allocation issues???

_Also, I was thinking, it would be good to have the option, either a  
block  
parameter or an overloaded function) to reset the vector\_sink, each time  
.data() is called… I can code this up unless anyone thinks this  
functionality would lead to regressions._

But I agree the vector sink block is much more convenient for FFTs…

-John

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 17, 2014, 2:39am UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/5 "2014-10-17T02:39:03Z")

</div>

Is there any way to access the fft bins from python without writing a  
custom block?

----- Original Message -----

From: “Martin B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Thursday, October 16, 2014 2:02:03 PM  
Subject: Re: [Discuss-gnuradio] help accessing fft bins in python script

A very simple way would just be to write your block downstream of the  
FFT in Python. You can then operate on the vectors in the work function.

M

On 10/16/2014 07:44 PM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and then leverage the dependency-tree evaluator to have my own
> 
> > however because when I review the vector sink’s data() method, it

[http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/master/entry/gr-fft/python/fft/qa\_fft.py](http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/master/entry/gr-fft/python/fft/qa_fft.py)

> > [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)
> 
> * * *
> 
> 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)

* * *

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)**

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 17, 2014, 6:30pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/6 "2014-10-17T18:30:49Z")

</div>

See attached screen shot. You’ll need to change some things around for  
3.7. Use a probe vector instead and change the call in the function  
probe  
“data” accordingly. Probe buffer is from a proprietary out-of-tree  
module  
used with 3.6…

-John

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 17, 2014, 6:42pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/7 "2014-10-17T18:42:44Z")

</div>

Again, if one uses the vector-probe block, one can call the appropriate  
function from a function-probe, at that point, you have a variable with  
the contents of the FFT output vector in it, which can be used in a call  
to your

own Python code.

On 2014-10-17 12:01, Brad H. wrote:

> SUBJECT: Re: [Discuss-gnuradio] help accessing fft bins in python script
> 
> > M
> > 
> > > function probe running at a couple of Hz,
> > > 
> > > > file into an fft of size 32 and then review the 32 fft bins at an
> > > > 
> > > > Discuss-gnuradio mailing list
> > 
> > * * *
> 
> 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) [3]

Links:

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 17, 2014, 7:22pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/8 "2014-10-17T19:22:37Z")

</div>

k1gto wrote

> Is there any way to access the fft bins from python without writing a  
> custom block?

See this:  
[http://ha5kfu.sch.bme.hu/fft\_test](http://ha5kfu.sch.bme.hu/fft_test)

Lou  
KD4HSO

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/help-accessing-fft-bins-in-python-script-tp50854p50891.html](http://gnuradio.4.n7.nabble.com/help-accessing-fft-bins-in-python-script-tp50854p50891.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [October 17, 2014, 6:03pm UTC](https://www.ruby-forum.com/t/help-accessing-fft-bins-in-python-script/232586/9 "2014-10-17T18:03:22Z")

</div>

This sounds interesting - do you have any sample code?

Can anybody explain the concept of “size” of an fft (Arg 1 of fft .  
fft\_vcc ) comes into play if the output of that FFT generates as many  
samples as it receives?

----- Original Message -----

From: “John M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “Brad H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Cc: “Martin B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Friday, October 17, 2014 1:50:31 AM  
Subject: Re: [Discuss-gnuradio] help accessing fft bins in python script

Sometimes when I want to grab samples and perform some periodic  
operation like CNR estimation, or fine-frequency estimation I sometimes  
use a vector\_sink, and then two function probe blocks - one to read the  
data and one to reset it (yes I call the reset function from the  
function probe). This seems to work wonderfully for certain corner cases  
where a vector sink doesn’t work well. And I mostly use this technique  
when I want to prototyping something quickly before writing a block. But  
am I asking for trouble with memory allocation issues???

Also, I was thinking, it would be good to have the option, either a  
block parameter or an overloaded function) to reset the vector\_sink,  
each time .data() is called… I can code this up unless anyone thinks  
this functionality would lead to regressions.

But I agree the vector sink block is much more convenient for FFTs…

-John

On Thu, Oct 16, 2014 at 5:37 PM, Brad H. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \> wrote:

Is there any way to access the fft bins from python without writing a  
custom block?

From: “Martin B.” \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Thursday, October 16, 2014 2:02:03 PM  
Subject: Re: [Discuss-gnuradio] help accessing fft bins in python script

A very simple way would just be to write your block downstream of the  
FFT in Python. You can then operate on the vectors in the work function.

M

On 10/16/2014 07:44 PM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and then leverage the dependency-tree evaluator to have my own
> 
> > however because when I review the vector sink’s data() method, it

[http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/master/entry/gr-fft/python/fft/qa\_fft.py](http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/master/entry/gr-fft/python/fft/qa_fft.py)

> > [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)
> 
> * * *
> 
> 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)

* * *

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)**

* * *

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)**
