Advertisement
SubhamRath

cross_and _corelation

Feb 24th, 2021
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.85 KB | None | 0 0
  1. clc
  2. clear all;
  3. close all;
  4.  
  5. x = input('enter the sequence :');
  6. px=input('pointer position of x : ');
  7. a = input('enter the impulse sequence :');
  8. ph=input('pointer position of h : ');
  9. for i= 1:length(a)
  10.     h(i) = a(length(a)+1-i);
  11. end
  12. lx=length(x);
  13. lh=length(h);
  14. left=1-px;
  15. right=lx-px;
  16. left1=-(lh-ph);
  17. right1=-(1-ph);
  18.  
  19. t=[left:right];
  20. t1=[left1:right1];
  21.  
  22. subplot(3,1,1)
  23. stem(t,x)
  24. title('input sequence(x)')
  25. subplot(3,1,2)
  26. stem(t1,a)
  27. title('input sequence(h)')
  28.  
  29. for i= 1:lh
  30.     ph(i) = h(lh+1-i);
  31. end
  32. t3=[-right1:-left1];
  33. x1 = [zeros(1,lh-1), x , zeros(1, lh-1)];
  34. ly = lx+lh-1;
  35. for i = 1:ly
  36.     z = x1(1, 1:length(ph)) .*ph;
  37.     y(i) = sum(z);
  38.     ph = [ 0 ph];
  39. end
  40. y
  41. t4 = [left+left1:right+right1];
  42. subplot(3,1,3)
  43. stem(t4,y)
  44. if(x==a)
  45.     title('auto-corelation signal(y)')
  46. else
  47.     title('cross-corelation signal(y)')
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement