static void test_line_filter(int line_model_no) { float out; double sumin; double sumout; double gain; int i; int j; int p; int ptr; int len; swept_tone_state_t *s; float filter[129]; int16_t buf[BLOCK_LEN]; s = swept_tone_init(NULL, 200.0f, 3900.0f, -10.0f, 120*SAMPLE_RATE, 0); for (j = 0; j < 129; j++) filter[j] = 0.0f; ptr = 0; for (;;) { if ((len = swept_tone(s, buf, BLOCK_LEN)) <= 0) break; sumin = 0.0; sumout = 0.0; for (i = 0; i < len; i++) { /* Add the sample in the filter buffer */ p = ptr; filter[p] = buf[i]; if (++p == 129) p = 0; ptr = p; /* Apply the filter */ out = 0.0f; for (j = 0; j < 129; j++) { out += line_models[line_model_no][128 - j]*filter[p]; if (++p >= 129) p = 0; } sumin += buf[i]*buf[i]; sumout += out*out; } /*endfor*/ gain = (sumin != 0.0) ? 10.0*log10(sumout/sumin + 1.0e-10) : 0.0; printf("%7.1f %f\n", swept_tone_current_frequency(s), gain); } /*endfor*/ swept_tone_free(s); }
int16_t buf[SAMPLES_PER_CHUNK]; int i; int len; double sumin; double sumout; swept_tone_state_t *swept; double freq; double gain; int template_entry; FILE *file; /* Things like noise don't highlight the frequency response of the high Q notch very well. We use a slowly swept frequency to check it. */ printf("Frequency response test\n"); sig_tone_rx_set_mode(s, SIG_TONE_RX_PASSTHROUGH | SIG_TONE_RX_FILTER_TONE, 0); swept = swept_tone_init(NULL, 200.0f, 3900.0f, -10.0f, 120*SAMPLE_RATE, 0); template_entry = 0; file = fopen("sig_tone_notch", "wb"); for (;;) { if ((len = swept_tone(swept, buf, SAMPLES_PER_CHUNK)) <= 0) break; /*endif*/ sumin = 0.0; for (i = 0; i < len; i++) sumin += (double) buf[i]*(double) buf[i]; /*endfor*/ sig_tone_rx(s, buf, len); sumout = 0.0; for (i = 0; i < len; i++) sumout += (double) buf[i]*(double) buf[i];