Shafayat__

Untitled

May 12th, 2023
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.50 KB | None | 0 0
  1. x = [-1,4,1,4,2];
  2. n = length(x);
  3. y = zeros(1,2*n-1);
  4. z = xcorr(x);
  5. for delay = -n+1:n-1
  6.     if delay<0
  7.         y(delay+n) = sum(x(1:n+delay).^x(-delay+1:n));
  8.     elseif delay==0
  9.         y(delay+n) = sum(x.^2);
  10.     else
  11.         y(delay+n) = sum(x(delay+1:n).^x(1:n-delay));
  12.     end
  13. end
  14.  
  15. subplot(3,1,1);
  16. stem(x);
  17. title('General Function');
  18.  
  19. subplot(3,1,2);
  20. stem(z);
  21. title('Auto-correlation with Correlation Function');
  22.  
  23. subplot(3,1,3);
  24. stem(-n+1:n-1,y);
  25. title('Auto-correlation Manually');
  26.  
Advertisement
Add Comment
Please, Sign In to add comment