mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-02-22 22:48:28 +00:00
Added different modulations in signal generator (#2492)
* Added DSB, AM 100% mod index and AM 50% mod index. Changed UI.
This commit is contained in:
parent
5bd208bca1
commit
520ad97f78
@ -44,9 +44,9 @@ SigGenView::~SigGenView() {
|
|||||||
|
|
||||||
void SigGenView::update_config() {
|
void SigGenView::update_config() {
|
||||||
if (checkbox_stop.value())
|
if (checkbox_stop.value())
|
||||||
baseband::set_siggen_config(transmitter_model.channel_bandwidth(), options_shape.selected_index_value(), field_stop.value());
|
baseband::set_siggen_config(transmitter_model.channel_bandwidth(), (options_mod.selected_index_value() << 4) + options_shape.selected_index_value(), field_stop.value());
|
||||||
else
|
else
|
||||||
baseband::set_siggen_config(transmitter_model.channel_bandwidth(), options_shape.selected_index_value(), 0);
|
baseband::set_siggen_config(transmitter_model.channel_bandwidth(), (options_mod.selected_index_value() << 4) + options_shape.selected_index_value(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SigGenView::update_tone() {
|
void SigGenView::update_tone() {
|
||||||
@ -78,6 +78,7 @@ SigGenView::SigGenView(
|
|||||||
baseband::run_image(portapack::spi_flash::image_tag_siggen);
|
baseband::run_image(portapack::spi_flash::image_tag_siggen);
|
||||||
|
|
||||||
add_children({&labels,
|
add_children({&labels,
|
||||||
|
&options_mod,
|
||||||
&options_shape,
|
&options_shape,
|
||||||
&text_shape,
|
&text_shape,
|
||||||
&symfield_tone,
|
&symfield_tone,
|
||||||
@ -87,22 +88,48 @@ SigGenView::SigGenView(
|
|||||||
&field_stop,
|
&field_stop,
|
||||||
&tx_view});
|
&tx_view});
|
||||||
|
|
||||||
symfield_tone.hidden(1); // At first launch , by default we are in CW Shape has NO MOD , we are not using Tone modulation.
|
symfield_tone.hidden(true); // At first launch , by default we are in CW: Shape ignored, we are not using Tone modulation.
|
||||||
|
options_shape.hidden(true);
|
||||||
|
text_shape.hidden(true);
|
||||||
symfield_tone.set_value(1000); // Default: 1000 Hz
|
symfield_tone.set_value(1000); // Default: 1000 Hz
|
||||||
options_shape.on_change = [this](size_t, OptionsField::value_t v) {
|
options_shape.on_change = [this](size_t, OptionsField::value_t v) {
|
||||||
text_shape.set(shape_strings[v]);
|
text_shape.set(shape_strings[v]);
|
||||||
if (auto_update)
|
if (auto_update)
|
||||||
update_config();
|
update_config();
|
||||||
if ((v == 0) || (v == 6)) { // In Shapes Options (CW & Pseudo Random Noise) we are not using Tone modulation freq.
|
|
||||||
symfield_tone.hidden(1);
|
if (v == 5) { // In Shape Pseudo Random Noise we are not using Tone modulation freq.
|
||||||
|
symfield_tone.hidden(true);
|
||||||
} else {
|
} else {
|
||||||
symfield_tone.hidden(0);
|
symfield_tone.hidden(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_dirty();
|
set_dirty();
|
||||||
};
|
};
|
||||||
options_shape.set_selected_index(0);
|
options_shape.set_selected_index(0);
|
||||||
text_shape.set(shape_strings[0]);
|
text_shape.set(shape_strings[0]);
|
||||||
|
|
||||||
|
options_mod.on_change = [this](size_t, OptionsField::value_t v) {
|
||||||
|
if (auto_update)
|
||||||
|
update_config();
|
||||||
|
|
||||||
|
if (v == 0) { // In Modulation Options CW we are not using Tone modulation freq.
|
||||||
|
symfield_tone.hidden(true);
|
||||||
|
} else {
|
||||||
|
symfield_tone.hidden(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((v == 0) || (v == 2) || (v == 3)) { // In Modulation Options CW, QPSK, BPSK we are not using Shapes.
|
||||||
|
options_shape.hidden(true);
|
||||||
|
text_shape.hidden(true);
|
||||||
|
} else {
|
||||||
|
options_shape.hidden(false);
|
||||||
|
text_shape.hidden(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_dirty();
|
||||||
|
};
|
||||||
|
options_mod.set_selected_index(0);
|
||||||
|
|
||||||
field_stop.set_value(1);
|
field_stop.set_value(1);
|
||||||
|
|
||||||
symfield_tone.set_value(1000); // Default: 1000 Hz
|
symfield_tone.set_value(1000); // Default: 1000 Hz
|
||||||
|
@ -58,68 +58,73 @@ class SigGenView : public View {
|
|||||||
app_settings::SettingsManager settings_{
|
app_settings::SettingsManager settings_{
|
||||||
"tx_siggen", app_settings::Mode::TX};
|
"tx_siggen", app_settings::Mode::TX};
|
||||||
|
|
||||||
const std::string shape_strings[9] = {
|
const std::string shape_strings[6] = {// max 15 character text space.
|
||||||
"CW (No mod.) ",
|
"Sine",
|
||||||
"Sine mod. FM",
|
"Triangle",
|
||||||
"Triangle mod.FM", // max 15 character text space.
|
"Saw up",
|
||||||
"Saw up mod. FM",
|
"Saw down",
|
||||||
"Saw down mod.FM",
|
"Square",
|
||||||
"Square mod. FM",
|
"Pseudo Noise"};
|
||||||
"Pseudo Noise FM", // using 16 bits LFSR register, 16 order polynomial feedback.
|
|
||||||
"BPSK 0,1,0,1...",
|
|
||||||
"QPSK 00-01-10.."};
|
|
||||||
|
|
||||||
bool auto_update{false};
|
bool auto_update{false};
|
||||||
|
|
||||||
Labels labels{
|
Labels labels{
|
||||||
{{3 * 8, 4 + 10}, "Shape:", Theme::getInstance()->fg_light->foreground},
|
{{3 * 8, 2 * 8}, "Modulation:", Theme::getInstance()->fg_light->foreground},
|
||||||
{{6 * 8, 7 * 8}, "Tone: Hz", Theme::getInstance()->fg_light->foreground},
|
{{3 * 8, 3 * 8 + 8 + 10}, "Shape:", Theme::getInstance()->fg_light->foreground},
|
||||||
{{22 * 8, 15 * 8 + 4}, "s.", Theme::getInstance()->fg_light->foreground},
|
{{6 * 8, 2 * 8 + 7 * 8}, "Tone: Hz", Theme::getInstance()->fg_light->foreground},
|
||||||
{{8 * 8, 20 * 8}, "Modulation: FM", Theme::getInstance()->fg_light->foreground}};
|
{{22 * 8, 2 * 8 + 15 * 8 + 4}, "s.", Theme::getInstance()->fg_light->foreground}};
|
||||||
|
|
||||||
ImageOptionsField options_shape{
|
ImageOptionsField options_shape{
|
||||||
{10 * 8, 4, 32, 32},
|
{10 * 8, 3 * 8 + 8, 32, 32},
|
||||||
Theme::getInstance()->bg_darkest->foreground,
|
Theme::getInstance()->bg_darkest->foreground,
|
||||||
Theme::getInstance()->bg_darkest->background,
|
Theme::getInstance()->bg_darkest->background,
|
||||||
{{&bitmap_sig_cw, 0},
|
{{&bitmap_sig_sine, 0},
|
||||||
{&bitmap_sig_sine, 1},
|
{&bitmap_sig_tri, 1},
|
||||||
{&bitmap_sig_tri, 2},
|
{&bitmap_sig_saw_up, 2},
|
||||||
{&bitmap_sig_saw_up, 3},
|
{&bitmap_sig_saw_down, 3},
|
||||||
{&bitmap_sig_saw_down, 4},
|
{&bitmap_sig_square, 4},
|
||||||
{&bitmap_sig_square, 5},
|
{&bitmap_sig_noise, 5}}};
|
||||||
{&bitmap_sig_noise, 6},
|
|
||||||
{&bitmap_sig_noise, 7}, // Pending to add a correct BPSK icon.
|
|
||||||
{&bitmap_sig_noise, 8}}}; // Pending to add a correct QPSK icon.
|
|
||||||
|
|
||||||
Text text_shape{
|
Text text_shape{
|
||||||
{15 * 8, 4 + 10, 15 * 8, 16},
|
{15 * 8, 3 * 8 + 8 + 10, 15 * 8, 16},
|
||||||
""};
|
""};
|
||||||
|
|
||||||
SymField symfield_tone{
|
SymField symfield_tone{
|
||||||
{12 * 8, 7 * 8},
|
{12 * 8, 2 * 8 + 7 * 8},
|
||||||
5};
|
5};
|
||||||
|
|
||||||
Button button_update{
|
Button button_update{
|
||||||
{5 * 8, 10 * 8, 8 * 8, 3 * 8},
|
{5 * 8, 2 * 8 + 10 * 8, 8 * 8, 3 * 8},
|
||||||
"Update"};
|
"Update"};
|
||||||
|
|
||||||
Checkbox checkbox_auto{
|
Checkbox checkbox_auto{
|
||||||
{15 * 8, 10 * 8},
|
{15 * 8, 2 * 8 + 10 * 8},
|
||||||
4,
|
4,
|
||||||
"Auto"};
|
"Auto"};
|
||||||
|
|
||||||
Checkbox checkbox_stop{
|
Checkbox checkbox_stop{
|
||||||
{5 * 8, 15 * 8},
|
{5 * 8, 2 * 8 + 15 * 8},
|
||||||
10,
|
10,
|
||||||
"Stop after"};
|
"Stop after"};
|
||||||
|
|
||||||
NumberField field_stop{
|
NumberField field_stop{
|
||||||
{20 * 8, 15 * 8 + 4},
|
{20 * 8, 2 * 8 + 15 * 8 + 4},
|
||||||
2,
|
2,
|
||||||
{1, 99},
|
{1, 99},
|
||||||
1,
|
1,
|
||||||
' '};
|
' '};
|
||||||
|
|
||||||
|
OptionsField options_mod{
|
||||||
|
{15 * 8, 2 * 8},
|
||||||
|
12,
|
||||||
|
{{"CW (No mod.)", 0},
|
||||||
|
{"FM", 1},
|
||||||
|
{"BPSK", 2},
|
||||||
|
{"QPSK", 3},
|
||||||
|
{"DSB", 4},
|
||||||
|
{"AM 100% dep.", 5},
|
||||||
|
{"AM 50% depth", 6}}};
|
||||||
|
|
||||||
TransmitterView tx_view{
|
TransmitterView tx_view{
|
||||||
16 * 16,
|
16 * 16,
|
||||||
10000,
|
10000,
|
||||||
|
@ -38,28 +38,67 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
} else
|
} else
|
||||||
sample_count--;
|
sample_count--;
|
||||||
|
|
||||||
if (tone_shape == 0) {
|
if (modulation == 0) {
|
||||||
// CW
|
// CW
|
||||||
re = 127; // max. signed 8 bits value . (-128 ...+127), max. amplitude , static phasor at 0º
|
re = 127; // max. signed 8 bits value . (-128 ...+127), max. amplitude , static phasor at 0º
|
||||||
im = 0;
|
im = 0;
|
||||||
} else {
|
} else if (modulation == 2) {
|
||||||
if (tone_shape == 1) {
|
// Digital BPSK consecutive 0,1,0,...continuous cycle, 1 bit/symbol, at rate of 2 symbols / Freq Tone Periode... without any Pulse shape at the moment .
|
||||||
|
re = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128; // Sending 2 bits by Periode T of the GUI tone, alternative static phasor to 0, -180º , 0º
|
||||||
|
im = 0;
|
||||||
|
tone_phase += tone_delta; // In BPSK-QSPK we are using to calculate each 1/4 of the periode.
|
||||||
|
} else if (modulation == 3) {
|
||||||
|
// Digital QPSK consecutive 00, 01, 10, 11,00, ...continuous cycle ,2 bits/symbol, at rate of 4 symbols / Freq Tone Periode. not random., without any Pulse shape at the moment .
|
||||||
|
|
||||||
|
switch (((tone_phase & 0xFF000000) >> 24)) {
|
||||||
|
case 0 ... 63: // equivalent to 1/4 of total 360º degrees.
|
||||||
|
/* "00" */
|
||||||
|
re = (sine_table_i8[32]); // we are sending symbol-phasor 45º during 1/4 of the total periode
|
||||||
|
im = (sine_table_i8[32 + 64]); // 32 index = rounded (45º/360º * 255 total sin table steps) = 31,875
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 64 ... 127:
|
||||||
|
/* "01" */
|
||||||
|
re = (sine_table_i8[96]); // symbol-phasor 135º
|
||||||
|
im = (sine_table_i8[96 + 64]); // 96 index = 32 + 256/4
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 128 ... 191:
|
||||||
|
/* "10" */
|
||||||
|
re = (sine_table_i8[159]); // symbol-phasor 225º
|
||||||
|
im = (sine_table_i8[159 + 64]); // 159 rounded index = 96 + 256/4 = 159.3
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 192 ... 255:
|
||||||
|
/* "11" */
|
||||||
|
re = (sine_table_i8[223]); // symbol-phasor 315º ; 223 rounded index = (315/360) * 255 =223.125
|
||||||
|
im = (sine_table_i8[((223 + 64) & 0xFF)]); // Max index 255, circular periodic conversion.
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tone_phase += tone_delta; // In BPSK-QSPK we are using to calculate each 1/4 of the periode.
|
||||||
|
|
||||||
|
} else { // Other modulations: FM, DSB, AM
|
||||||
|
if (tone_shape == 0) {
|
||||||
// Sine
|
// Sine
|
||||||
sample = (sine_table_i8[(tone_phase & 0xFF000000) >> 24]);
|
sample = (sine_table_i8[(tone_phase & 0xFF000000) >> 24]);
|
||||||
} else if (tone_shape == 2) {
|
} else if (tone_shape == 1) {
|
||||||
// Triangle
|
// Triangle
|
||||||
int8_t a = (tone_phase & 0xFF000000) >> 24;
|
int8_t a = (tone_phase & 0xFF000000) >> 24;
|
||||||
sample = (a & 0x80) ? ((a << 1) ^ 0xFF) - 0x80 : (a << 1) + 0x80;
|
sample = (a & 0x80) ? ((a << 1) ^ 0xFF) - 0x80 : (a << 1) + 0x80;
|
||||||
} else if (tone_shape == 3) {
|
} else if (tone_shape == 2) {
|
||||||
// Saw up
|
// Saw up
|
||||||
sample = ((tone_phase & 0xFF000000) >> 24);
|
sample = ((tone_phase & 0xFF000000) >> 24);
|
||||||
} else if (tone_shape == 4) {
|
} else if (tone_shape == 3) {
|
||||||
// Saw down
|
// Saw down
|
||||||
sample = ((tone_phase & 0xFF000000) >> 24) ^ 0xFF;
|
sample = ((tone_phase & 0xFF000000) >> 24) ^ 0xFF;
|
||||||
} else if (tone_shape == 5) {
|
} else if (tone_shape == 4) {
|
||||||
// Square
|
// Square
|
||||||
sample = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128;
|
sample = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128;
|
||||||
} else if (tone_shape == 6) {
|
} else if (tone_shape == 5) {
|
||||||
// Noise generator, pseudo random noise generator, 16 bits linear-feedback shift register (LFSR) algorithm, variant Fibonacci.
|
// Noise generator, pseudo random noise generator, 16 bits linear-feedback shift register (LFSR) algorithm, variant Fibonacci.
|
||||||
// https://en.wikipedia.org/wiki/Linear-feedback_shift_register
|
// https://en.wikipedia.org/wiki/Linear-feedback_shift_register
|
||||||
// 16 bits LFSR .taps: 16, 15, 13, 4 ;feedback polynomial: x^16 + x^15 + x^13 + x^4 + 1
|
// 16 bits LFSR .taps: 16, 15, 13, 4 ;feedback polynomial: x^16 + x^15 + x^13 + x^4 + 1
|
||||||
@ -79,49 +118,13 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
if (counter == 15) {
|
if (counter == 15) {
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
} else if (tone_shape == 7) {
|
|
||||||
// Digital BPSK consecutive 0,1,0,...continuous cycle, 1 bit/symbol, at rate of 2 symbols / Freq Tone Periode... without any Pulse shape at the moment .
|
|
||||||
re = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128; // Sending 2 bits by Periode T of the GUI tone, alternative static phasor to 0, -180º , 0º
|
|
||||||
im = 0;
|
|
||||||
} else if (tone_shape == 8) {
|
|
||||||
// Digital QPSK consecutive 00, 01, 10, 11,00, ...continuous cycle ,2 bits/symbol, at rate of 4 symbols / Freq Tone Periode. not random., without any Pulse shape at the moment .
|
|
||||||
|
|
||||||
switch (((tone_phase & 0xFF000000) >> 24)) {
|
|
||||||
case 0 ... 63: // equivalent to 1/4 of total 360º degrees.
|
|
||||||
/* "00" */
|
|
||||||
re = (sine_table_i8[32]); // we are sending symbol-phasor 45º during 1/4 of the total periode
|
|
||||||
im = (sine_table_i8[32 + 64]); // 32 index = rounded (45º/360º * 255 total sin table steps) = 31,875
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 64 ... 127:
|
|
||||||
/* "01" */
|
|
||||||
re = (sine_table_i8[96]); // symbol-phasor 135º
|
|
||||||
im = (sine_table_i8[96 + 64]); // 96 index = 32 + 256/4
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 128 ... 191:
|
|
||||||
/* "10" */
|
|
||||||
re = (sine_table_i8[159]); // symbol-phasor 225º
|
|
||||||
im = (sine_table_i8[159 + 64]); // 159 rounded index = 96 + 256/4 = 159.3
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 192 ... 255:
|
|
||||||
/* "11" */
|
|
||||||
re = (sine_table_i8[223]); // symbol-phasor 315º ; 223 rounded index = (315/360) * 255 =223.125
|
|
||||||
im = (sine_table_i8[((223 + 64) & 0xFF)]); // Max index 255, circular periodic conversion.
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tone_shape != 6) { //(all except Pseudo Random White Noise). We are in (1):periodic signals or (2):BPSK/QPSK , in both cases ,we need Tone updated acum sum phases to modulate in FM / or control phasor phase (BPSK & QPSK.)
|
if (tone_shape != 5) { // All periodic except Pseudo Random White Noise.
|
||||||
tone_phase += tone_delta; // In periodic signals(Sine/triangle/square) we are using to FM mod. in BPSK-QSPK we are using to calculate each 1/4 of the periode.
|
tone_phase += tone_delta; // In periodic signals we are using phase to generate the tone to be modulated.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tone_shape < 7) { // All Option shape signals except BPSK(7) & QPSK(8) we are modulating in FM. (Those two has phase shift modulation XPSK , not FM )
|
if (modulation == 1) {
|
||||||
// Do FM modulation
|
// Do FM modulation
|
||||||
delta = sample * fm_delta;
|
delta = sample * fm_delta;
|
||||||
|
|
||||||
@ -130,6 +133,21 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
|
|
||||||
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]); // sin LUT is not dealing with decimals , output range [-128 ,...127]
|
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]); // sin LUT is not dealing with decimals , output range [-128 ,...127]
|
||||||
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
|
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
|
||||||
|
|
||||||
|
} else if (modulation == 4) {
|
||||||
|
// Do Double Side Band modulation
|
||||||
|
re = sample;
|
||||||
|
im = 0;
|
||||||
|
|
||||||
|
} else if (modulation == 5) {
|
||||||
|
// Do AM modulation (100% mod index)
|
||||||
|
re = (127 >> 1) + (sample >> 1);
|
||||||
|
im = 0;
|
||||||
|
|
||||||
|
} else if (modulation == 6) {
|
||||||
|
// Do AM modulation (50% mod index)
|
||||||
|
re = 95 + (sample >> 2);
|
||||||
|
im = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +172,8 @@ void SigGenProcessor::on_message(const Message* const msg) {
|
|||||||
auto_off = false;
|
auto_off = false;
|
||||||
|
|
||||||
fm_delta = message.bw * (0xFFFFFFULL / 1536000);
|
fm_delta = message.bw * (0xFFFFFFULL / 1536000);
|
||||||
tone_shape = message.shape;
|
tone_shape = message.shape & 0xF;
|
||||||
|
modulation = (message.shape & 0xF0) >> 4;
|
||||||
|
|
||||||
// lfsr = seed_value ; // Finally not used , init lfsr 8 bits.
|
// lfsr = seed_value ; // Finally not used , init lfsr 8 bits.
|
||||||
lfsr_16 = seed_value_16; // init lfsr 16 bits.
|
lfsr_16 = seed_value_16; // init lfsr 16 bits.
|
||||||
|
@ -36,7 +36,7 @@ class SigGenProcessor : public BasebandProcessor {
|
|||||||
bool configured{false};
|
bool configured{false};
|
||||||
|
|
||||||
uint32_t tone_delta{0}, fm_delta{}, tone_phase{0};
|
uint32_t tone_delta{0}, fm_delta{}, tone_phase{0};
|
||||||
uint8_t tone_shape{};
|
uint8_t tone_shape{}, modulation{};
|
||||||
uint32_t sample_count{0};
|
uint32_t sample_count{0};
|
||||||
bool auto_off{};
|
bool auto_off{};
|
||||||
int32_t phase{0}, sphase{0}, delta{0}; // they may have sign in the pseudo random sample generation.
|
int32_t phase{0}, sphase{0}, delta{0}; // they may have sign in the pseudo random sample generation.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user