2
0

twotone.m 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. % twotone.m
  2. % David Rowe Aug 2012
  3. % Used to experiment with combining phase of two tones
  4. function cbphase
  5. Wo = 100.0*pi/4000;
  6. L = floor(pi/Wo);
  7. phi = zeros(1,L);
  8. % two harmonics
  9. a = 20; b = 21;
  10. % set up phases to whatever
  11. phi(a) = -pi;
  12. phi(b) = -pi/2;
  13. % synthesis the two-tone signal
  14. N = 16000;
  15. Nplot = 250;
  16. s = zeros(1,N);
  17. for m=a:b
  18. s_m = cos(m*Wo*(0:(N-1)) + phi(m));
  19. s = s + s_m;
  20. endfor
  21. % now our theory says that this signal should be the same perceptually
  22. phi_(a) = (phi(a) - phi(b))/2;
  23. phi_(b) = (phi(b) - phi(a))/2;
  24. s_ = zeros(1,N);
  25. for m=a:b
  26. s_m = cos(m*Wo*(0:(N-1)) + phi_(m));
  27. s_ = s_ + s_m;
  28. endfor
  29. % plot them and see if envelope has the same phase, but "carriers"
  30. % have different phase
  31. figure(1);
  32. clf;
  33. subplot(211);
  34. plot(s(1:Nplot));
  35. subplot(212);
  36. plot(s_(1:Nplot),'r');
  37. endfunction