Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.72 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. Rxx = xcorr(x,x);
  7. Rxy = xcorr(x,y);
  8.  
  9. dt = 10/length(x);
  10. T = 10;
  11. t = 0:dt:T-dt;
  12. fs = Fs1;
  13.  
  14. X = fft(x);
  15. Y = fft(y);
  16.  
  17. subplot(2,1,1);
  18. plot((-length(Rxx)/2 : length(Rxx)/2-1)/fs*1000, Rxx)   %s->ms
  19. axis tight;
  20. xlabel('czas [ms]');
  21. ylabel('Rxx');
  22. title('Autokorelacja Rxx');
  23. grid on;
  24.  
  25. subplot(2,1,2);
  26. tR = (-length(Rxy)/2 : length(Rxy)/2-1)/fs*1000;
  27. plot(tR, Rxy)   %s->ms
  28. axis tight;
  29. xlabel('czas [ms]');
  30. ylabel('Rxy');
  31. title('Korelacja krzyżowa Rxy');
  32. grid on;
  33.  
  34. [peak1, index1] = max(Rxy);       %odległość liczona opóźnienia korelacji krzyżowj
  35. distance1 = abs(tR(index1))*320/1000;
  36.  
  37. figure();
  38. H = Y./X;
  39. N = length(H);
  40. absH = abs(H);
  41. argH = unwrap(angle(H));
  42. f=(0:length(absH)/2-1)*fs/(length(absH));
  43.  
  44. subplot(2,1,1);
  45. semilogx(f,20*log((absH(1:N/2))));
  46. axis tight;
  47. xlabel('częstotliowość [Hz]');
  48. ylabel('|L|');
  49. line([fs/2 fs/2], ylim,'Color',[1 0 0],'LineWidth',1);
  50. title('Ch-ka amplitudowo-częstotliwościowa');
  51. grid on;
  52.  
  53. subplot(2,1,2);
  54. semilogx(f,(argH(1:N/2)));
  55. axis tight;
  56. xlabel('częstotliowość [Hz]');
  57. ylabel('faza [ ^o]');
  58. line([fs/2 fs/2], ylim,'Color',[1 0 0],'LineWidth',1);
  59. title('Ch-ka fazowowo-częstotliwościowa');
  60. grid on;
  61.  
  62. figure();
  63. h = ifft(H);
  64. plot(t(1:1500),h(1:1500));
  65. axis tight;
  66. xlabel('czas [s]');
  67. ylabel('A');
  68. title('Odpowiedź impulsowa');
  69. grid on;
  70.  
  71. [peak2, index2] = max(h);   %odległość liczona z opóźniania odp. impulsowej
  72. distance2 = index2/fs*320;
  73.  
  74. [maxRxx,IRxx]=max(Rxx); %odległość liczona z różnicy czasu autokorelacji i korelacji krzyżowej
  75. [maxRxy,IRxy]=max(Rxy);
  76. tdiff1=abs(IRxx-IRxy)/fs;
  77. distance3=tdiff1*320;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement