about to do some more enc/dec separation
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 7 Apr 2016 04:39:54 +0000 (04:39 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 7 Apr 2016 04:39:54 +0000 (04:39 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2773 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/newamp.m
codec2-dev/octave/newamp_batch.m
codec2-dev/octave/newamp_fbf.m

index a3ec6b332b6b3b128aeb907e6acd3bc316daec30..79d16aa55af756f06ed40d03582b0c0a19c0b2c2 100644 (file)
@@ -32,7 +32,7 @@
 melvq;
 
 
-function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, k=7, vq)
+function [maskdB_ maskdB_cyclic Dabs dk_ D1 ind] = decimate_in_freq(maskdB, cyclic=1, k=7, vq)
 
     % Lets try to come up with a smoothed, cyclic model.  Replace
     % points from 3500 Hz to 4000Hz with a sequence that joins without
@@ -55,26 +55,31 @@ function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, k
       D = fft(maskdB);
     end
     Dabs = abs(D);                        % this returned for plotting
+    D1 = D(1);                            % pass energy back for training
 
     % truncate D to rate k, convert to 2k length real vector for quantisation and transmission
+    % note we remove DC term as this is the frame energy that we quantise elsewhere
 
     Dk = [0 D(2:k-1) real(D(k)) D(L-k+1:L)]; 
-    dk = real(ifft(Dk));
+    dk = real(ifft(Dk));                     % Q: why is there any imag part at all?
         
     % quantisation
 
     if nargin == 4
-       [res dk_ ] = mbest(vq, dk, 4);
-       std(dk_ - dk)
+       [res dk_ vq_ind] = mbest(vq, dk, 4);
+       [D1_ D1_ind] = quantise(0:(2000/15):2500, D1);
+       ind = [vq_ind D1_ind];
+       printf(" vq: %4.1f D1: %4.1f\n", std(dk_ - dk), D1_- D1);       
     else
        dk_ = dk;
+       D1_ = D1;
     end
 
     % convert quantised dk back to rate L magnitude spectrum
 
     Dk_ = fft(dk_);
     D_ = zeros(1,L);
-    D_(1) = D(1);                         % lets assume energy comes through separately
+    D_(1) = D1;                           % energy seprately quantised
     D_(2:k-1) = Dk_(2:k-1);
     D_(L-k+1:L) = Dk_(k+1:2*k);
     d_ = ifft(D_);                        % back to spectrum at rate L
@@ -86,10 +91,11 @@ function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, k
     ypts = [ maskdB_(anchor-1) maskdB_(anchor) (maskdB_(anchor)-10)];
     mask_pp = splinefit(xpts, ypts, 1);
     maskdB_ = [maskdB_(1:anchor) ppval(mask_pp, anchor+1:L)];
-
+   
 endfunction
 
 
+
 function tp = est_pf_locations(maskdB_)
   % find turning points - used for finding PF freqs when we decimate in time
 
@@ -503,7 +509,7 @@ endfunction
 
 % quantise input sample to nearest value in table, optionally return bianry code
 
-function [quant_out bits] = quantise(levels, quant_in)
+function [quant_out best_i bits] = quantise(levels, quant_in)
 
   % find closest quantiser level
 
@@ -753,7 +759,7 @@ function maskdB_ = decimate_frame_rate(model, decimate, f, frames, mask_sample_f
     left_fraction  = 1 - mod((f-1),decimate)/decimate;
     right_fraction = 1 - left_fraction;
 
-    printf("f: %d left_f: %d right_f: %d left_fraction: %f right_fraction: %f \n", f, left_f, right_f, left_fraction, right_fraction)
+    printf("f: %d left_f: %d right_f: %d left_fraction: %3.2f right_fraction: %3.2f \n", f, left_f, right_f, left_fraction, right_fraction)
 
     % fit splines to left and right masks
 
index 3c6db1ed9d9e0f61f305a089f38043f373468351..b2f9559cc16cfe52a659cea744431386f0f5a859 100644 (file)
@@ -16,7 +16,7 @@
 
 % process a whole file and write results
 
-function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_name)
+function [dk_log D1_log] = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_name)
   newamp;
   more off;
 
@@ -26,7 +26,7 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
   dec_in_time = 1;
   synth_phase = 1;
   vq_en = 1;
