Advertisement
Guest User

CPP/CPA Algo'

a guest
Jan 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.90 KB | None | 0 0
  1. -----
  2. Version #1
  3. -----
  4. % define model
  5. f1 = 1100;              % frequency of tone generator 1; unit: Hz
  6. f2 = 2900;              % frequency of tone generator 2; unit: Hz
  7. Ts = 1/(40*max(f1,f2)); % sampling period; unit: s
  8. dMic = 1;               % distance between microphones centered about origin; unit: m
  9. dSrc = 10;              % distance between tone generators centered about origin; unit: m
  10. c = 340.29;             % speed of sound; unit: m / s
  11.  
  12. % generate tones
  13. figure(1);
  14. t = [0:Ts:0.025];
  15. tone1 = sin(2*pi*f1*t);
  16. tone2 = sin(2*pi*f2*t);
  17. plot(t,tone1);
  18. hold on;
  19. plot(t,tone2,'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -1 1]); legend('tone 1', 'tone 2');
  20. hold off;
  21.  
  22. % mix tones at microphones
  23. % assume inverse square attenuation of sound intensity (i.e., inverse linear attenuation of sound amplitude)
  24. figure(2);
  25. dNear = (dSrc - dMic)/2;
  26. dFar = (dSrc + dMic)/2;
  27. mic1 = 1/dNear*sin(2*pi*f1*(t-dNear/c)) + \
  28.        1/dFar*sin(2*pi*f2*(t-dFar/c));
  29. mic2 = 1/dNear*sin(2*pi*f2*(t-dNear/c)) + \
  30.        1/dFar*sin(2*pi*f1*(t-dFar/c));
  31. plot(t,mic1);
  32. hold on;
  33. plot(t,mic2,'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -1 1]); legend('mic 1', 'mic 2');
  34. hold off;
  35.  
  36. % use svd to isolate sound sources
  37. figure(3);
  38. x = [mic1' mic2'];
  39. [W,s,v]=svd((repmat(sum(x.*x,1),size(x,1),1).*x)*x');
  40. plot(t,v(:,1));
  41. hold on;
  42. maxAmp = max(v(:,1));
  43. plot(t,v(:,2),'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -maxAmp maxAmp]); legend('isolated tone 1', 'isolated tone 2');
  44. hold off;
  45. ====================================================
  46. -----
  47. Version #2
  48. -----
  49.  
  50. [x1, Fs1] = audioread('mixed1.wav');
  51. [x2, Fs2] = audioread('mixed2.wav');
  52. xx = [x1, x2]';
  53. yy = sqrtm(inv(cov(xx')))*(xx-repmat(mean(xx,2),1,size(xx,2)));
  54. [W,s,v] = svd((repmat(sum(yy.*yy,1),size(yy,1),1).*yy)*yy');
  55. a = W*xx;
  56. audiowrite('refined1.wav', a(1,:), Fs1);
  57. audiowrite('refined2.wav', a(2,:), Fs1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement