improved corner cases in rate K resampling, back to splines for now, plotting poor...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 23 Jun 2017 20:07:43 +0000 (20:07 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 23 Jun 2017 20:07:43 +0000 (20:07 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3240 01035d8c-6547-0410-b346-abe4f91aad63

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

index 3b40b92f81a86bbc8304780209b8ff470e8b13d1..b1b8df4caa510ff0624e3f018c77f6dc2f3b25f5 100644 (file)
@@ -518,10 +518,10 @@ function [rate_K_surface rate_K_sample_freqs_kHz] = resample_const_rate_f(model,
 
     rate_L_sample_freqs_kHz = (1:L)*Wo*Fs/(2000*pi);
     
-    %rate_K_surface(f,:) = interp1(rate_L_sample_freqs_kHz, AmdB, rate_K_sample_freqs_kHz, "spline", "extrap");
-    rate_K_surface(f,:)  = interp_para(rate_L_sample_freqs_kHz, AmdB, Fs/(2*1000), rate_K_sample_freqs_kHz);    
+    rate_K_surface(f,:) = interp1(rate_L_sample_freqs_kHz, AmdB, rate_K_sample_freqs_kHz, "spline", "extrap");
+    %rate_K_surface(f,:)  = interp_para(rate_L_sample_freqs_kHz, AmdB, Fs/(2*1000), rate_K_sample_freqs_kHz);    
 
-    %printf("\r%d/%d", f, frames);
+    %printf("%d\n", f);
   end
   %printf("\n");
 endfunction
@@ -588,9 +588,10 @@ endfunction
 % Take a rate K surface and convert back to time varying rate L
 
 function [model_ AmdB_] = resample_rate_L(model, rate_K_surface, rate_K_sample_freqs_kHz, Fs=8000)
-  max_amp = 1600;
+  max_amp = 160;
   [frames col] = size(model);
 
+  AmdB_ = zeros(frames, max_amp);
   model_ = zeros(frames, max_amp+2);
   for f=1:frames
     Wo = model(f,1);
@@ -599,10 +600,10 @@ function [model_ AmdB_] = resample_rate_L(model, rate_K_surface, rate_K_sample_f
     
     % back down to rate L
 
-    % AmdB_ = interp1(rate_K_sample_freqs_kHz, rate_K_surface(f,:), rate_L_sample_freqs_kHz, "spline", 0);
-    AmdB_ = interp_para(rate_K_sample_freqs_kHz, rate_K_surface(f,:), Fs/(2*1000), rate_L_sample_freqs_kHz);
-
-    model_(f,1) = Wo; model_(f,2) = L; model_(f,3:(L+2)) = 10 .^ (AmdB_(1:L)/20);
+    AmdB_(f,1:L) = interp1(rate_K_sample_freqs_kHz, rate_K_surface(f,:), rate_L_sample_freqs_kHz, "spline", rate_K_surface(f,1));
+    %AmdB_(f,1:L) = interp_para(rate_K_sample_freqs_kHz, rate_K_surface(f,:), Fs/(2*1000), rate_L_sample_freqs_kHz);
+    %printf("f: %d %f %f %f\n", f, rate_K_sample_freqs_kHz(1), rate_L_sample_freqs_kHz(1), AmdB_(1));
+    model_(f,1) = Wo; model_(f,2) = L; model_(f,3:(L+2)) = 10 .^ (AmdB_(f, 1:L)/20);
    end
 endfunction
 
@@ -1553,7 +1554,7 @@ function [AmdB_ residual fvec fvec_ amps] = piecewise_model(AmdB, Wo, vq, vq_m)
     plot(mask_sample_freqs_kHz, residual);
     end
 
-    %printf("\nfr1: %f fr2: %f fr3: %f fr4: %f\n", fr1, fr2, fr3, fr4);
+    printf("\nfr1: %f fr2: %f fr3: %f fr4: %f\n", fr1, fr2, fr3, fr4);
     [fvec fvec_ind] = sort([fr1 fr2 fr3 fr4]);
     amps = amp(fvec_ind(1:4));
 
index 24ab999481ac5325859ea7cfe686ee987fe74e73..0010c3776fd4d0868dfdc63303f6081bd94fced7 100644 (file)
@@ -124,6 +124,7 @@ function surface = newamp1_batch(input_prefix, varargin)
   for f=1:frames
     %printf("%d ", f);   
     Wo = model_(f,1); L = min([model_(f,2) max_amp-1]); Am = model_(f,3:(L+2));
+    assert(Wo*L < pi);
 
     Am_ = zeros(1,max_amp); Am_(2:L) = Am(1:L-1); fwrite(fam, Am_, "float32");
     fwrite(fWo, Wo, "float32");
@@ -186,6 +187,13 @@ endfunction
 function [model_ rate_K_surface] = experiment_const_freq(model, mean_removal, vq_filename)
   [frames nc] = size(model);
   Fs = 8000;
+  fg = 1;
+
+  energy = zeros(1,frames);
+  for f=1:frames
+    L = model(f,2);
+    energy(f) = 10*log10(sum( model(f,3:(L+2)) .^ 2 ));
+  end
 
   melvq;
   if length(vq_filename) 
@@ -194,7 +202,7 @@ function [model_ rate_K_surface] = experiment_const_freq(model, mean_removal, vq
     size(vq)
   end
 
-  rate_K_sample_freqs_kHz = [0.1:0.1:3.9];
+  rate_K_sample_freqs_kHz = [0.1:0.1:4];
   K = length(rate_K_sample_freqs_kHz);
   rate_K_surface = resample_const_rate_f(model, rate_K_sample_freqs_kHz, Fs);
 
@@ -209,13 +217,8 @@ function [model_ rate_K_surface] = experiment_const_freq(model, mean_removal, vq
   if length(vq_filename) 
     [res rate_K_surface_ ind] = mbest(vq, rate_K_surface, m);
     sd_per_frame = std(res');
-    energy = zeros(1,frames);
-    for f=1:frames
-      L = model(f,2);
-      energy(f) = 10*log10(sum( model(f,3:(L+2)) .^ 2 ));
-    end
-    figure(1); subplot(211); plot(energy); subplot(212); plot(sd_per_frame);
-    figure(2); hist(sd_per_frame);
+    figure(fg++); subplot(211); plot(energy); subplot(212); plot(sd_per_frame);
+    figure(fg); hist(sd_per_frame);
     printf("VQ rms SD: %3.2f\n", mean(sd_per_frame));
   else
     rate_K_surface_ = rate_K_surface;
@@ -229,14 +232,26 @@ function [model_ rate_K_surface] = experiment_const_freq(model, mean_removal, vq
 
   [model_ AmdB_] = resample_rate_L(model, rate_K_surface_, rate_K_sample_freqs_kHz, Fs);
 
-  sum_sd = 0;
+  % Measure distortion between AmdB and AmdB_, ths includes distortion
+  % in the rate K <-> L transition.  Can optionally plot distorted
+  % frames
+
+  plot_sd_thresh = 10;
+  sd = zeros(1,frames);
   for f=1:frames
+    Wo = model(f,1);
     L = model(f,2);
     AmdB = 20*log10(model(f,3:(L+2)));
-    sum_sd = std(AmdB(1:L) - AmdB_(f,1:L));
+    sd(f) = std(AmdB(1:L) - AmdB_(f,1:L));
+    if sd(f) > plot_sd_thresh
+      printf("fg: %d f: %d\n", fg, f);
+      figure(fg++); clf; plot((1:L)*Wo*4/pi, AmdB(1:L),'b+-'); hold on; plot((1:L)*Wo*4/pi, AmdB_(f,1:L),'r+-');
+      plot(rate_K_sample_freqs_kHz, rate_K_surface_(f,:), 'c+-'); hold off;
+    end
   end
-  printf("rate K resampling SD: %3.2f\n", mean(sum_sd));
-
+  printf("rate K resampling SD: %3.2f\n", mean(sd));
+  figure(fg++); clf; subplot(211); plot(energy); subplot(212); plot(sd);
+  figure(fg++); clf; hist(sd);
 endfunction