daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest May 16th, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %Question(1):
  2.  
  3. %A)1-
  4. n1=[-12:12];
  5. x1=[-2,-1,0,1,2];
  6. x1=[x1 x1 x1 x1 x1];
  7. stem(n1,x1);        
  8. title('Plotting five periods');
  9. xlabel('n1');
  10. ylabel('x1');      
  11. figure
  12.  
  13. %A)2-
  14. n2=[0:20];
  15. x2=exp(0.1*n2).*[stepseg(0,0,20)-stepseg(20,0,20)];
  16. x2=[x2 x2 x2];
  17. %n2=[0:62];
  18. n2=[-21:41];
  19. stem(n2,x2);
  20. title('Plotting three periods');
  21. xlabel('n2');
  22. ylabel('x2=e^(0.1*n2)*[u(n)-u(n-20)]');
  23. figure
  24.  
  25. %A)3-
  26. n3=[0:10];
  27. x3=sin(0.1*pi*n3).*[stepseg(0,0,10)-stepseg(10,0,10)];
  28. x3=[x3 x3 x3 x3];
  29. n3=[-22:21];
  30. stem(n3,x3);
  31. title('Plotting four periods');
  32. ylabel('x3=sin(0.1*pi*n3)*[u(n)-u(n-10)]');
  33. xlabel('n3');
  34. figure
  35.  
  36. %A)4-
  37. n4=[0:24]
  38. x4a=[1,2,3];
  39. x4b=[1,2,3,4];
  40. x4a=[x4a x4a x4a x4a x4a x4a x4a x4a 1];  %to suits the n[0:24] 25 elements
  41. x4b=[x4b x4b x4b x4b x4b x4b 1];          %to suits the n[0:24] 25 elements
  42. x4=x4a+x4b;
  43. stem(n4,x4);
  44. title('The sum of two periodic signals');
  45. xlabel('n4');
  46. ylabel('x4');
  47. figure
  48. %-------------------------------------------------------------------------------
  49.  
  50. %B)
  51. x=[2,4,-3,1,-5,4,7];
  52. n=[-3,3];
  53. %B)1-
  54. [x1,n1]=sigshift(x,n,3);                 %x(n-3)
  55. [x2,n2]=sigshift(x,n,-4);                %x(n+4)
  56. [x12,n12]=sigadd(2*x1,n1,3*x2,n2);       %x12=2*x(n-3)+3*x(n+4)
  57. [xfinal,nfinal]=sigadd(x12,n12,-1*x,n);  %xfinal=2*x(n-3)+3*x(n+4)-x(n)
  58. stem(nfinal,xfinal);
  59. xlabel('nfinal');
  60. ylabel('2*x(n-3)+3*x(n+4)-x(n)');
  61. figure
  62.  
  63. %B)2-
  64. [x1,n1]=sigshift(x,n,-4);                %x1=x(n+4)
  65. [x2,n2]=sigshift(x,n,-5);                %x2=x(n+5)
  66. [x12,n12]=sigadd(4*x1,n1,5*x2,n2);       %x12=4*x(n+4)+5*x(n+5)
  67. [xfinal,nfinal]=sigadd(x12,n12,2*x,n);   %xfinal=4*x(n+4)+5*x(n+5)+2*x(n)
  68. stem(nfinal,xfinal);
  69. xlabel('nfinal');
  70. ylabel('4*x(n+4)+5*x(n+5)+2*x(n)');
  71. figure
  72.  
  73. %B)3-
  74. [x1,n1]=sigshift(x,n,-3);                %x1=x(n+3)
  75. [x2,n2]=sigshift(x,n,2);                 %x2=x(n-2)
  76. [x3,n3]=sigshift(x,n,-1);                %x3=x(n+1)
  77. [x4,n4]=sigfold(x3,n3)                   %x4=x(1-n)
  78. [x12,n12]=sigmult(x1,n1,x2,n2);          %x12=x(n+3)*x(n-2)
  79. [x34,n34]=sigmult(x3,n3,x4,n4);          %x34=x(n+1)*x(1-n)
  80. [xfinal,nfinal]=sigadd(x12,n12,x34,n34)  %xfinal=x(n+3)*x(n-2)+x(n+1)*x(1-n)
  81. stem(xfinal,nfinal);
  82. xlabel('nfinal');
  83. ylabel('x(n+3)*x(n-2)+x(n+1)*x(1-n)');
  84. figure
  85.  
  86. %B)4-
  87. x=[zeros(1,7) x zeros(1,7)];
  88. n=[-10:10];
  89. [x1,n1]=sigshift(x,n,-2);                %x1=x(n+2);
  90. [x2,n2]=sigmult(x1,n1,cos(0.1*pi*n),n);  %x2=x(n+2)*cos(2*pi*n)
  91. [x3,n3]=sigmult(x,n,exp(0.5*n),n);       %x3=e^(0.5*n)*x(n)
  92. [xfinal,nfinal]=sigadd(2*x3,n3,x2,n2);   %xfinal=2*e^(0.5*n)*x(n)+x(n+2)*cos(2*pi*n)
  93. stem(xfinal,nfinal)
  94. xlabel('nfinal');
  95. ylabel('2*e^(0.5*n)*x(n)+x(n+2)*cos(2*pi*n)');
  96. figure
  97. %-------------------------------------------------------------------------------
  98.  
  99. %Question(2):
  100.  
  101. %i)
  102. x1=[1,2,4];
  103. nx=[0:2];
  104. h1=[1,1,1,1,1];
  105. nh=[-2:2];
  106. [y,ny]=conv_m(x1,nx,h1,nh);
  107. stem(ny,y);
  108. title('Convolution');
  109. xlabel('ny');
  110. ylabel('y=x1*h1');
  111. figure
  112.  
  113. %ii)
  114. x2=[0,1,-2,3,-4];
  115. nx=[0:4];
  116. h2=[0.5,1,2,1,0.5];
  117. nh=[-2:2];
  118. [y1,ny1]=conv_m(x2,nx,h2,nh);
  119. stem(ny1,y1);
  120. title('Convolution');
  121. xlabel('ny');
  122. ylabel('y=x1*h1');
  123. figure
  124.  
  125. %iii)
  126. x3=[1,2,3,4];
  127. nx=[0:3];
  128. h3=[4,3,2,1];
  129. nh=[0:3];
  130. [y3,ny3]=conv_m(x3,nx,h3,nh)
  131. stem(ny3,y3);
  132. title('convolution');
  133. xlabel('ny3');
  134. ylabel('y=x*h');
  135. figure
  136.  
  137. %iv)
  138. x4=[1,2,3,4];
  139. h4=[1,2,3,4];
  140. n4=[0:3];
  141. [y4,ny4]=conv_m(x4,n4,h4,n4);
  142. stem(ny4,y4);
  143. title('convolution');
  144. xlabel('ny3');
  145. ylabel('y=x*h');
  146. figure
  147.  
  148. %------------------------------------------------------------------------------
  149. %Question(3):
RAW Paste Data
Top