From 1c25bbc96121f10cd1a6756d06faddf64da6de7e Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 11 Aug 2017 07:47:14 +0000 Subject: [PATCH] reas results with 2 bit slope and 1 bit mag quantiser 1-3k, with dec by 4, and refactored to quantiser callbacks git-svn-id: https://svn.code.sf.net/p/freetel/code@3352 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/closed_quant_slope.m | 3 +++ codec2-dev/octave/open_quant_slope.m | 4 ++++ codec2-dev/octave/vq_search_slope.m | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 codec2-dev/octave/closed_quant_slope.m create mode 100644 codec2-dev/octave/open_quant_slope.m diff --git a/codec2-dev/octave/closed_quant_slope.m b/codec2-dev/octave/closed_quant_slope.m new file mode 100644 index 00000000..7d5a465b --- /dev/null +++ b/codec2-dev/octave/closed_quant_slope.m @@ -0,0 +1,3 @@ +function b = closed_quant_slope(b) + b(1) = max(0.5, b(1)); +end diff --git a/codec2-dev/octave/open_quant_slope.m b/codec2-dev/octave/open_quant_slope.m new file mode 100644 index 00000000..20965547 --- /dev/null +++ b/codec2-dev/octave/open_quant_slope.m @@ -0,0 +1,4 @@ +function b = open_quant_slope(b) + b(2) = quantise([-1 -0.5 0.5 1], b(2)); + b(1) = quantise([0.5 1.0], b(1)); +end diff --git a/codec2-dev/octave/vq_search_slope.m b/codec2-dev/octave/vq_search_slope.m index f0c6cb82..7f4d3349 100644 --- a/codec2-dev/octave/vq_search_slope.m +++ b/codec2-dev/octave/vq_search_slope.m @@ -27,9 +27,9 @@ function [idx contrib errors b_log2] = vq_search_slope(vq, data, closed_quant_fn for i=1:nVec c = [sum(target) target*(1:nCols)' target*vq(i,:)' ]'; b = inv(A(:,:,i))*c; - if nargin == 3; + if nargin >= 3; b = feval(closed_quant_fn,b); - end; + end b_log(i,:) = b; diff(i,:) = target - (b(1)*vq(i,:) + b(2)*(1:nCols) + b(3)); @@ -43,9 +43,17 @@ function [idx contrib errors b_log2] = vq_search_slope(vq, data, closed_quant_fn errors(f) = mn; idx(f) = min_ind(1); b = b_log(min_ind,:); - b_log2(f,:) = b; + + % optional quantisation performed after error min loop + % - note we recalc gain to match energy after quantisation - %printf("f: %d i: %d mg: %f sl: %f g: %f\n", f, idx(f), b(1), b(2), b(3)); + if nargin == 4 + b = feval(open_quant_fn, b); + b(3) = (sum(target) - sum(b(1)*vq(min_ind,:) + b(2)*(1:nCols)))/nCols; + end + + printf("f: %d i: %d mg: %f sl: %f g: %f\n", f, idx(f), b(1), b(2), b(3)); + b_log2(f,:) = b; contrib(f,:) = b(1)*vq(min_ind,:) + b(2)*(1:nCols) + b(3); end -- 2.25.1