Signal Source: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(Waveform types: better structure)
 
(28 intermediate revisions by 3 users not shown)
Line 8: Line 8:


; Sample Rate (''R'')
; Sample Rate (''R'')
: default: samp_rate
: Default value: samp_rate
: Sample rate (fs) is the average number of samples obtained in one second. Its units are samples per second or hertz e.g. 48,000 sample rate is 48 kHz.


; Waveform (''R'')
; Waveform (''R'')
: options: [Constant, Sine, Cosine, Square, Triangle, Saw Tooth]
: options: [Constant, Sine, Cosine, Square, Triangle, Saw Tooth]
: For selection with a variable, the following values should be used:
: Description: see "Waveform Types" below
    constant = 100
    sine = 101
    cosine = 102
    square = 103
    triangle = 104
    sawtooth = 105


; Frequency (''R'')
; Frequency (''R'')
: frequency of the waveform (default: 1000)
: Frequency of the waveform (default: 1000)


; Amplitude (''R'')
; Amplitude (''R'')
: amplitude of the output (default: 1)
: Amplitude of the output (default: 1)


; Offset (''R'')
; Offset (''R'')
: offset from zero (default: 0)
: Offset from zero (default: 0)


; Initial Phase (Radians) (''R'')
; Initial Phase (Radians) (''R'')
: default: 0
: Default: 0


== Messages ==
== Waveform Types ==  
; Constant
: A constant value as specified by ''Amplitude'' + ''Offset''
; Sine
: Real-valued signal types: ''Amplitude''·sin(2π·''Frequency''/''Sample Rate''·n) + ''Offset''
: Complex-valued signal types: ''Amplitude''·[cos(2π·''Frequency''/''Sample Rate''·n) + 1j·sin(2π·''Frequency''/''Sample Rate''·n)] + ''Offset''
; Cos
: Real-valued signal types: ''Amplitude''·cos(2π·''Frequency''/''Sample Rate''·n) + ''Offset''
: Complex-valued signal types (identical to Sin): ''Amplitude''·cos(2π·''Frequency''/''Sample Rate''·n) + 1j·sin(2π·''Frequency''/''Sample Rate''·n) + ''Offset''
; Square (Phase wraps in [–π,+π], increasing by ''Frequency''/''Sample Rate'' every sample)
: Real-valued signal types:
:: phase < 0: ''Amplitude''+''Offset''
:: phase &ge; 0: ''Offset''
: Complex-valued signal types (Real part: 0-centered π-wide square wave, Imag leads Real by 90°):
:: phase in [-π, -π/2): ''Amplitude'' + 0j + ''Offset''
:: phase in [-π/2,  0): ''Amplitude'' + 1j·''Amplitude'' + ''Offset''
:: phase in [ 0, +π/2): 0 + 1j·''Amplitude'' + ''Offset''
:: phase in [+π/2, +π): 0 + 0j + ''Offset''
; Triangle (Phase wraps in [–π,+π], increasing by ''Frequency''/''Sample Rate'' every sample)
: Real-valued signal types:
:: Phase in [-π, 0): Linear ramp from -''Amplitude'' to +''Amplitude'' (both + ''Offset'')
:: Phase in [0, +π): Linear ramp from +''Amplitude'' to -''Amplitude'' (both + ''Offset'')
: Complex-valued signal types (Real part: triangle wave, rising in [-π,0), falling [0,+π), Imag leads Real by 90°):
:: phase in [-π, -π/2): TODO
:: phase in [-π/2,  0): TODO
:: phase in [ 0, +π/2): TODO
:: phase in [+π/2, +π): TODO
; Sawtooth (Phase wraps in [–π,+π], increasing by ''Frequency''/''Sample Rate'' every sample)
: Real-valued signal types (Rises from -π to +π, then jumps back to -π):
:: ''Amplitude''·phase / (2π) + ''Amplitude''/2 + ''Offset''
: Complex-valued signal types (TODO)


The 'freq' message port has been <code>deprecated in 3.9</code> in favor of the 'cmd' message port.


The 'cmd' message port accepts message pairs.
; For selection with a variable, the following values should be used:
* 'freq' . float value
: Constant: <code>analog.GR_CONST_WAVE</code>
* 'ampl' . float value
: Sine: <code>analog.GR_SIN_WAVE</code>
* 'phase' . float value
: Cosine: <code>analog.GR_COS_WAVE</code>
* 'offset' . float value
: Square: <code>analog.GR_SQR_WAVE</code>
: Triangle: <code>analog.GR_TRI_WAVE</code>
: Sawtooth: <code>analog.GR_SAW_WAVE</code>
 
== Message Ports ==
 
