phase experiment scripts
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 31 Aug 2009 01:41:55 +0000 (01:41 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 31 Aug 2009 01:41:55 +0000 (01:41 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@35 01035d8c-6547-0410-b346-abe4f91aad63

codec2/octave/phase.m [new file with mode: 0644]
codec2/octave/pulse.m [new file with mode: 0644]

diff --git a/codec2/octave/phase.m b/codec2/octave/phase.m
new file mode 100644 (file)
index 0000000..859dde8
--- /dev/null
@@ -0,0 +1,43 @@
+% phase.m
+% David Rowe August 2009
+% experiments with phase for sinusoidal codecs
+
+function phase(samname, F0, randphase, png)
+  Wo=2*pi*F0/8000;
+  P=2*pi/Wo;
+  L = floor(pi/Wo);
+  N = 16000;
+  A = 10000/L;
+  phi = zeros(1,L);
+  if (randphase == 1) 
+    rand("seed",0);
+    phi = rand(L,1)*2*pi;
+  endif
+  s = zeros(1,N);
+
+  for m=1:L
+    s = s + A*cos(m*Wo*(0:(N-1)) + phi(m));
+  endfor
+
+  figure(1);
+  clg;
+  plot(s(1:250));
+
+  fs=fopen(samname,"wb");
+  fwrite(fs,s,"short");
+  fclose(fs);
+
+  if png
+      % small image to fit blog
+
+      __gnuplot_set__ terminal png size 450,300
+      ss = sprintf("__gnuplot_set__ output \"%s.png\"", samname);
+      eval(ss)
+      replot;
+
+      % for some reason I need this to stop large plot getting wiped
+      __gnuplot_set__ output "/dev/null"
+  endif
+
+endfunction
+
diff --git a/codec2/octave/pulse.m b/codec2/octave/pulse.m
new file mode 100644 (file)
index 0000000..7df4a8d
--- /dev/null
@@ -0,0 +1,32 @@
+% pulse.m
+% David Rowe August 2009
+% experiments with phase for sinusoidal codecs
+%   - lets see how pulse waveforms are perceived at different F0
+%   - experiment suggested by O'Shaughnessy, "Speech Communication", page 145
+%   - in low F0 alternative phase pulses are perceived as 2F0
+
+function pulse(samname, F0, alternate)
+  Wo = 2*pi*F0/8000;
+  P  = 2*pi/Wo
+  L  = floor(pi/Wo);
+  N  = 16000;
+  A  = 1000;
+  phi = zeros(1,L);
+  if (alternate == 1) 
+    % shift phases of some harmonics to introduce -ve pulses
+    % note magnitude spectrum unchanged
+    phi(2:2:L) = (2:2:L)*pi*(P)*Wo;
+  endif
+  s = zeros(1,N);
+
+  for m=1:L
+    s = s + A*cos(m*Wo*(0:(N-1)) + phi(m));
+  endfor
+
+  plot(s(1:250));
+
+  fs=fopen(samname,"wb");
+  fwrite(fs,s,"short");
+  fclose(fs);
+endfunction
+