first pass VQ, about to add AbyS peak finding for last two resonators
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 6 Dec 2016 23:34:07 +0000 (23:34 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 6 Dec 2016 23:34:07 +0000 (23:34 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2926 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/newamp.m
codec2-dev/octave/newamp1_batch.m
codec2-dev/octave/newamp1_fbf.m

index 54b66c23f15db07e72d2415e046735db26616e59..31f00dab7a619934b85c46a6f57260f293b31a13 100644 (file)
@@ -861,7 +861,7 @@ function [v] = est_voicing_bits(v1, v5)
 endfunction
 
 
-function [AmdB_ residual] = piecewise_model(AmdB, Wo
+function [AmdB_ residual fvec fvec_] = piecewise_model(AmdB, Wo, vq, vq_m
     L = length(AmdB);
     l1000 = floor(L/4);     
     AmdB_ = ones(1,L);
@@ -872,6 +872,7 @@ function [AmdB_ residual] = piecewise_model(AmdB, Wo)
     fmin = 0.150;
     lmin = floor(L*fmin/4);
     [mx mx_ind] = max(AmdB(lmin+1:l1000));
+    amp(1) = mx;
     mx_ind += lmin;
     AmdB_ = parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx;  
 
@@ -879,9 +880,10 @@ function [AmdB_ residual] = piecewise_model(AmdB, Wo)
 
     fr1 = mx_ind*Wo*4/pi;
     fmin = 1;
-    lmin = round(L*fmin/4);
+    lmin = round(fmin*L/4);
 
     [mx mx_ind] = max(AmdB(lmin+1:L));
+    amp(2) = mx;
     mx_ind += lmin;
     AmdB_ = max(AmdB_, parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx);  
     fr2 = mx_ind*Wo*4/pi;
@@ -889,7 +891,7 @@ function [AmdB_ residual] = piecewise_model(AmdB, Wo)
     % fit a third resonator, must be +/- 300 Hz after 2nd resonator
 
     residual = AmdB;
-    residual(1:lmin) = 0;
+    residual(1:lmin) = -40;
 
     fr2 = mx_ind*Wo*4/pi;
     fmin = fr2 - 0.300;
@@ -897,14 +899,41 @@ function [AmdB_ residual] = piecewise_model(AmdB, Wo)
     
     lmin = max(1, round(L*fmin/4));
     lmax = min(L, round(L*fmax/4));
-    residual(lmin:lmax) = 0;
+    residual(lmin:lmax) = -40;
 
     [mx mx_ind] = max(residual);
+    amp(3) = mx;
     AmdB_ = max(AmdB_, parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx);  
     fr3 = mx_ind*Wo*4/pi;
    
+    % 4th resonator 
+
+    fmin = fr3 - 0.300;
+    fmax = fr3 + 0.300;
+    
+    lmin = max(1, round(L*fmin/4));
+    lmax = min(L, round(L*fmax/4));
+    residual(lmin:lmax) = 0;
+    [mx mx_ind] = max(residual);
+    amp(4) = mx;
+    AmdB_ = max(AmdB_, parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx);  
+    fr4 = mx_ind*Wo*4/pi;
+
     %figure(3);
     %plot(mask_sample_freqs_kHz, residual);
 
-    printf("\nfr1: %f fr2: %f fr3: %f\n", fr1, fr2, fr3);
+    %printf("\nfr1: %f fr2: %f fr3: %f fr4: %f\n", fr1, fr2, fr3, fr4);
+    [fvec fvec_ind] = sort([fr1 fr2 fr3 fr4]);
+
+    % optional VQ of freqeuncies
+    if nargin == 4
+      AmdB_ = ones(1,L);
+      [mes fvec_ ind] = mbest(vq, fvec, vq_m);
+      for i=1:4
+        an_amp = amp(fvec_ind(i));
+        AmdB_ = max(AmdB_, parabolic_resonator(fvec_(i), mask_sample_freqs_kHz) + an_amp);      
+      end
+    end
+
 endfunction
index e58879aeb085fad4ade972b5048e6bb6be0b8dfb..e2c75ef31c5cb1adde96195b64221f8e1d3f6878 100644 (file)
 % Or with a little more processing:
 %   codec2-dev/build_linux/src$ ./c2sim ../../raw/hts2a.raw --amread hts2a_am.out --awread hts2a_aw.out --phase0 --postfilter --Woread hts2a_Wo.out -o - | play -q -t raw -r 8000 -s -2 -
 
-
 % process a whole file and write results
 
-function  newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
+function fvec_log = newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
   newamp;
   more off;
 
   max_amp = 80;
+  load vq;
 
   model_name = strcat(samname,"_model.txt");
   model = load(model_name);
@@ -38,6 +38,8 @@ function  newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
 
   % encoder loop ------------------------------------------------------
 
+  fvec_log = [];
+
   for f=1:frames
     printf("%d ", f);   
 
@@ -55,7 +57,8 @@ function  newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
     AmdB_(mx_ind) += 6;
     #}
 
-    AmdB_ = piecewise_model(AmdB, Wo);
+    [AmdB_ res fvec] = piecewise_model(AmdB, Wo, vq, 2);
+    fvec_log = [fvec_log; fvec];
     #{
     l1000 = floor(L/4);     
     AmdB_ = AmdB;
index e170721d2f3e696eb3d4adf7abc8c315bfc50215..1cc8e4ca95f5a04e87c6adbee00a0a17833b49eb 100644 (file)
@@ -19,8 +19,9 @@
 function newamp1_fbf(samname, f=10)
   newamp;
   more off;
-  plot_spectrum = 1;
-  mask_en = 1;
+  quant_en = 0;
+
+  load vq;
 
   % load up text files dumped from c2sim ---------------------------------------
 
@@ -57,7 +58,11 @@ function newamp1_fbf(samname, f=10)
     AmdB_(mx_ind) += 6;
     #}
 
-    [AmdB_ residual] = piecewise_model(AmdB, Wo);
+    if quant_en
+      [AmdB_ residual fvec fvec_] = piecewise_model(AmdB, Wo, vq, 2);
+    else
+      [AmdB_ residual fvec] = piecewise_model(AmdB, Wo);
+    end
 
     figure(2);
     clf;
@@ -67,21 +72,24 @@ function newamp1_fbf(samname, f=10)
     hold on;
     plot((1:L)*Wo*4000/pi, AmdB,";Am;r+-");
     plot(Am_freqs_kHz*1000, AmdB_, ';model;c');
-    plot(Am_freqs_kHz*1000, residual, ';model;g');
+    plot(fvec*1000, 60*ones(1,4), ';fvec;go');
+    if quant_en
+      plot(fvec_*1000, 60*ones(1,4), ';fvec q;ro');
+    end
 
     hold off;
 
     % interactive menu ------------------------------------------
 
-    printf("\rframe: %d  menu: n-next  b-back  q-quit  m-mask_en", f);
+    printf("\rframe: %d  menu: n-next  b-back  q-quit  m-quant_en", f);
     fflush(stdout);
     k = kbhit();
 
     if (k == 'm')
-      if mask_en
-        mask_en = 0;
+      if quant_en
+        quant_en = 0;
       else
-        mask_en = 1; 
+        quant_en = 1; 
       end
     endif
     if (k == 'n')