; cmd
: The 'cmd' message port accepts message [https://wiki.gnuradio.org/index.php/Polymorphic_Types_(PMTs)#Pairs pairs].
:*'freq' . float value
:*'ampl' . float value
:*'phase' . float value
:*'offset' . float value
: For GNU Radio 3.8, the messages dont work correctly with pairs, but they do work fine with a dictionary. This issue is explained [https://github.com/gnuradio/gnuradio/issues/4239 here].
: The amplitude of the signal source can be changed to 0.5 by adding the following PMT to the message strobe block.
: <syntaxhighlight lang="python">
pmt.dict_add(pmt.make_dict(), pmt.intern("ampl"), pmt.from_double(0.5))
</syntaxhighlight>
: The above command creates a dictionary and adds a pmt pair of ("ampl", 0.5) to the dictionary.
 
; freq
: The value of frequency in the signal source can be changed by connecting a message strobe. The Message PMT parameter can be set to '''pmt.from_float(new_freq)'''. In this way, the frequency of the signal source will be changed to new_freq value after the specified period in the message strobe.
 
: The 'freq' message port has been <code>deprecated in 3.9</code> in favor of the 'cmd' message port.


== Example Flowgraph ==
== Example Flowgraph ==
Line 75: Line 121:


; C++ files
; C++ files
: [https://github.com/gnuradio/gnuradio TODO]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/lib/sig_source_impl.cc sig_source_impl.cc]


; Header files
; Header files
: [https://github.com/gnuradio/gnuradio TODO]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/lib/sig_source_impl.h sig_source_impl.h]


; Public header files
; Public header files
: [https://github.com/gnuradio/gnuradio TODO]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/include/gnuradio/analog/sig_source.h Base]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/include/gnuradio/analog/sig_source_waveform.h Waveforms]


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

Latest revision as of 19:08, 8 August 2022

Signal generator: generates a variety of waveforms.

Supports an output of type complex, float, int, and short

Parameters

(R): Run-time adjustable

Sample Rate (R)
Default value: samp_rate
Sample rate (fs) is the average number of samples obtained in one second. Its units are samples per second or hertz e.g. 48,000 sample rate is 48 kHz.
Waveform (R)
options: [Constant, Sine, Cosine, Square, Triangle, Saw Tooth]
Description: see "Waveform Types" below
Frequency (R)
Frequency of the waveform (default: 1000)
Amplitude (R)
Amplitude of the output (default: 1)
Offset (R)
Offset from zero (default: 0)
Initial Phase (Radians) (R)
Default: 0

Waveform Types

Constant
A constant value as specified by Amplitude + Offset
Sine
Real-valued signal types: Amplitude·sin(2π·Frequency/Sample Rate·n) + Offset
Complex-valued signal types: Amplitude·[cos(2π·Frequency/Sample Rate·n) + 1j·sin(2π·Frequency/Sample Rate·n)] + Offset
Cos
Real-valued signal types: Amplitude·cos(2π·Frequency/Sample Rate·n) + Offset
Complex-valued signal types (identical to Sin): Amplitude·cos(2π·Frequency/Sample Rate·n) + 1j·sin(2π·Frequency/Sample Rate·n) + Offset
Square (Phase wraps in [–π,+π], increasing by Frequency/Sample Rate every sample)
Real-valued signal types:
phase < 0: Amplitude+Offset
phase ≥ 0: Offset
Complex-valued signal types (Real part: 0-centered π-wide square wave, Imag leads Real by 90°):
phase in [-π, -π/2): Amplitude + 0j + Offset
phase in [-π/2, 0): Amplitude + 1j·Amplitude + Offset
phase in [ 0, +π/2): 0 + 1j·Amplitude + Offset
phase in [+π/2, +π): 0 + 0j + Offset
Triangle (Phase wraps in [–π,+π], increasing by Frequency/Sample Rate every sample)
Real-valued signal types:
Phase in [-π, 0): Linear ramp from -Amplitude to +Amplitude (both + Offset)
Phase in [0, +π): Linear ramp from +Amplitude to -Amplitude (both + Offset)
Complex-valued signal types (Real part: triangle wave, rising in [-π,0), falling [0,+π), Imag leads Real by 90°):
phase in [-π, -π/2): TODO
phase in [-π/2, 0): TODO
phase in [ 0, +π/2): TODO
phase in [+π/2, +π): TODO
Sawtooth (Phase wraps in [–π,+π], increasing by Frequency/Sample Rate every sample)
Real-valued signal types (Rises from -π to +π, then jumps back to -π):
Amplitude·phase / (2π) + Amplitude/2 + Offset
Complex-valued signal types (TODO)


For selection with a variable, the following values should be used
Constant: analog.GR_CONST_WAVE
Sine: analog.GR_SIN_WAVE
Cosine: analog.GR_COS_WAVE
Square: analog.GR_SQR_WAVE
Triangle: analog.GR_TRI_WAVE
Sawtooth: analog.GR_SAW_WAVE

Message Ports

cmd
The 'cmd' message port accepts message pairs.
  • 'freq' . float value
  • 'ampl' . float value
  • 'phase' . float value
  • 'offset' . float value
For GNU Radio 3.8, the messages dont work correctly with pairs, but they do work fine with a dictionary. This issue is explained here.
The amplitude of the signal source can be changed to 0.5 by adding the following PMT to the message strobe block.
 pmt.dict_add(pmt.make_dict(), pmt.intern("ampl"), pmt.from_double(0.5))
The above command creates a dictionary and adds a pmt pair of ("ampl", 0.5) to the dictionary.
freq
The value of frequency in the signal source can be changed by connecting a message strobe. The Message PMT parameter can be set to pmt.from_float(new_freq). In this way, the frequency of the signal source will be changed to new_freq value after the specified period in the message strobe.
The 'freq' message port has been deprecated in 3.9 in favor of the 'cmd' message port.

Example Flowgraph

This flowgraph is for version 3.9+.

Signal-source-ex.png

Example Output

Types of Waveforms:

Cosine (complex):

Signal-source-cosine.png

Constant:

Signal-source-constant.png

Square:

Signal-source-square.png

Triangle:

Signal-source-triangle.png

Sawtooth:

Signal-source-sawtooth.png

Source Files

C++ files
sig_source_impl.cc
Header files
sig_source_impl.h
Public header files
Base
Waveforms
Block definition
analog_sig_source_x.block.yml