Improvement of Goertzel filter. Using Hamming window now. Add test routine.
This commit is contained in:
@@ -5,6 +5,7 @@ noinst_PROGRAMS = \
|
||||
test_sendevolumenregler \
|
||||
test_compandor \
|
||||
test_emphasis \
|
||||
test_goertzel \
|
||||
test_dtmf \
|
||||
test_dms \
|
||||
test_sms \
|
||||
@@ -150,3 +151,12 @@ test_v27scrambler_LDADD = \
|
||||
$(top_builddir)/src/libv27/libv27.a \
|
||||
-lm
|
||||
|
||||
test_goertzel_SOURCES = test_goertzel.c dummy.c
|
||||
|
||||
test_goertzel_LDADD = \
|
||||
$(COMMON_LA) \
|
||||
$(top_builddir)/src/libdebug/libdebug.a \
|
||||
$(top_builddir)/src/libgoertzel/libgoertzel.a \
|
||||
$(top_builddir)/src/liboptions/liboptions.a \
|
||||
-lm
|
||||
|
||||
|
51
src/test/test_goertzel.c
Normal file
51
src/test/test_goertzel.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "../libsample/sample.h"
|
||||
#include "../libgoertzel/goertzel.h"
|
||||
#include "../libdebug/debug.h"
|
||||
|
||||
#define level2db(level) (20 * log10(level))
|
||||
#define db2level(db) pow(10, (double)db / 20.0)
|
||||
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static void gen_samples(sample_t *samples, double freq)
|
||||
{
|
||||
int i;
|
||||
double value;
|
||||
|
||||
for (i = 0; i < SAMPLERATE; i++) {
|
||||
value = cos(2.0 * M_PI * freq / (double)SAMPLERATE * (double)i);
|
||||
samples[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int num_kanal;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
goertzel_t goertzel;
|
||||
sample_t samples[SAMPLERATE];
|
||||
double frequency = 1000;
|
||||
double duration = 1.0/100.0;
|
||||
double level;
|
||||
double i;
|
||||
|
||||
printf("testing goertzel with frequency %.1f and duration 1 / %.0f\n", frequency, 1.0 / duration);
|
||||
|
||||
for (i = 700; i < 1301; i = i + 10) {
|
||||
gen_samples(samples, (double)i);
|
||||
audio_goertzel_init(&goertzel, frequency, SAMPLERATE);
|
||||
audio_goertzel(&goertzel, samples, SAMPLERATE * duration, 0, &level, 1);
|
||||
printf("%s%.0f Hz: %.1f dB", debug_db(level), i, level2db(level));
|
||||
if ((int)round(i) == (int)round(frequency))
|
||||
printf(" level=%.6f\n", level);
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user