Advertisement
MurlocProger

ACF/CCF

Mar 24th, 2024
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.64 KB | Source Code | 0 0
  1. clear
  2. close all
  3. %Initial Data
  4. A = 8e-3;
  5. F0 = 3000;
  6. Fs = 48000;
  7. Q = 3;
  8. N = 10;
  9. m = 0;
  10. sq = A;
  11. D = 1/Q*100;
  12. t = 0:1/Fs:N*1/F0-1/Fs;
  13. t0 = -(1/F0-1/Fs):1/Fs:1/F0-1/Fs;
  14. %Single Rectangular Signal
  15. y0 = A*rectpuls(t0, 1/F0*(D/100));
  16. subplot(3, 3, 1)
  17. plot(t0, y0)
  18. title('Original Single Signal')
  19. %Periodic Rectangular Signal
  20. y1 = A*(square(2*pi*F0*t, D));
  21. subplot(3, 3, 2);
  22. plot(t, y1);
  23. title('Origianl Periodic Signal');
  24. %White Noise
  25. y2 = sq*(rand(1, length(y1))-0.5);
  26. subplot(3, 3, 3)
  27. plot(t, y2)
  28. title('White Noise')
  29. %Signal-noise Mixture
  30. y3 = y1 + y2;
  31. subplot(3, 3, 4)
  32. plot(t, y3)
  33. title('Signal-noise mixture')
  34. %ACF of Single Rectangular Signal
  35. [ACF_y0, lags0] = xcorr(y0);
  36. subplot(3, 3, 5)
  37. plot(lags0, ACF_y0)
  38. title('Single Signal ACF')
  39. %ACF of Periodic Rectangular Signal
  40. [ACF_y1, lags1] = xcorr(y1);
  41. subplot(3, 3, 6)
  42. plot(lags1, ACF_y1)
  43. title('Pediodic Signal ACF')
  44. %Interval from Mixture
  45. start_T = randi(N/2, 1, 1);
  46. end_T = start_T+randi(N/2, 1, 1);
  47. period =  floor(length(y3)/N);
  48. y3_interval = y3(period*start_T:period*end_T);
  49. subplot(3, 3, 7);
  50. plot(t(period*start_T:period*end_T),y3_interval);
  51. title('Interval from mixture');
  52. [CCF_y3Xy3_interval, lags2] = xcorr(y3, y3_interval);
  53. subplot(3, 3, 8)
  54. plot(lags2,CCF_y3Xy3_interval)
  55. title('Cross Correlation for Y3 and interval')
  56. CCF_max = max(CCF_y3Xy3_interval);
  57. disp(CCF_max)
  58. CCF_max_index = find(CCF_y3Xy3_interval==CCF_max);
  59. disp(CCF_max_index)
  60. %Find original interval
  61. left_border_index = round(CCF_max_index - length(y3_interval)/2);%?
  62. right_border_index = round(CCF_max_index + length(y3_interval)/2);%?
  63. display(left_border_index)
  64. display(right_border_index)
Tags: Matlab
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement