put some boundary conditions on the interpolator, helped with high frequency artefact...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 13 Jul 2017 06:48:07 +0000 (06:48 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 13 Jul 2017 06:48:07 +0000 (06:48 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3300 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/c2wideband_batch.m
codec2-dev/octave/c2wideband_fbf.m [new file with mode: 0644]
codec2-dev/octave/newamp.m

index c6031519d46092c74d0e10275eaea71d915c86c7..a57411195f100179ff7441bfa8d1e800f23a0487 100644 (file)
       $ octave
       octave:1> c2wideband_batch("../build_linux/src/speech", "mode", "generate map")
 
-    Then to run bathc simulation and generate output speech:
+    Then to run batch simulation and generate output speech:
    
        octave:1> c2wideband_batch("../build_linux/src/speech");
 
       ~/codec2-dev/build_linux/src$ ./c2sim ~/Desktop/c2_hd/speech_orig_16k.wav --Fs 16000 --phase0 --postfilter --amread speech_am.out --hmread speech_hm.out -o | play -t raw -r 16000 -s -2 - 
 #}
 
-#{
-  TODO:
-    [ ] how to generate dct coeff readout map for wideband
-        + maybe sep function
-        + save map as disk file for sucessive runs
-        + document process, special mode
-#}
 
 function [surface mean_f] = c2wideband_batch(input_prefix, varargin)
   newamp;
diff --git a/codec2-dev/octave/c2wideband_fbf.m b/codec2-dev/octave/c2wideband_fbf.m
new file mode 100644 (file)
index 0000000..4d68704
--- /dev/null
@@ -0,0 +1,92 @@
+% c2wideband_fbf.m
+%
+% Copyright David Rowe 2017
+% This program is distributed under the terms of the GNU General Public License 
+% Version 2
+%
+
+% Interactive Octave script to explore frame by frame operation of
+% wideband Codc 2.
+
+#{
+     Make sure codec2-dev is compiled with the -DDUMP option - see README for
+     instructions.
+
+     Usage:
+      ~/codec2-dev/build_linux/src$ ./c2sim ~/Desktop/c2_hd/speech_orig_16k.wav --Fs 16000 --dump speech
+
+      $ cd ~/codec2-dev/octave
+      $ octave
+      octave:1> c2wideband_fbf("../build_linux/src/speech")
+#}
+
+function c2wideband_fbf(samname, f=70, varargin)
+  more off;
+  newamp;
+
+  Fs = 16000; Fs2 = Fs/2; K = 30;
+
+  % load up text files dumped from c2sim ---------------------------------------
+
+  sn_name = strcat(samname,"_sn.txt");
+  Sn = load(sn_name);
+  sw_name = strcat(samname,"_sw.txt");
+  Sw = load(sw_name);
+  model_name = strcat(samname,"_model.txt");
+  model = load(model_name);
+  [frames tmp] = size(model);
+
+  % Keyboard loop --------------------------------------------------------------
+
+  k = ' ';
+  do 
+    s = [ Sn(2*f-1,:) Sn(2*f,:) ];
+    figure(1); clf; plot(s); axis([1 length(s) -20000 20000]);
+
+    Wo = model(f,1); L = model(f,2); Am = model(f,3:(L+2)); AmdB = 20*log10(Am);
+    Am_freqs_kHz = (1:L)*Wo*Fs2/(1000*pi);
+
+    [rate_K_vec rate_K_sample_freqs_kHz] = resample_const_rate_f_mel(model(f,:), K, Fs);
+
+    % plots ----------------------------------
+  
+    figure(2); clf; 
+    plot((1:L)*Wo*Fs2/pi, AmdB,";AmdB;g+-");
+    axis([1 Fs2 -20 80]);
+    hold on;
+    stem(rate_K_sample_freqs_kHz*1000, rate_K_vec, ";rate K;b+-");
+
+    [model_ AmdB_] = resample_rate_L(model(f,:), rate_K_vec, rate_K_sample_freqs_kHz, Fs);
+    AmdB_ = AmdB_(1:L);
+
+    plot((1:L)*Wo*Fs2/pi, AmdB_,";AmdB;r+-");
+    hold off;
+
+    % interactive menu ------------------------------------------
+
+    printf("\rframe: %d  menu: n-next  b-back  q-quit [%d]", f);
+    fflush(stdout);
+    k = kbhit();
+
+    if k == 'n'
+      f = f + 1;
+    endif
+    if k == 'b'
+      f = f - 1;
+    endif
+  until (k == 'q')
+  printf("\n");
+
+endfunction
+
+function ind = arg_exists(v, str) 
+   ind = 0;
+   for i=1:length(v)
+      if strcmp(v{i}, str)
+        ind = i;
+      end     
+    end
+endfunction
+
+
index b0e0e3c101b671ad6e27b26215adfe082fbc6231..f31e81fd6db58033a5e88a41c979dfe6d71ef6dd 100644 (file)
@@ -588,7 +588,7 @@ 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 = 160;
+  max_amp = 160; K = columns(rate_K_surface);
   [frames col] = size(model);
 
   AmdB_ = zeros(frames, max_amp);
@@ -600,7 +600,10 @@ function [model_ AmdB_] = resample_rate_L(model, rate_K_surface, rate_K_sample_f
     
     % back down to rate L
 
-    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) = interp1([0 rate_K_sample_freqs_kHz Fs/2000], 
+                            [rate_K_surface(f,1) rate_K_surface(f,:) rate_K_surface(f,K)], 
+                            rate_L_sample_freqs_kHz, 
+                            "spline");
     %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);