scripts to test resampling
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 10 Mar 2011 06:48:51 +0000 (06:48 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 10 Mar 2011 06:48:51 +0000 (06:48 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@282 01035d8c-6547-0410-b346-abe4f91aad63

codec2/octave/plresample.m [new file with mode: 0644]
codec2/octave/quadinterp.m [new file with mode: 0644]

diff --git a/codec2/octave/plresample.m b/codec2/octave/plresample.m
new file mode 100644 (file)
index 0000000..53eae59
--- /dev/null
@@ -0,0 +1,98 @@
+% Copyright David Rowe 2009
+% This program is distributed under the terms of the GNU General Public License 
+% Version 2
+%
+% Plot resampled ampltiude modelling information from dump files.
+
+function plresample(samname, f)
+  
+  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);
+
+  modelq_name = strcat(samname,"_qmodel.txt");
+  if (file_in_path(".",modelq_name))
+    modelq = load(modelq_name);
+  endif
+
+  resample_name = strcat(samname,"_res.txt");
+  if (file_in_path(".",resample_name))
+    resample = load(resample_name);
+  endif
+
+  k = ' ';
+  do 
+    figure(1);
+    clf;
+    s = [ Sn(2*f-1,:) Sn(2*f,:) ];
+    plot(s);
+    axis([1 length(s) -20000 20000]);
+
+    figure(2);
+    Wo = model(f,1);
+    L = model(f,2);
+    Am = model(f,3:(L+2));
+    plot((1:L)*Wo*4000/pi, 20*log10(Am),";Am;r");
+    axis([1 4000 -10 80]);
+    hold on;
+    plot((0:255)*4000/256, Sw(f,:),";Sw;");
+     
+    if (file_in_path(".",modelq_name))
+      Amq = modelq(f,3:(L+2));
+      plot((1:L)*Wo*4000/pi, 20*log10(Amq),";Amq;g" );
+      signal = Am * Am';
+      noise = (Am-Amq) * (Am-Amq)'; 
+      snr1 = 10*log10(signal/noise);
+      Am_err_label = sprintf(";Am error SNR %4.2f dB;m",snr1);
+      plot((1:L)*Wo*4000/pi, 20*log10(Amq) - 20*log10(Am), Am_err_label);
+      %Am(1:4)
+      %Amq(1:4)
+    endif
+
+    if (file_in_path(".",resample_name))
+       Wo_r = resample(f,1);
+        L_r = resample(f,2);
+        Am_r = resample(f,3:(L_r+2));
+        plot((1:L_r)*Wo_r*4000/pi, 20*log10(Am_r(1:L_r)),"+;Amres;c" );
+        %Am_r(1:4)
+    endif
+
+    hold off;
+
+    % interactive menu
+
+    printf("\rframe: %d  menu: n-next  b-back  p-png  q-quit", f);
+    fflush(stdout);
+    k = kbhit();
+    if (k == 'n')
+      f = f + 1;
+    endif
+    if (k == 'b')
+      f = f - 1;
+    endif
+
+    % optional print to PNG
+
+    if (k == 'p')
+      figure(1);
+      pngname = sprintf("%s_%d_sn.png",samname,f);
+      print(pngname, '-dpng', "-S500,500")
+      pngname = sprintf("%s_%d_sn_large.png",samname,f);
+      print(pngname, '-dpng', "-S800,600")
+
+      figure(2);
+      pngname = sprintf("%s_%d_sw.png",samname,f);
+      print(pngname, '-dpng', "-S500,500")
+      pngname = sprintf("%s_%d_sw_large.png",samname,f);
+      print(pngname, '-dpng', "-S1200,800")
+    endif
+
+  until (k == 'q')
+  printf("\n");
+
+endfunction
diff --git a/codec2/octave/quadinterp.m b/codec2/octave/quadinterp.m
new file mode 100644 (file)
index 0000000..7e080fe
--- /dev/null
@@ -0,0 +1,21 @@
+% quadinterp.m
+% David Rowe 10/3/11
+
+x_1 = -10; y_1 = 1;
+x0 = 0; y0 = 3;
+x1 = 2; y1 = 2;
+
+plot([ x_1 x0 x1 ], [y_1 y0 y1], "r+");
+
+c = y0
+a = (y_1*x1 - y1*x_1 + c*x_1 - c*x1)/(x_1*x_1*x1 - x1*x1*x_1)
+b = (y1 -a*x1*x1 - c)/x1
+polyfit([x_1 x0 x1],[y_1 y0 y1],2)
+
+hold on;
+for x = -11:0.25:3;
+    y = a*x*x + b*x + c;
+    plot(x,y,'o');
+end
+hold off;
+