From c43666d6f05bf920de5326489073adbcc60a88cc Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Wed, 19 Sep 2018 16:36:22 +0300 Subject: [PATCH] EQ FIR: Add check and removal for trailing zeros in filter coefficients This patch adds removing of extra zeros in the FIR coefficients. The zeros can happen in some responses due to fixed point quantization of very small values. The zero taps consume DSP resources for nothing so better to clean them out for EQ configuration data. Signed-off-by: Seppo Ingalsuo --- tune/eq/eq_fir_blob_quant.m | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tune/eq/eq_fir_blob_quant.m b/tune/eq/eq_fir_blob_quant.m index f3c53fc..6d06003 100644 --- a/tune/eq/eq_fir_blob_quant.m +++ b/tune/eq/eq_fir_blob_quant.m @@ -44,15 +44,31 @@ if nargin < 2 bits = 16; end +%% Quantize [bq, shift] = eq_fir_quantize(b, bits); -nb = length(bq); +%% Check trailing zeros +nf = length(bq); +nz = nf; +while bq(nz) == 0 + nz = nz - 1; +end +if nz < nf + nb = nz + 1; + fprintf(1,'Note: Filter length was reduced to %d -> %d due to trailing zeros.\n', ... + nf, nb); + bq = bq(1:nb); +else + nb = nf; +end + +%% Make length multiple of four (optimized FIR core) mod4 = mod(nb, 4); if mod4 > 0 pad = zeros(1,4-mod4); bqp = [bq pad]; nnew = length(bqp); - fprintf(1,'Note: Filter length was %d, padded length into %d,\n', nb, nnew); + fprintf(1,'Note: Filter length was %d, padded length into %d.\n', nb, nnew); else nnew = nb; bqp = bq;