Move amplitude (level) debugging to debug.c

This commit is contained in:
Andreas Eversberg 2016-05-15 20:31:42 +02:00
parent adc3270dc0
commit 7aa2445b47
6 changed files with 28 additions and 65 deletions

View File

@ -188,21 +188,6 @@ static void fsk_receive_bit(bnetz_t *bnetz, int bit, double level, double qualit
bnetz_receive_telegramm(bnetz, bnetz->fsk_filter_telegramm, level, quality); bnetz_receive_telegramm(bnetz, bnetz->fsk_filter_telegramm, level, quality);
} }
char *show_level(int value)
{
static char text[22];
value /= 5;
if (value < 0)
value = 0;
if (value > 20)
value = 20;
strcpy(text, " ");
text[value] = '*';
return text;
}
//#define DEBUG_FILTER //#define DEBUG_FILTER
//#define DEBUG_QUALITY //#define DEBUG_QUALITY
@ -236,8 +221,8 @@ static inline void fsk_decode_step(bnetz_t *bnetz, int pos)
if (softbit < 0) if (softbit < 0)
softbit = 0; softbit = 0;
#ifdef DEBUG_FILTER #ifdef DEBUG_FILTER
printf("|%s", show_level(result[0]/level*100)); printf("|%s", debug_amplitude(result[0]/level));
printf("|%s| low=%.3f high=%.3f level=%d\n", show_level(result[1]/level*100), result[0]/level, result[1]/level, (int)level); printf("|%s| low=%.3f high=%.3f level=%d\n", debug_amplitude(result[1]/level), result[0]/level, result[1]/level, (int)level);
#endif #endif
if (softbit > 0.5) if (softbit > 0.5)
bit = 1; bit = 1;
@ -264,8 +249,8 @@ static inline void fsk_decode_step(bnetz_t *bnetz, int pos)
} else if (--bnetz->fsk_filter_sample == 0) { } else if (--bnetz->fsk_filter_sample == 0) {
/* if sample counter bit reaches 0, we reset sample counter to one bit duration */ /* if sample counter bit reaches 0, we reset sample counter to one bit duration */
#ifdef DEBUG_QUALITY #ifdef DEBUG_QUALITY
printf("|%s| quality=%.2f ", show_level(softbit * 100), quality); printf("|%s| quality=%.2f ", debug_amplitude(softbit), quality);
printf("|%s|\n", show_level(quality * 100)); printf("|%s|\n", debug_amplitude(quality);
#endif #endif
/* adjust level, so we get peak of sine curve */ /* adjust level, so we get peak of sine curve */
fsk_receive_bit(bnetz, bit, level / 0.63662 * 32768.0 / TX_PEAK_TONE, quality); fsk_receive_bit(bnetz, bit, level / 0.63662 * 32768.0 / TX_PEAK_TONE, quality);

View File

@ -552,18 +552,6 @@ static int fsk_distributed_encode(cnetz_t *cnetz, const char *bits)
return count; return count;
} }
void show_level(double level)
{
char text[42] = " ";
if (level > 1.0)
level = 1.0;
if (level < -1.0)
level = -1.0;
text[20 - (int)(level * 20)] = '*';
printf("%s\n", text);
}
/* decode samples and hut for bit changes /* decode samples and hut for bit changes
* use deviation to find greatest slope of the signal (bit change) * use deviation to find greatest slope of the signal (bit change)
*/ */

View File

