Signal Source: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Signal generator, generates a variety of signals. Supports an output of type complex, float, int, and short Args: * Sample Rate : Sampling rate of signal * Waveform : wavefo...") |
(Waveform types: better structure) |
||
(39 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
Signal generator | [[Category:Block Docs]] | ||
Signal generator: generates a variety of waveforms. | |||
Supports an output of type complex, float, int, and short | Supports an output of type complex, float, int, and short | ||
== Parameters == | |||
<b>(''R''):</b> <span class="plainlinks">[https://wiki.gnuradio.org/index.php/GNURadioCompanion#Variable_Controls ''Run-time adjustable'']</span> | |||
; 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: <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 == | |||
; 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 == | |||
This flowgraph is for version 3.9+. | |||
[[File:Signal-source-ex.png]] | |||
== Example Output == | |||
Types of Waveforms: | |||
Cosine (complex): | |||
[[File:Signal-source-cosine.png|600px]] | |||
Constant: | |||
[[File:Signal-source-constant.png|600px]] | |||
Square: | |||
[[File:Signal-source-square.png|600px]] | |||
Triangle: | |||
[[File:Signal-source-triangle.png|600px]] | |||
Sawtooth: | |||
[[File:Signal-source-sawtooth.png|600px]] | |||
== Source Files == | |||
; C++ files | |||
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/lib/sig_source_impl.cc sig_source_impl.cc] | |||
; Header files | |||
: [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/lib/sig_source_impl.h sig_source_impl.h] | |||
; Public header files | |||
: [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 | |||
: [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+.
Example Output
Types of Waveforms:
Cosine (complex):
Constant:
Square:
Triangle:
Sawtooth:
Source Files
- C++ files
- sig_source_impl.cc
- Header files
- sig_source_impl.h
- Block definition
- analog_sig_source_x.block.yml