aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-02-12 07:35:05 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-02-18 21:02:53 +0100
commit58ebc152922055581c3f19c4ddd68c324059dbab (patch)
treeaa933446815d3f3d84444e154a2a23f081323228 /src/test
parent4de1e0188d41c29477a5705e13dddea84a195e7b (diff)
Add test to measure performance of FM modulation and filtering
Diffstat (limited to 'src/test')
-rw-r--r--src/test/Makefile.am12
-rw-r--r--src/test/test_performance.c67
2 files changed, 78 insertions, 1 deletions
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index eace0dc..eb50f7d 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -6,7 +6,8 @@ noinst_PROGRAMS = \
test_compandor \
test_emphasis \
test_dms \
- test_sms
+ test_sms \
+ test_performance
test_filter_SOURCES = test_filter.c dummy.c
@@ -57,3 +58,12 @@ test_sms_LDADD = \
$(UHD_LIBS) \
-lm
+test_performance_SOURCES = dummy.c test_performance.c
+
+test_performance_LDADD = \
+ $(COMMON_LA) \
+ $(top_builddir)/src/common/libcommon.a \
+ $(ALSA_LIBS) \
+ $(UHD_LIBS) \
+ -lm
+
diff --git a/src/test/test_performance.c b/src/test/test_performance.c
new file mode 100644
index 0000000..622df67
--- /dev/null
+++ b/src/test/test_performance.c
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <math.h>
+#include <string.h>
+#include <sys/time.h>
+#include "../common/sample.h"
+#include "../common/filter.h"
+#include "../common/fm_modulation.h"
+#include "../common/debug.h"
+
+struct timeval start_tv, tv;
+double duration;
+int tot_samples;
+
+#define T_START() \
+ gettimeofday(&start_tv, NULL); \
+ tot_samples = 0; \
+ while (1) {
+
+#define T_STOP(what, samples) \
+ gettimeofday(&tv, NULL); \
+ duration = (double)tv.tv_sec + (double)tv.tv_usec / 1e6; \
+ duration -= (double)start_tv.tv_sec + (double)start_tv.tv_usec / 1e6; \
+ tot_samples += samples; \
+ if (duration >= 0.5) \
+ break; \
+ } \
+ printf("%s: %.3f mega samples/sec\n", what, (double)tot_samples / duration / 1e6); \
+
+
+#define SAMPLES 1000
+sample_t samples[SAMPLES];
+float buff[SAMPLES * 2];
+fm_mod_t mod;
+fm_demod_t demod;
+filter_t lp;
+
+int main(void)
+{
+ fm_mod_init(&mod, 50000, 0, 0.333);
+ T_START()
+ fm_modulate(&mod, samples, SAMPLES, buff);
+ T_STOP("FM modulate", SAMPLES)
+
+ fm_demod_init(&demod, 50000, 0, 10000.0);
+ T_START()
+ fm_demodulate(&demod, samples, SAMPLES, buff);
+ T_STOP("FM demodulate", SAMPLES)
+
+ filter_lowpass_init(&lp, 10000.0 / 2.0, 50000, 1);
+ T_START()
+ filter_process(&lp, samples, SAMPLES);
+ T_STOP("low-pass filter (second order)", SAMPLES)
+
+ filter_lowpass_init(&lp, 10000.0 / 2.0, 50000, 2);
+ T_START()
+ filter_process(&lp, samples, SAMPLES);
+ T_STOP("low-pass filter (fourth order)", SAMPLES)
+
+ filter_lowpass_init(&lp, 10000.0 / 2.0, 50000, 4);
+ T_START()
+ filter_process(&lp, samples, SAMPLES);
+ T_STOP("low-pass filter (eigth order)", SAMPLES)
+
+ return 0;
+}
+