how to insert if...else logic between 2 blocks

2020-12-04 Thread james jordan
Hi ALL,
i want to compute process a block's output then pass the result to another 
block's input. the process is not a fix equation but like this if(output > 
a)... else... so is there any way to do this without making a new block by 
myself. can i modify the generated python code to insert this logic? if i have 
to make a new block then how to make?





Re: how to insert if...else logic between 2 blocks

2020-12-04 Thread Fabian Schwartau
Hi James,

three options I can see:
1) Quick& Dirty: Implement both algorithms in parallel and use the Peak
Detector block to generate a 0 or 1 depending on your condition. Then
invert the condition, multiply the outputs of the two algorithms with
the two condition outputs and add them.
2) Depending on your condition and what you want to do, the Python
Module block may help. You can implement python function in it and use
them anywhere in your flow chart:
https://wiki.gnuradio.org/index.php/Python_Module
3) Build your own module:
https://wiki.gnuradio.org/index.php/OutOfTreeModules

Best regards,
Fabian

Am 04.12.20 um 10:36 schrieb james jordan:
> Hi ALL,
> i want to compute process a block's output then pass the result to
> another block's input. the process is not a fix equation but like this
> if(output > a)... else... so is there any way to do this without making
> a new block by myself. can i modify the generated python code to insert
> this logic? if i have to make a new block then how to make?
> 
> 
> 




Re: how to insert if...else logic between 2 blocks

2020-12-04 Thread Fabian Schwartau
Hi James,
I cannot tell where you got that init function from, but you are passing
3 arguments to it (ignoring self). The first one has a default argument
(1850e6), but the following don't. That's not allowed in python. If you
want to give a default parameter for the center_freq, put the parameter
at the end:
def __init__(self, fft_size, freq_range, center_freq=1850e6):
or give default values for all parameters:
def __init__(self, center_freq=1850e6, fft_size=1024, freq_range=10e6):

I don't know if it is common (possble) to have an __init__ function in a
"Python Module". I used it just to define a single function, just like
in the example from the wiki.

Hope that helps, I am not a GNU Radio expert, especially on those more
advanced topics like building your own modules.

Best regards,
Fabian

Am 04.12.20 um 14:18 schrieb james jordan:
> Hi Fabian,
> thanks for your quick reply. i think python block is a good choice but
> how to define the block param as what i want? i only see there is a
> example param in the block. when i modify the code as below
> def __init__(self, center_freq=1850e6, fft_size, freq_range):
> grc can not interpret the source code. it shows "Param -
> Code(_source_code): Can't interpret source code: non-default argument
> follows default argument (, line 16)"
> how to deal with this?
> 
> 
> 
> 
> *From:* Discuss-gnuradio
>  on
> behalf of Fabian Schwartau 
> *Sent:* Friday, December 4, 2020 7:14 PM
> *To:* discuss-gnuradio@gnu.org 
> *Subject:* Re: how to insert if...else logic between 2 blocks
>  
> Hi James,
> 
> three options I can see:
> 1) Quick& Dirty: Implement both algorithms in parallel and use the Peak
> Detector block to generate a 0 or 1 depending on your condition. Then
> invert the condition, multiply the outputs of the two algorithms with
> the two condition outputs and add them.
> 2) Depending on your condition and what you want to do, the Python
> Module block may help. You can implement python function in it and use
> them anywhere in your flow chart:
> https://wiki.gnuradio.org/index.php/Python_Module
> 3) Build your own module:
> https://wiki.gnuradio.org/index.php/OutOfTreeModules
> 
> Best regards,
> Fabian
> 
> Am 04.12.20 um 10:36 schrieb james jordan:
>> Hi ALL,
>> i want to compute process a block's output then pass the result to
>> another block's input. the process is not a fix equation but like this
>> if(output > a)... else... so is there any way to do this without making
>> a new block by myself. can i modify the generated python code to insert
>> this logic? if i have to make a new block then how to make?
>> 
>> 
>> 
> 
> 




Re: how to insert if...else logic between 2 blocks

2020-12-04 Thread james jordan
Hi Fabian,
thanks for your quick reply. i think python block is a good choice but how to 
define the block param as what i want? i only see there is a example param in 
the block. when i modify the code as below
def __init__(self, center_freq=1850e6, fft_size, freq_range):
grc can not interpret the source code. it shows "Param - Code(_source_code): 
Can't interpret source code: non-default argument follows default argument 
(, line 16)"
how to deal with this?




From: Discuss-gnuradio 
 on behalf of 
Fabian Schwartau 
Sent: Friday, December 4, 2020 7:14 PM
To: discuss-gnuradio@gnu.org 
Subject: Re: how to insert if...else logic between 2 blocks

Hi James,

three options I can see:
1) Quick& Dirty: Implement both algorithms in parallel and use the Peak
Detector block to generate a 0 or 1 depending on your condition. Then
invert the condition, multiply the outputs of the two algorithms with
the two condition outputs and add them.
2) Depending on your condition and what you want to do, the Python
Module block may help. You can implement python function in it and use
them anywhere in your flow chart:
https://wiki.gnuradio.org/index.php/Python_Module
3) Build your own module:
https://wiki.gnuradio.org/index.php/OutOfTreeModules

Best regards,
Fabian

Am 04.12.20 um 10:36 schrieb james jordan:
> Hi ALL,
> i want to compute process a block's output then pass the result to
> another block's input. the process is not a fix equation but like this
> if(output > a)... else... so is there any way to do this without making
> a new block by myself. can i modify the generated python code to insert
> this logic? if i have to make a new block then how to make?
>
>
> 




Re: Post on Gnu Radio Companion filtering

2020-12-04 Thread Gary Schafer

"When responding to a thread from Discuss Gnuradio, be sure to include it as a CC or 
'Reply All'."

Yup. When I received the daily digest today, I realized my mistake. My bad. 
(*waves at everyone*)

Thanks, Barry!

On 12/4/20 4:27 PM, Barry Duggan wrote:

Hi Gary,

Thank you for your correction. We have updated 
https://wiki.gnuradio.org/index.php/Quadrature_Demod and fixed the math 
rendering as well :)

Also I have added your FM posts to 
https://wiki.gnuradio.org/index.php/SuggestedReading#GNU_Radio_Specific

You may be interested in https://pysdr.org/ in reference to your creating 
filters using Python code.

Cheers!
---
Barry Duggan KV4FV
https://github.com/duggabe

P.S. When responding to a thread from Discuss Gnuradio, be sure to include it 
as a CC or 'Reply All'.

On 12/3/20 8:22 PM, Gary Schafer wrote:

Hi, Barry! (*waves*)

That's great! Glad to help where I can! Can't tell you how much I appreciate 
GRC. I'm actually working on a SDR class based on it.

With respect to the quad demod block documentation, the *text* that says, "the one-sample delayed 
input and the conjugate undelayed signal", should read "the one-sample 
delayed-&-conjugated input and the undelayed input signal". The delayed sample is also the one 
that is conjugated.

FYI, the Tex code is correct.

I was working on demodding NOAA APT signals for my next post (cuz that is a fun one) 
followed by a post on creating filters using Python code (the "tap" blocks). Do 
you have suggestions for other posts?

Regards,

Gary

On 12/3/20 9:00 PM, Barry Duggan wrote:

Hi Gary,

You have some very interesting material there! I plan to include it in our 
https://wiki.gnuradio.org/index.php/SuggestedReading list.

In reference to the https://wiki.gnuradio.org/index.php/Quadrature_Demod block, 
what part do you think needs correcting? I work on the GNU Radio documentation 
and would like to make sure things are stated correctly.

Thanks,




Re: Post on Gnu Radio Companion filtering

2020-12-04 Thread Barry Duggan

Hi Gary,

Thank you for your correction. We have updated 
https://wiki.gnuradio.org/index.php/Quadrature_Demod and fixed the math 
rendering as well :)


Also I have added your FM posts to 
https://wiki.gnuradio.org/index.php/SuggestedReading#GNU_Radio_Specific


You may be interested in https://pysdr.org/ in reference to your 
creating filters using Python code.


Cheers!
---
Barry Duggan KV4FV
https://github.com/duggabe

P.S. When responding to a thread from Discuss Gnuradio, be sure to 
include it as a CC or 'Reply All'.


On 12/3/20 8:22 PM, Gary Schafer wrote:

Hi, Barry! (*waves*)

That's great! Glad to help where I can! Can't tell you how much I 
appreciate GRC. I'm actually working on a SDR class based on it.


With respect to the quad demod block documentation, the *text* that 
says, "the one-sample delayed input and the conjugate undelayed signal", 
should read "the one-sample delayed-&-conjugated input and the undelayed 
input signal". The delayed sample is also the one that is conjugated.


FYI, the Tex code is correct.

I was working on demodding NOAA APT signals for my next post (cuz that 
is a fun one) followed by a post on creating filters using Python code 
(the "tap" blocks). Do you have suggestions for other posts?


Regards,

Gary

On 12/3/20 9:00 PM, Barry Duggan wrote:

Hi Gary,

You have some very interesting material there! I plan to include it in 
our https://wiki.gnuradio.org/index.php/SuggestedReading list.


In reference to the 
https://wiki.gnuradio.org/index.php/Quadrature_Demod block, what part 
do you think needs correcting? I work on the GNU Radio documentation 
and would like to make sure things are stated correctly.


Thanks,




Re: how to insert if...else logic between 2 blocks

2020-12-04 Thread james jordan
Hi  Fabian,
thanks for your help. i write a fft index to freq transform block. i put the 
source here for anyone need.






From: Discuss-gnuradio 
 on behalf of 
Fabian Schwartau 
Sent: Friday, December 4, 2020 9:28 PM
To: discuss-gnuradio@gnu.org 
Subject: Re: how to insert if...else logic between 2 blocks

Hi James,
I cannot tell where you got that init function from, but you are passing
3 arguments to it (ignoring self). The first one has a default argument
(1850e6), but the following don't. That's not allowed in python. If you
want to give a default parameter for the center_freq, put the parameter
at the end:
def __init__(self, fft_size, freq_range, center_freq=1850e6):
or give default values for all parameters:
def __init__(self, center_freq=1850e6, fft_size=1024, freq_range=10e6):

I don't know if it is common (possble) to have an __init__ function in a
"Python Module". I used it just to define a single function, just like
in the example from the wiki.

Hope that helps, I am not a GNU Radio expert, especially on those more
advanced topics like building your own modules.

Best regards,
Fabian

Am 04.12.20 um 14:18 schrieb james jordan:
> Hi Fabian,
> thanks for your quick reply. i think python block is a good choice but
> how to define the block param as what i want? i only see there is a
> example param in the block. when i modify the code as below
> def __init__(self, center_freq=1850e6, fft_size, freq_range):
> grc can not interpret the source code. it shows "Param -
> Code(_source_code): Can't interpret source code: non-default argument
> follows default argument (, line 16)"
> how to deal with this?
>
>
> 
> 
> *From:* Discuss-gnuradio
>  on
> behalf of Fabian Schwartau 
> *Sent:* Friday, December 4, 2020 7:14 PM
> *To:* discuss-gnuradio@gnu.org 
> *Subject:* Re: how to insert if...else logic between 2 blocks
>
> Hi James,
>
> three options I can see:
> 1) Quick& Dirty: Implement both algorithms in parallel and use the Peak
> Detector block to generate a 0 or 1 depending on your condition. Then
> invert the condition, multiply the outputs of the two algorithms with
> the two condition outputs and add them.
> 2) Depending on your condition and what you want to do, the Python
> Module block may help. You can implement python function in it and use
> them anywhere in your flow chart:
> https://wiki.gnuradio.org/index.php/Python_Module
> 3) Build your own module:
> https://wiki.gnuradio.org/index.php/OutOfTreeModules
>
> Best regards,
> Fabian
>
> Am 04.12.20 um 10:36 schrieb james jordan:
>> Hi ALL,
>> i want to compute process a block's output then pass the result to
>> another block's input. the process is not a fix equation but like this
>> if(output > a)... else... so is there any way to do this without making
>> a new block by myself. can i modify the generated python code to insert
>> this logic? if i have to make a new block then how to make?
>>
>>
>> 
>
>


"""
Embedded Python Blocks:

Each time this file is saved, GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__  will
be the parameters. All of them are required to have default values!
"""

import numpy as np
from gnuradio import gr


class blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_block
"""Embedded Python Block example - a simple multiply const"""

def __init__(self, center_freq=1850e6, fft_size=1024, freq_range=5e6):  # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.sync_block.__init__(
self,
name='Embedded Python Block',   # will show up in GRC
in_sig=[np.short],
out_sig=[np.float32]
)
# if an attribute with the same name as a parameter is found,
# a callback is registered (properties work, too).
self.center_freq = center_freq
self.fft_size = fft_size
self.freq_range = freq_range

def work(self, input_items, output_items):
if (input_items[0] >= (self.fft_size/2)).all():
output_items[0][:] = (self.freq_range * (input_items[0] - self.fft_size/2) / self.fft_size + self.center_freq - self.freq_range/2) / 1e6
else:
output_items[0][:] = (self.freq_range * input_items[0] / self.fft_size + self.center_freq) / 1e6
return len(output_items[0])