2
0

phase.m 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. % phase.m
  2. % David Rowe August 2009
  3. % experiments with phase for sinusoidal codecs
  4. function phase(samname, F0, png)
  5. Wo=2*pi*F0/8000;
  6. P=2*pi/Wo;
  7. L = floor(pi/Wo);
  8. Nsam = 16000;
  9. N = 80;
  10. F = Nsam/N;
  11. A = 10000/L;
  12. phi = zeros(1,L);
  13. s = zeros(1,Nsam);
  14. for m=floor(L/2):L
  15. phi_off(m) = -m*Wo*8;
  16. end
  17. for f=1:F
  18. phi(1) = phi(1) + Wo*N;
  19. phi(1) = mod(phi(1),2*pi);
  20. for m=1:L
  21. phi(m) = m*phi(1);
  22. end
  23. x = zeros(1,N);
  24. for m=1:L
  25. x = x + A*cos(m*Wo*(0:(N-1)) + phi(m));
  26. endfor
  27. s((f-1)*N+1:f*N) = x;
  28. endfor
  29. figure(1);
  30. clf;
  31. plot(s(1:250));
  32. fs=fopen(samname,"wb");
  33. fwrite(fs,s,"short");
  34. fclose(fs);
  35. if (nargin == 3)
  36. % small image to fit blog
  37. __gnuplot_set__ terminal png size 450,300
  38. ss = sprintf("__gnuplot_set__ output \"%s.png\"", samname);
  39. eval(ss)
  40. replot;
  41. % for some reason I need this to stop large plot getting wiped
  42. __gnuplot_set__ output "/dev/null"
  43. endif
  44. endfunction