Advertisement
defineSN

linear and circular convolution

May 19th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.06 KB | None | 0 0
  1. %syms p q % needed only when poly2sym() is used
  2. run_loop=1;
  3. while run_loop==1
  4. x=input('enter 1st sequence');
  5. h=input('enter 2nd sequence');
  6. x_str=char(int2str(x));
  7. h_str=char(int2str(h));
  8. %x_str=char(poly2sym(x,p)); %this returns the sequence as a polynomial
  9. %h_str=char(poly2sym(h,q));
  10. N1=length(x);
  11. N2=length(h);
  12. %N=max(N1,N2)
  13. N=(N1+N2-1) % circular convolution using N=max(N1,N2) will result in aliasing of (N2-1) points if N1 not=N2
  14. y=conv(x,h)
  15. yc=cconv(x,h,N)
  16.  
  17. n=0:1:N1-1;
  18. subplot(2,2,1);
  19. stem(n,x)
  20. xlabel('No. of samples');
  21. ylabel('amplitude');
  22. title(['First sequence:',x_str]);
  23.  
  24. n=0:1:N2-1;
  25. subplot(2,2,2);
  26. stem(n,h)
  27. xlabel('No. of samples');
  28. ylabel('amplitude');
  29. title(['Second sequence:',h_str]);
  30.  
  31. n=0:1:(N1+N2)-2;
  32. subplot(2,2,3);
  33. stem(n,y)
  34. xlabel('No. of samples');
  35. ylabel('amplitude');
  36. title('Sequence for linear convolution');
  37.  
  38. n=0:1:N-1;
  39. subplot(2,2,4);
  40. stem(n,yc)
  41. xlabel('No. of samples');
  42. ylabel('amplitude');
  43. title('Sequence for circular convolution');
  44. run_loop=input('continue with another convolution? 1(YES), 0(NO):')
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement