Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.42 KB | None | 0 0
  1. clc, clear, close all
  2.  
  3. [x, Fs1] = audioread('whitenoise2018.wav');
  4. [y, Fs2] = audioread('whitenoise_rec2018.wav');
  5.  
  6. dt = 10/length(x);
  7. T = 10;
  8. t = 0:dt:T-dt;
  9. fs = Fs1;
  10.  
  11.  
  12.  
  13. X = fft(x);
  14. Y = fft(y);
  15.  
  16. Rxx = xcorr(x,x);
  17. Rxy = xcorr(x,y);
  18.  
  19. subplot(2,1,1);
  20. plot((-length(Rxx)/2 : length(Rxx)/2-1)/fs*1000, Rxx)   %s->ms
  21. axis tight;
  22. xlabel('time [ms]');
  23. ylabel('Rxx');
  24. title('Autokorelacja Rxx');
  25. grid on;
  26.  
  27. subplot(2,1,2);
  28. plot((-length(Rxy)/2 : length(Rxy)/2-1)/fs*1000, Rxy)   %s->ms
  29. axis tight;
  30. xlabel('czas [ms]');
  31. ylabel('Rxy');
  32. title('Korelacja krzyżowa Rxy');
  33. grid on;
  34.  
  35. figure();
  36. H = Y./X;
  37. N = length(H);
  38. absH = abs(H);
  39. argH = unwrap(angle(H));
  40. f=(0:length(absH)/2-1)*fs/(length(absH));
  41.  
  42. subplot(2,1,1);
  43. semilogx(f,20*log((absH(1:N/2))));
  44. axis tight;
  45. xlabel('częstotliowość [Hz]');
  46. ylabel('|L|');
  47. line([fs/2 fs/2], ylim,'Color',[1 0 0],'LineWidth',1);
  48. title('Ch-ka amplitudowo-częstotliwościowa');
  49. grid on;
  50.  
  51. subplot(2,1,2);
  52. semilogx(f,(argH(1:N/2)));
  53. axis tight;
  54. xlabel('częstotliowość [Hz]');
  55. ylabel('faza [ ^o]');
  56. line([fs/2 fs/2], ylim,'Color',[1 0 0],'LineWidth',1);
  57. title('Ch-ka fazowowo-częstotliwościowa');
  58. grid on;
  59.  
  60. figure();
  61. h = ifft(H);
  62. plot(t(1:1500),h(1:1500));
  63. axis tight;
  64. xlabel('czas [s]');
  65. ylabel('A');
  66. title('Odpowiedź impulsowa');
  67. grid on;
  68.  
  69. peak = 0.1;
  70. for i=1:length(h)
  71.     if h(i) >= peak
  72.         distance = i/fs*320;
  73.         break;
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement