Test filter uses a dB graph to show the response graphically

This commit is contained in:
Andreas Eversberg 2017-01-27 17:17:39 +01:00
parent 7ea3bc188d
commit b3fd53b165
3 changed files with 25 additions and 22 deletions

View File

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <math.h>
#include "sample.h"
#include "debug.h"
#include "display.h"
@ -118,6 +119,26 @@ const char *debug_amplitude(double level)
return text;
}
#define level2db(level) (20 * log10(level))
const char *debug_db(double level_db)
{
static char text[128];
int l;
strcpy(text, ": . : . : . : . : . : . : . : . : ");
if (level_db <= 0.0)
return text;
l = (int)round(level2db(level_db));
if (l > 3)
return text;
if (l < -48)
return text;
text[l + 48] = '*';
return text;
}
void debug_list_cat(void)
{
int i;

View File

@ -27,6 +27,7 @@
void _printdebug(const char *file, const char *function, int line, int cat, int level, int chan, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 7, 8)));
const char *debug_amplitude(double level);
const char *debug_db(double level_db);
void debug_list_cat(void);
int parse_debug_opt(const char *opt);

View File

@ -13,31 +13,12 @@
static double get_level(double *samples)
{
#if 0
int i;
double last = 0, envelope = 0;
int up = 0;
for (i = SAMPLERATE/2; i < SAMPLERATE; i++) {
if (last < samples[i]) {
up = 1;
} else if (last > samples[i]) {
if (up) {
if (last > envelope)
envelope = last;
}
up = 0;
}
last = samples[i];
}
#else
int i;
double envelope = 0;
for (i = SAMPLERATE/2; i < SAMPLERATE; i++) {
if (samples[i] > envelope)
envelope = samples[i];
}
#endif
return envelope;
}
@ -72,7 +53,7 @@ int main(void)
gen_samples(samples, (double)i);
filter_process(&filter_low, samples, SAMPLERATE);
level = get_level(samples);
printf("%4d Hz: %.1f dB", i, level2db(level));
printf("%s%4d Hz: %.1f dB", debug_db(level), i, level2db(level));
if (i == 1000)
printf(" cutoff\n");
else if (i == 2000)
@ -91,7 +72,7 @@ int main(void)
gen_samples(samples, (double)i);
filter_process(&filter_high, samples, SAMPLERATE);
level = get_level(samples);
printf("%4d Hz: %.1f dB", i, level2db(level));
printf("%s%4d Hz: %.1f dB", debug_db(level), i, level2db(level));
if (i == 2000)
printf(" cutoff\n");
else if (i == 1000)
@ -112,7 +93,7 @@ int main(void)
filter_process(&filter_low, samples, SAMPLERATE);
filter_process(&filter_high, samples, SAMPLERATE);
level = get_level(samples);
printf("%4d Hz: %.1f dB", i, level2db(level));
printf("%s%4d Hz: %.1f dB", debug_db(level), i, level2db(level));
if (i == 1000)
printf(" cutoff high\n");
else if (i == 2000)