From 75fd44436c688c59f2ee8b2957d2666e4fa85537 Mon Sep 17 00:00:00 2001 From: Zilog80 Date: Wed, 8 Jan 2020 10:07:07 +0100 Subject: [PATCH] IQ lowpass speedup --- scan/dft_detect.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scan/dft_detect.c b/scan/dft_detect.c index 4c735e7..984a1dd 100644 --- a/scan/dft_detect.c +++ b/scan/dft_detect.c @@ -1,4 +1,13 @@ +/* + * compile: + * gcc dft_detect.c -lm -o dft_detect + * speedup: + * gcc -Ofast dft_detect.c -lm -o dft_detect + * + * author: zilog80 + */ + #include #include #include @@ -574,7 +583,7 @@ static int lowpass_init(float f, int taps, float **pws) { h = (double*)calloc( taps+1, sizeof(double)); if (h == NULL) return -1; w = (double*)calloc( taps+1, sizeof(double)); if (w == NULL) return -1; - ws = (float*)calloc( taps+1, sizeof(float)); if (ws == NULL) return -1; + ws = (float*)calloc( 2*taps+1, sizeof(float)); if (ws == NULL) return -1; for (n = 0; n < taps; n++) { w[n] = 7938/18608.0 - 9240/18608.0*cos(2*M_PI*n/(taps-1)) + 1430/18608.0*cos(4*M_PI*n/(taps-1)); // Blackmann @@ -585,6 +594,9 @@ static int lowpass_init(float f, int taps, float **pws) { for (n = 0; n < taps; n++) { ws[n] /= norm; // 1-norm } + + for (n = 0; n < taps; n++) ws[taps+n] = ws[n]; // duplicate/unwrap + *pws = ws; free(h); h = NULL; @@ -594,7 +606,7 @@ static int lowpass_init(float f, int taps, float **pws) { } // struct { int taps; double *ws} -static float complex lowpass(float complex buffer[], ui32_t sample, ui32_t taps, float *ws) { +static float complex lowpass0(float complex buffer[], ui32_t sample, ui32_t taps, float *ws) { ui32_t n; double complex w = 0; for (n = 0; n < taps; n++) { @@ -602,6 +614,16 @@ static float complex lowpass(float complex buffer[], ui32_t sample, ui32_t taps, } return (float complex)w; } +static float complex lowpass(float complex buffer[], ui32_t sample, ui32_t taps, float *ws) { + ui32_t n; + ui32_t s = sample % taps; + double complex w = 0; + for (n = 0; n < taps; n++) { + w += buffer[n]*ws[taps+s-n]; // ws[taps+s-n] = ws[(taps+sample-n)%taps] + } + return (float complex)w; +// symmetry: ws[n] == ws[taps-1-n] +} static int f32buf_sample(FILE *fp, int inv) { @@ -1197,7 +1219,7 @@ int main(int argc, char **argv) { else { fp = fopen(*argv, "rb"); if (fp == NULL) { - fprintf(stderr, "%s konnte nicht geoeffnet werden\n", *argv); + fprintf(stderr, "error: open %s\n", *argv); return -50; } wavloaded = 1;