Signal Source: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(Waveform types: better structure)
 
(9 intermediate revisions by 2 users not shown)
Line 13: Line 13:
; 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'')
Line 32: Line 26:
; Initial Phase (Radians) (''R'')
; Initial Phase (Radians) (''R'')
: Default: 0
: 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 &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)
; For selection with a variable, the following values should be used:
: Constant: <code>analog.GR_CONST_WAVE</code>
: Sine: <code>analog.GR_SIN_WAVE</code>
: Cosine: <code>analog.GR_COS_WAVE</code>
: Square: <code>analog.GR_SQR_WAVE</code>
: Triangle: <code>analog.GR_TRI_WAVE</code>
: Sawtooth: <code>analog.GR_SAW_WAVE</code>


== Message Ports ==
== Message Ports ==
Line 42: Line 77:
:*'offset' . 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].
: 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].
: For GNU Radio 3.8, the amplitude of the signal source can be changed to 0.5 by adding the following PMT to the message strobe block.
: 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))
: <syntaxhighlight lang="python">
This PMT creates a dictionary and adds a pmt pair of ("ampl", 0.5) to the dictionary.
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
; 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. In the following example, the frequency of the signal source is changed to 1kHz after 5 seconds.
: 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.  
: [[File:Message_strobe_settings.PNG | 400px]]
 
: [[File:Signal_source_freq_msg_port.PNG]]


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


; C++ files
; C++ files
: [https://github.com/gnuradio/gnuradio/blob/master/gr-analog/lib/sig_source_impl.cc]
: [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/blob/master/gr-analog/lib/sig_source_impl.h]
: [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/blob/master/gr-analog/include/gnuradio/analog/sig_source.h Base]
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/include/gnuradio/analog/sig_source.h Base]
: [https://github.com/gnuradio/gnuradio/blob/master/gr-analog/include/gnuradio/analog/sig_source_waveform.h Waveforms]
: [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/blob/master/gr-analog/grc/analog_sig_source_x.block.yml]
: [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