summaryrefslogtreecommitdiff
path: root/gr-blocks/grc
diff options
context:
space:
mode:
authorghostop14 <ghostop14@gmail.com>2020-02-15 18:07:35 -0500
committerMichael Dickens <michael.dickens@ettus.com>2020-02-20 09:08:11 -0500
commit458414c7b2ab93fa1a6d130fa64d907dd9fca5f0 (patch)
tree95d0b94f17c4a5396756150558b922e0a240fb01 /gr-blocks/grc
parent5cd7b4cd472e9dca41f19e2cdfed4393374c9fe0 (diff)
gr-blocks: Add scaling option to Complex to/from ishort and ichar
The existing block combinations of complex-to-ichar/ichar-to-complex and complex-to-ishort/ishort-to-complex was not exposing a scale factor to the UI (it was hard-coded at 1.0) which prevented the blocks from being used with voltage-based inputs and outputs, for example a -127 to 127 byte input would be mapped directly to the same value as a float. The same was true in reverse and there were notes in the code about FIX clipping. Adding the scale factor provides a mechanism for the user to appropriately fix the clipping and scale the conversion correctly. Additional documentation was added to the block yml to provide guidance to users on how to appropriately select the scale factor for their use case, and the default value was set to 1.0 for backward compatibility.
Diffstat (limited to 'gr-blocks/grc')
-rw-r--r--gr-blocks/grc/blocks_complex_to_interleaved_char.block.yml18
-rw-r--r--gr-blocks/grc/blocks_complex_to_interleaved_short.block.yml24
-rw-r--r--gr-blocks/grc/blocks_interleaved_char_to_complex.block.yml16
-rw-r--r--gr-blocks/grc/blocks_interleaved_short_to_complex.block.yml17
4 files changed, 71 insertions, 4 deletions
diff --git a/gr-blocks/grc/blocks_complex_to_interleaved_char.block.yml b/gr-blocks/grc/blocks_complex_to_interleaved_char.block.yml
index 78a1da6e8b..84b85579a2 100644
--- a/gr-blocks/grc/blocks_complex_to_interleaved_char.block.yml
+++ b/gr-blocks/grc/blocks_complex_to_interleaved_char.block.yml
@@ -3,6 +3,10 @@ label: Complex To IChar
flags: [ python, cpp ]
parameters:
+- id: scale_factor
+ label: Scale Factor
+ dtype: float
+ default: '1.0'
- id: vector_output
label: Vector Output
dtype: enum
@@ -23,7 +27,7 @@ outputs:
templates:
imports: from gnuradio import blocks
- make: blocks.complex_to_interleaved_char(${vector_output})
+ make: blocks.complex_to_interleaved_char(${vector_output}, ${scale_factor})
cpp_templates:
includes: ['#include <gnuradio/blocks/complex_to_interleaved_char.h>']
@@ -33,4 +37,16 @@ cpp_templates:
'True': 'true'
'False': 'false'
+documentation: |-
+ This block converts a complex sample to interleaved IQ bytes.
+ The default scale factor is 1.0 for backward compatibility, however if
+ the outputs should be signed voltage style bytes (-127 to 127) the scale factor
+ should be set to 127.0 (SCHAR_MAX).
+
+ Also note that this block can inherently cause a loss of precision as it
+ maps the scaled inputs to integer outputs using an lrintf function. So
+ if you overlay a complex-to-ichar into a ichar-to-complex and overlay it
+ on the original signal, you can notice variation due to the integer
+ rounding.
+
file_format: 1
diff --git a/gr-blocks/grc/blocks_complex_to_interleaved_short.block.yml b/gr-blocks/grc/blocks_complex_to_interleaved_short.block.yml
index bd4a588aca..89739e8245 100644
--- a/gr-blocks/grc/blocks_complex_to_interleaved_short.block.yml
+++ b/gr-blocks/grc/blocks_complex_to_interleaved_short.block.yml
@@ -3,6 +3,10 @@ label: Complex To IShort
flags: [ python, cpp ]
parameters:
+- id: scale_factor
+ label: Scale Factor
+ dtype: float
+ default: '1.0'
- id: vector_output
label: Vector Output
dtype: enum
@@ -23,14 +27,32 @@ outputs:
templates:
imports: from gnuradio import blocks
- make: blocks.complex_to_interleaved_short(${vector_output})
+ make: blocks.complex_to_interleaved_short(${vector_output},${scale_factor})
+ callbacks:
+ - set_scale_factor(${scale_factor})
cpp_templates:
includes: ['#include <gnuradio/blocks/complex_to_interleaved_short.h>']
declarations: 'blocks::complex_to_interleaved_short::sptr ${id};'
make: 'this->${id} = blocks::complex_to_interleaved_short::make(${vector_output});'
+ callbacks:
+ - set_scale_factor(${scale_factor})
translations:
'True': 'true'
'False': 'false'
+documentation: |-
+ This block converts a complex sample to interleaved IQ 16-bit values.
+ The default scale factor is 1.0 for backward compatibility, however if
+ the outputs should be signed voltage style, some care needs to be taken
+ with the scale factor. For a 12-bit output (-2047 to 2047), the
+ scale factor should be 2047.0. For a full 16-bit output, the
+ scale factor should be 32767.0.
+
+ Also note that this block can inherently cause a loss of precision as it
+ maps the scaled inputs to integer outputs using an lrintf function. So
+ if you overlay a complex-to-ishort into a ishort-to-complex and overlay it
+ on the original signal, you can notice variation due to the integer
+ rounding.
+
file_format: 1
diff --git a/gr-blocks/grc/blocks_interleaved_char_to_complex.block.yml b/gr-blocks/grc/blocks_interleaved_char_to_complex.block.yml
index 39f747a981..46d01b79c3 100644
--- a/gr-blocks/grc/blocks_interleaved_char_to_complex.block.yml
+++ b/gr-blocks/grc/blocks_interleaved_char_to_complex.block.yml
@@ -3,6 +3,10 @@ label: IChar To Complex
flags: [ python, cpp ]
parameters:
+- id: scale_factor
+ label: Scale Factor
+ dtype: float
+ default: '1.0'
- id: vector_input
label: Vector Input
dtype: enum
@@ -23,14 +27,24 @@ outputs:
templates:
imports: from gnuradio import blocks
- make: blocks.interleaved_char_to_complex(${vector_input})
+ make: blocks.interleaved_char_to_complex(${vector_input},${scale_factor})
+ callbacks:
+ - set_scale_factor(${scale_factor})
cpp_templates:
includes: ['#include <gnuradio/blocks/interleaved_char_to_complex.h>']
declarations: 'blocks::interleaved_char_to_complex::sptr ${id};'
make: 'this->${id} = blocks::interleaved_char_to_complex::make(${vector_input});'
+ callbacks:
+ - set_scale_factor(${scale_factor})
translations:
'True': 'true'
'False': 'false'
+documentation: |-
+ This block converts interleaved IQ bytes to a float complex data type.
+ The default scale factor is 1.0 for backward compatibility, however if
+ the inputs are signed voltage style bytes (-127 to 127) the scale factor
+ should be set to 127.0 (SCHAR_MAX).
+
file_format: 1
diff --git a/gr-blocks/grc/blocks_interleaved_short_to_complex.block.yml b/gr-blocks/grc/blocks_interleaved_short_to_complex.block.yml
index f96960ad56..5904ed76b1 100644
--- a/gr-blocks/grc/blocks_interleaved_short_to_complex.block.yml
+++ b/gr-blocks/grc/blocks_interleaved_short_to_complex.block.yml
@@ -3,6 +3,10 @@ label: IShort To Complex
flags: [ python, cpp ]
parameters:
+- id: scale_factor
+ label: Scale Factor
+ dtype: float
+ default: '1.0'
- id: vector_input
label: Vector Input
dtype: enum
@@ -30,9 +34,10 @@ outputs:
templates:
imports: from gnuradio import blocks
- make: blocks.interleaved_short_to_complex(${vector_input}, ${swap})
+ make: blocks.interleaved_short_to_complex(${vector_input}, ${swap},${scale_factor})
callbacks:
- set_swap(${swap})
+ - set_scale_factor(${scale_factor})
cpp_templates:
includes: ['#include <gnuradio/blocks/interleaved_short_to_complex.h>']
@@ -40,8 +45,18 @@ cpp_templates:
make: 'this->${id} = blocks::interleaved_short_to_complex::make(${vector_input}, ${swap});'
callbacks:
- set_swap(${swap})
+ - set_scale_factor(${scale_factor})
translations:
'True': 'true'
'False': 'false'
+documentation: |-
+ This block converts interleaved 12/16-bit IQ samples to a float complex data
+ type. The default scale factor is 1.0 for backward compatibility, however if
+ the inputs are signed voltage style, some attention needs to be
+ paid to the scale factor to get the correct scaling. If the input is
+ 12-bit represented in a 16-bit number (-2047 to 2047), the scale factor
+ should be 2047.0. If the input is a full 16-bit sample (-32767 to 32767)
+ the scale factor should be set to 32767.0 (SHRT_MAX).
+
file_format: 1