discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Need help to understand code of sync:decimator bl


From: Marcus Müller
Subject: Re: [Discuss-gnuradio] Need help to understand code of sync:decimator block
Date: Sat, 08 Mar 2014 12:24:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sorry I was unclear: "5 inputs" means "5input items from the same
(only one) input stream".
Now, Miklos is most probably very right, the GNU Radio filters are
highly optimized. But let's take this as an exercise in understanding
decimators:

A decimator is just a normal block that "knows" that for every N input
items, it produces 1 output item. So if you produce but 1 output, GNU
Radio will now that you've seen input 0...4, and you will be presented
with 5...9 next time.

You're work's for loop does something like a moving average for *each*
input item, so that's what's wrong with it.
So, as I said: just drop the set_history call, and change your for
loop like following and your block should work:

for(int i = 0; i/5 < noutput_items; i += 5)
 out[i / 5] = (in[i]+ in[i+1]...+in[i+4]) / 5.0f;
return i/5;

Greetings,
Marcus


On 08.03.2014 12:03, kunal sankhe wrote:
> Hello Marcus,
> 
> Sorry for my vague explanation. I want to write a block which will 
> calculate moving average for a block of samples. I have only one
> input in this case. I am providing my data serially using vector to
> stream converter. I want to calculate average of a block of 5
> samples.
> 
> eg. from vector source {1,2,3,4,5,6,7,8,9,10}, i will get stream
> of integers.
> 
> Now I want to calculate average for first 5 samples i.e. 3 and then
> it should calculate average of {6,7,8,9,10} which is 8. So i should
> get desired output as {3,8}.
> 
> So I should get output for a block containing 5 samples. It should
> again consider block of 5 next samples and calculate average.
> 
> Please let me what changes do I need to make.
> 
> Thanks, Kunal
> 
> 
> On Sat, Mar 8, 2014 at 3:23 PM, Marcus Müller <address@hidden>
> wrote:
> 
> Hello Kunal,
> 
> You don't want to use set_history in this case:  you want to
> produce 1 output for 5 input, so you use a decimator; that's all
> you need to do. Drop the set_history. For reference: history is
> when for every input item you need the last 5 items before, 
> http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules#set_history
>
> 
Greetings,
> Marcus
>> 
>> 
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTGv3kAAoJEBQ6EdjyzlHtEXkH/i3Z8NnM9sQP3lZLFRU7SEsT
NedPJD7hcCGVlDUY16h7fdtuweHesDIP51vzrLJfmbC/swRS2gWhps5KrY7w8+vq
LwHZjBNSa1tBZ5e0OlrW+mCv2PXlrbC0kGOdMSnyoptWNVm8NNJgTw3VxVKHpWFK
FEpBfaIdoNt873qZdWnSxaCDeusrdeIDmNiE68bGwRd3solH4CSQe4Dve7Q7N45a
wEUn9UhHk/jOKRZ9hEqDM/sF1Bp2JL2zmZOj46YT82tvFjGNpFyftu2wei/LByst
/s0n8h8w0l0TjkEIE7ehIwYIEzBtuUv7Op8ePrDtKEBRy7BBcw/25e8ChlOKe1U=
=HpzM
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]