Float To Char: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(Created page with "Category:Block Docs Category:Stub Docs This is the template for the "Page-per-block Docs". This first section should describe what the block...")
 
m (Clarified the role of the 'Scale' value in the block.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Block Docs]]
[[Category:Block Docs]]
[[Category:Stub Docs]]
This block will convert a stream of signed 32-bit floating point values (floats) to a stream of signed 8-bit integers (char), with an optional scaling factor. The ''Float to Char'' block will quantize the input values, after being multiplied by the ''Scale'' factor, to integer values between -128 to +127. Values are rounded to the nearest integer. Any values less than -128 or greater than +127 will be clipped to these limits.
This is the template for the [[:Category:Block_Docs|"Page-per-block Docs"]].  This first section should describe what the block does and how to use it, using however many paragraphs necessary.  Note that the title of the wiki page should match the block's name in GRC, i.e. the one defined in the block's .grc file.  Look at the [[FFT]] Block for a good example.
 
As this is a basic template, it's also in the [[:Category:Stub_Docs|"Stub Docs category"]]. Please improve it.


== Parameters ==
== Parameters ==
(''R''): <span class="plainlinks">[https://wiki.gnuradio.org/index.php/GNURadioCompanion#Variable_Controls ''Run-time adjustable'']</span>
(''R''): <span class="plainlinks">[https://wiki.gnuradio.org/index.php/GNURadioCompanion#Variable_Controls ''Run-time adjustable'']</span>


; Param 1 (''R'')
; Scale (''R'')
: Description of parameter, provide any tips or recommended values. Note that the name of the parameter above should match the param's label that shows up in grc (e.g. Sample Rate).
: Scaling factor applied to input stream.
 
== Example Flowgraph ==
 
An example flowgraph showing the affect that the ''Float to Char'' block has on an input signal.


; Param 2
[[File:Float-to-Char-flowgraph.png|800px]]
: blah blah blah


== Example Flowgraph ==
The [[Signal Source]] block provides a sinusoid with an amplitude of 1. Using a ''Scale'' value of the ''Float to Char'' block of 1, the input signal will be quantized to values of -1, 0, and 1. Note that the input is multiplied by the ''Scale'' value before being quantized into the ''char'' data type.
 
[[File:Float-to-Char-scale-1.png|800px]]
 
Using a ''Scale'' value of 127 for the ''Float to Char'', and 1 for the ''Char to Float'', the sinusoid looks more natural.
 
[[File:Float-to-Char-scale-127.png|800px]]
 
However, zooming in on the sinusoid that has passed through the ''Float to Char'' shows that the amplitudes have been quantized to integer values.
 
[[File:Float-to-Char-scale-127-1-zoomed.png|800px]]
 
If the amplitude of the input signal is higher than 127 or less than -128, the signal amplitudes will be clipped at these limits. For example, here's an example using a ''Scale'' value of 150 for the ''Float to Char'' block.


Insert description of flowgraph here, then show a screenshot of the flowgraph and the output if there is an interesting GUI.  Currently we have no standard method of uploading the actual flowgraph to the wiki or git repo, unfortunately.  The plan is to have an example flowgraph showing how the block might be used, for every block, and the flowgraphs will live in the git repo.
[[File:Float-to-Char-scale-150-1.png|800px]]


== Source Files ==
== Source Files ==


; C++ fileshttps://wiki.gnuradio.org/index.php/SISO
; C++ files
 
: [https://github.com/gnuradio/gnuradio/blob/main/gr-blocks/lib/float_to_char_impl.cc float_to_char_impl.cc]
: [https://github.com/gnuradio/gnuradio TODO]


; Header files
; Header files
: [https://github.com/gnuradio/gnuradio TODO]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-blocks/lib/float_to_char_impl.h float_to_char_impl.h]
 
; Public header files
: [https://github.com/gnuradio/gnuradio TODO]


; Block definition
; Block Definition
: [https://github.com/gnuradio/gnuradio TODO]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-blocks/grc/blocks_float_to_char.block.yml blocks_float_to_char.block.yml]

Latest revision as of 02:12, 23 March 2025

This block will convert a stream of signed 32-bit floating point values (floats) to a stream of signed 8-bit integers (char), with an optional scaling factor. The Float to Char block will quantize the input values, after being multiplied by the Scale factor, to integer values between -128 to +127. Values are rounded to the nearest integer. Any values less than -128 or greater than +127 will be clipped to these limits.

Parameters

(R): Run-time adjustable

Scale (R)
Scaling factor applied to input stream.

Example Flowgraph

An example flowgraph showing the affect that the Float to Char block has on an input signal.

Float-to-Char-flowgraph.png

The Signal Source block provides a sinusoid with an amplitude of 1. Using a Scale value of the Float to Char block of 1, the input signal will be quantized to values of -1, 0, and 1. Note that the input is multiplied by the Scale value before being quantized into the char data type.

Float-to-Char-scale-1.png

Using a Scale value of 127 for the Float to Char, and 1 for the Char to Float, the sinusoid looks more natural.

Float-to-Char-scale-127.png

However, zooming in on the sinusoid that has passed through the Float to Char shows that the amplitudes have been quantized to integer values.

Float-to-Char-scale-127-1-zoomed.png

If the amplitude of the input signal is higher than 127 or less than -128, the signal amplitudes will be clipped at these limits. For example, here's an example using a Scale value of 150 for the Float to Char block.

Float-to-Char-scale-150-1.png

Source Files

C++ files
float_to_char_impl.cc
Header files
float_to_char_impl.h
Block Definition
blocks_float_to_char.block.yml