Merge pull request #936 from Brumi-2021/solving_bug_in_noise_option_Signal_Generator_tool

Solving Noise generation in Signal gen App
This commit is contained in:
gullradriel 2023-04-30 17:33:18 +02:00 committed by GitHub
commit fe1837ec23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 26 deletions

View File

@ -48,14 +48,16 @@ private:
void update_tone();
void on_tx_progress(const uint32_t progress, const bool done);
const std::string shape_strings[7] = {
"CW",
"Sine",
"Triangle",
"Saw up",
"Saw down",
"Square",
"Noise"
const std::string shape_strings[9] = {
"CW ",
"Sine ",
"Triangle ",
"Saw up ",
"Saw down ",
"Square ",
"Noise n20Khz",
"Noise n10khz",
"Noise n5khz "
};
bool auto_update { false };
@ -78,7 +80,9 @@ private:
{ &bitmap_sig_saw_up, 3 },
{ &bitmap_sig_saw_down, 4 },
{ &bitmap_sig_square, 5 },
{ &bitmap_sig_noise, 6 }
{ &bitmap_sig_noise, 6 },
{ &bitmap_sig_noise, 7 },
{ &bitmap_sig_noise, 8 }
}
};

View File

@ -49,7 +49,7 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
// Sine
sample = (sine_table_i8[(tone_phase & 0xFF000000) >> 24]);
} else if (tone_shape == 2) {
// Tri
// Triangle
int8_t a = (tone_phase & 0xFF000000) >> 24;
sample = (a & 0x80) ? ((a << 1) ^ 0xFF) - 0x80 : (a << 1) + 0x80;
} else if (tone_shape == 3) {
@ -61,24 +61,34 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
} else if (tone_shape == 5) {
// Square
sample = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128;
} else if (tone_shape == 6) {
// Noise
sample = (lfsr & 0xFF000000) >> 24;
feedback = ((lfsr >> 31) ^ (lfsr >> 29) ^ (lfsr >> 15) ^ (lfsr >> 11)) & 1;
lfsr = (lfsr << 1) | feedback;
if (!lfsr) lfsr = 0x1337; // Shouldn't do this :(
} else if (tone_shape == 6) { // taps: 6 5; feedback polynomial: x^6 + x^5 + 1 , Periode 63 = 2^n-1,it generates armonincs n x 20Khz
// White Noise generator, pseudo random noise generator, 8 bits linear-feedback shift register (LFSR) algorithm, variant Fibonacci.
// https://en.wikipedia.org/wiki/Linear-feedback_shift_register
bit = ((lfsr >> 2) ^ (lfsr >> 3)) & 1;
lfsr = (lfsr >> 1) | (bit << 7);
sample = lfsr;
} else if (tone_shape == 7) { // taps: 7 6; feedback polynomial: x^7 + x^6 + 1 , Periode 127 = 2^n-1,it generates armonincs n x 10Khz
bit = ((lfsr >> 1) ^ (lfsr >> 2)) & 1;
lfsr = (lfsr >> 1) | (bit << 7);
sample = lfsr;
} else if (tone_shape == 8) { //taps:8,6,5,4;feedback polynomial: x^8 + x^6 + x^5 + x^4 + 1,Periode 255= 2^n-1, armonics n x 5khz
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4)) & 1;
lfsr = (lfsr >> 1) | (bit << 7);
sample = lfsr;
}
if (tone_shape < 6) {
tone_phase += tone_delta;
}
tone_phase += tone_delta;
// Do FM
// Do FM modulation
delta = sample * fm_delta;
phase += delta;
sphase = phase + (64 << 24);
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]);
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
im = (sine_table_i8[( phase & 0xFF000000) >> 24]);
}
buffer.p[i] = {re, im};
@ -104,7 +114,8 @@ void SigGenProcessor::on_message(const Message* const msg) {
fm_delta = message.bw * (0xFFFFFFULL / 1536000);
tone_shape = message.shape;
lfsr = 0x54DF0119;
// lfsr = 0x54DF0119;
lfsr = seed_value ;
configured = true;
break;

View File

@ -38,13 +38,14 @@ private:
BasebandThread baseband_thread { 1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit };
uint32_t tone_delta { 0 }, fm_delta { };
uint32_t lfsr { }, feedback { }, tone_shape { };
uint32_t tone_delta { 0 }, fm_delta { },tone_phase { 0 };
uint8_t tone_shape { };
uint32_t sample_count { 0 };
bool auto_off { };
uint32_t tone_phase { 0 }, phase { 0 }, delta { 0 }, sphase { 0 };
int8_t sample { 0 };
int8_t re { 0 }, im { 0 };
int32_t phase { 0 }, sphase { 0 }, delta { 0 }; // they may have sign .
int8_t sample { 0 }, re { 0 }, im { 0 }; // they may have sign .
uint8_t seed_value = {0x56}; // seed : any nonzero start state will work.
uint8_t lfsr { }, bit { }; // bit must be 8-bit to allow bit<<7 later in the code */
TXProgressMessage txprogress_message { };
};