[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] How to extract part of a vector in GNURadio Compa
From: |
CEL |
Subject: |
Re: [Discuss-gnuradio] How to extract part of a vector in GNURadio Companion? |
Date: |
Tue, 30 Jan 2018 17:15:28 +0000 |
Hi Kokosz, Hi Jeff!
I really like Jeff's approach, as it's very "GNU Radio stylish"!
Another flexible way of doing this would be to simply write a python
block – and that's super easy if you just use the "Python Block" in
GRC; you just set the "in_sig" in the file that opens when you click on
"Open in Editor" to something like [(np.complex,1024)], and the out_sig
to something that makes sense to your application, like [np.float32] if
you just want to output one mean power value per input vector, or
[(np.float32, 100)] when you want to produce one output vector of 100
real values per input vector.
Then, you write your "math" in the work method below; notice that you
need to write to the *elements* of the first output, so
"output_items[0][:]" is the right thing to assign to.
I'm including a simple "give me the mean of element 113 through 250"
block below.
Best regards,
Marcus
class blk(gr.sync_block):
def __init__(self, scale = 1.0): # only default arguments here
gr.sync_block.__init__(
self,
name='Vector partial mean',
in_sig=[(np.complex64, 1024)],
out_sig=[np.complex64]
)
self.scale = scale
def work(self, input_items, output_items):
output_items[0][0] = input_items[0][0][112:250].mean() *
self.scale
return 1 #we've produced exactly one item of output,so return 1
On Tue, 2018-01-30 at 11:23 -0500, Jeff Long wrote:
> Reading this again, you're probably looking to continuously extract a
> slice from a vector type, not a vector sink as I first read it.
>
> Ah, there is an efficient way. Convert vector-to-stream, use keep-m-in-n
> with an offset, and convert back to a vector. Hope that works.
>
>
> On 01/30/2018 11:06 AM, Jeff Long wrote:
> > Flowgraphs aren't procedural, so you can't say "run, then extract". But
> > you can build a flowgraph in GRC, import/run it from a small Python
> > program, and then extract a slice of the vector.
> >
> > On 01/30/2018 10:44 AM, kokosz wrote:
> > > Dear all,
> > >
> > > Is there any way to extract just some part of a vector in GNURadio
> > > Companion for further processing?
> > >
> > > For example, FFT block returns a vector of, say, 1024 complex points
> > > in frequency domain, but I want to extract just some of them (e.g.
> > > points no. 113-250) and then process them (e.g. convert to stream and
> > > calculate their average value etc).
> > >
> > >
> > > _______________________________________________
> > > Discuss-gnuradio mailing list
> > > address@hidden
> > > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
> > >
>
> _______________________________________________
> Discuss-gnuradio mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
smime.p7s
Description: S/MIME cryptographic signature