-  dk_log = [];
+  D_log = []; dk_log = []; D1_log = []; ind_log = [];
   train = 0;
 
   model_name = strcat(samname,"_model.txt");
@@ -92,25 +92,29 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
        maskdB_(a_non_masked_m) = maskdB_(a_non_masked_m) + 9;
     end
 
-    AmdB_ = maskdB;
+    AmdB_ = AmdB;
     if dec_in_freq
       if vq_en
-        [AmdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 10, vq);
+        [AmdB_ tmp1 Dabs dk_ D1 ind] = decimate_in_freq(maskdB, 1, 10, vq);
+        ind_log = [ind_log; ind];
       else
-        [AmdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 10);
+        [AmdB_ tmp1 D dk_ D1] = decimate_in_freq(maskdB, 0, 10);
+      end
+      if train
+        dk_log = [dk_log; dk_];
+        D1_log = [D1_log D1];
       end
-      dk_log = [dk_log; dk_];
     end
+    %AmdB_(1:L/8) = maskdB(1:L/8);
     AmdB_pf = AmdB_*1.5;
     AmdB_pf += max(AmdB_) - max(AmdB_pf);
-    %sd_sum += sum(maskdB - AmdB_pf);
+    sd_sum += std(maskdB - AmdB_);
     %AmdB_pf = AmdB_;
 
     Am_ = zeros(1,max_amp);
     Am_ = 10 .^ (AmdB_pf(1:L-1)/20); 
     model_(f,3:(L+1)) = Am_;
   end
-  printf("\nsd_sum: %5.2f\n", sd_sum/frames);
 
   % decoder loop -----------------------------------------------------
 
@@ -202,6 +206,7 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
     fclose(faw);
   end
 
+  printf("\nsd_sum: %5.2f\n", sd_sum/frames);
   printf("\n");
 endfunction
 
index c3d1bb63289078b24aae9725afc502f0dfabab3e..2cbe3154204c171ab2335b71d76b2eb690bb99ee 100644 (file)
@@ -23,7 +23,7 @@ function newamp_fbf(samname, f=10)
   dec_in_freq = 1;
   dec_in_time = 0;
   vq_en = 0;
-  mask_en = 0;
+  mask_en = 1;
 
   % load up text files dumped from c2sim ---------------------------------------
 
@@ -69,30 +69,33 @@ function newamp_fbf(samname, f=10)
     %plot(Am_freqs_kHz*1000, maskdB, ';mask;g');
 
     if mask_en
-      AmdB_ = maskdB;
+      AmdB_ = AmdB = maskdB;
     else
-      AmdB_ = AmdB;
+      AmdB_ = AmdB = AmdB;
     end
     if dec_in_freq
       [tmp1 tmp2 D] = decimate_in_freq(AmdB, 0);
       if vq_en
         [AmdB_ AmdB_cyclic D_cyclic dk_] = decimate_in_freq(AmdB, 1, 10, vq);
+        plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc vq;c');
       else
         [AmdB_ AmdB_cyclic D_cyclic dk_] = decimate_in_freq(AmdB_, 1, 10);
+        plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc;c');
       end
 
       plot(Am_freqs_kHz*1000, AmdB_cyclic, ';mask cyclic;b');
-      plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc;c');
       AmdB_pf = AmdB_*(1.5);
-      AmdB_pf += mean(AmdB) - mean(AmdB_pf);
+      AmdB_pf += max(AmdB_) - max(AmdB_pf);
       %max(AmdB_pf)-max(AmdB_)
       %AmdB_pf -= max(AmdB_pf)-max(AmdB_);
     end
 
     %AmdB_pf = AmdB_*(1.5);
     %AmdB_pf += mean(AmdB) - mean(AmdB_pf);
-    AmdB_pf = AmdB_;
-    plot(Am_freqs_kHz*1000, AmdB_pf, ';mask trunc pf;g');
+    %AmdB_pf = AmdB_;
+
+    %plot(Am_freqs_kHz*1000, AmdB_pf, ';after pf;g');
+    axis([0 4000 20 80]);
 
     % Optional decimated parameters
     %   need to general model_ parameters either side
@@ -132,7 +135,8 @@ function newamp_fbf(samname, f=10)
 
       figure(5)
       clf
-      stem(dk_)
+      stem(dk_);
+      axis([0 20 -60 60])
     end
 
     % interactive menu ------------------------------------------