@ -317,17 +317,6 @@ got_sync:
} }
} }
#ifdef DEBUG_DECODER
static void fsk_show_level(double level)
{
if (level > 1.0)
level = 1.0;
if (level < -1.0)
level = -1.0;
printf(" *\n" + 10 - (int)(level * 10));
}
#endif
/* DOC TBD: find change for bit change */ /* DOC TBD: find change for bit change */
static inline void find_change(fsk_fm_demod_t *fsk) static inline void find_change(fsk_fm_demod_t *fsk)
{ {
@ -438,7 +427,7 @@ void fsk_fm_demod(fsk_fm_demod_t *fsk, int16_t *samples, int length)
if (fsk->cnetz->dsp_mode != DSP_MODE_SPK_V) { if (fsk->cnetz->dsp_mode != DSP_MODE_SPK_V) {
#ifdef DEBUG_DECODER #ifdef DEBUG_DECODER
DEBUG_DECODER DEBUG_DECODER
fsk_show_level((double)samples[i] / 32768.0); puts(debug_amplitude((double)samples[i] / 32768.0));
#endif #endif
find_change(fsk); find_change(fsk);
} else { } else {
@ -462,7 +451,7 @@ void fsk_fm_demod(fsk_fm_demod_t *fsk, int16_t *samples, int length)
if (t >= 0.5 && t < 5.5) { if (t >= 0.5 && t < 5.5) {
#ifdef DEBUG_DECODER #ifdef DEBUG_DECODER
DEBUG_DECODER DEBUG_DECODER
fsk_show_level((double)samples[i] / 32768.0); puts(debug_amplitude((double)samples[i] / 32768.0));
#endif #endif
find_change(fsk); find_change(fsk);
} else } else

View File

@ -70,3 +70,17 @@ void _printdebug(const char *file, const char *function, int line, int cat, int
fflush(stdout); fflush(stdout);
} }
const char *debug_amplitude(double level)
{
static char text[42];
strcpy(text, " : ");
if (level > 1.0)
level = 1.0;
if (level < -1.0)
level = -1.0;
text[20 + (int)(level * 20)] = '*';
return text;
}

View File

@ -19,5 +19,7 @@
#define PDEBUG(cat, level, fmt, arg...) _printdebug(__FILE__, __FUNCTION__, __LINE__, cat, level, fmt, ## arg) #define PDEBUG(cat, level, fmt, arg...) _printdebug(__FILE__, __FUNCTION__, __LINE__, cat, level, fmt, ## arg)
void _printdebug(const char *file, const char *function, int line, int cat, int level, const char *fmt, ...); void _printdebug(const char *file, const char *function, int line, int cat, int level, const char *fmt, ...);
const char *debug_amplitude(double level);
extern int debuglevel; extern int debuglevel;

View File

@ -267,21 +267,6 @@ static void fsk_receive_bit(nmt_t *nmt, int bit, double quality, double level)
nmt_receive_frame(nmt, nmt->fsk_filter_frame, quality, level * 32768.0 / TX_PEAK_FSK, frames_elapsed); nmt_receive_frame(nmt, nmt->fsk_filter_frame, quality, level * 32768.0 / TX_PEAK_FSK, frames_elapsed);
} }
char *show_level(int value)
{
static char text[22];
value /= 5;
if (value < 0)
value = 0;
if (value > 20)
value = 20;
strcpy(text, " ");
text[value] = '*';
return text;
}
//#define DEBUG_MODULATOR //#define DEBUG_MODULATOR
//#define DEBUG_FILTER //#define DEBUG_FILTER
//#define DEBUG_QUALITY //#define DEBUG_QUALITY
@ -317,9 +302,9 @@ static inline void fsk_decode_step(nmt_t *nmt, int pos)
#define MIN_QUALITY 0.33 #define MIN_QUALITY 0.33
softbit = (softbit - MIN_QUALITY) / (1.0 - MIN_QUALITY - MIN_QUALITY); softbit = (softbit - MIN_QUALITY) / (1.0 - MIN_QUALITY - MIN_QUALITY);
#ifdef DEBUG_FILTER #ifdef DEBUG_FILTER
// printf("|%s", show_level(result[0]/level*100)); // printf("|%s", debug_amplitude(result[0]/level));
// printf("|%s| low=%.3f high=%.3f level=%d\n", show_level(result[1]/level*100), result[0]/level, result[1]/level, (int)level); // printf("|%s| low=%.3f high=%.3f level=%d\n", debug_amplitude(result[1]/level), result[0]/level, result[1]/level, (int)level);
printf("|%s| softbit=%.3f\n", show_level(softbit * 100), softbit); printf("|%s| softbit=%.3f\n", debug_amplitude(softbit), softbit);
#endif #endif
if (softbit > 1) if (softbit > 1)
softbit = 1; softbit = 1;
@ -348,8 +333,8 @@ static inline void fsk_decode_step(nmt_t *nmt, int pos)
else else
quality = 1.0 - softbit * 2.0; quality = 1.0 - softbit * 2.0;
#ifdef DEBUG_QUALITY #ifdef DEBUG_QUALITY
printf("|%s| quality=%.2f ", show_level(softbit * 100), quality); printf("|%s| quality=%.2f ", debug_amplitude(softbit), quality);
printf("|%s|\n", show_level(quality * 100)); printf("|%s|\n", debug_amplitude(quality));
#endif #endif
/* adjust level, so a peak level becomes 100% */ /* adjust level, so a peak level becomes 100% */
fsk_receive_bit(nmt, bit, quality, level / 0.63662); fsk_receive_bit(nmt, bit, quality, level / 0.63662);
@ -442,7 +427,7 @@ void sender_receive(sender_t *sender, int16_t *samples, int length)
spl = nmt->fsk_filter_spl; spl = nmt->fsk_filter_spl;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
#ifdef DEBUG_MODULATOR #ifdef DEBUG_MODULATOR
printf("|%s|\n", show_level((int)((samples[i] / TX_PEAK_FSK) * 50)+50)); printf("|%s|\n", debug_amplitude((double)samples[i] / TX_PEAK_FSK / 2.0));
#endif #endif
spl[pos++] = samples[i]; spl[pos++] = samples[i];
if (nmt->fsk_filter_mute) { if (nmt->fsk_filter_mute) {