Advertisement
Cinster

Untitled

May 22nd, 2019
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. %Zachary Orsoli 40004528
  2. %ELEC 342 Lab2 Part1 Question2
  3. clear all
  4. clc
  5.  
  6. % b)
  7. n=[0:1];
  8. x1=n;
  9. x2=n;
  10.  
  11. y1 =x1.^2;
  12. y2 = x2.^2;
  13. %if x3[n] = x1[n] + x2[n]
  14. x3 = x1+x2;
  15. y3 = x3.^2;
  16. y4=y1+y2;
  17. disp(' ') %create line spacing
  18. disp('For the system y[n] = x^2[n] with input x[n]=[0,1] :')
  19. if(y3 == y4)
  20. disp('This function is linear since y3[n] = y4[n]')
  21. else
  22. disp('This function is not linear since y3[n] is not equal to y4[n]')
  23. end
  24. %Checking for Time Invariance
  25. x1 = n;
  26. x2 = x1+1;
  27. y2 =(x2).^2;
  28. y1_shifted = (x1+1).^2;
  29. if(y1_shifted == y2)
  30. disp('This function is Time-Invariant since y1[n+shift] = y2[n] where x2 = x1 +shift')
  31. else
  32. disp('This function is not Time-Invariant since y1[n+shift] is notequal to y2[n]')
  33. end
  34. %part b) (i) with range x[n]=[0:20]
  35. n = [0:20];
  36. x1 = n;
  37. x2 = n;
  38. %if y[n] = x^2[n]
  39. y1 =x1.^2;
  40. y2 = x2.^2;
  41. %if x3[n] = x1[n] + x2[n]
  42. x3 = x1+x2;
  43. y3 = x3.^2;
  44. y4=y1+y2;
  45. disp(' ') %create line spacing
  46. disp('For the system y[n] = x^2[n] with input x[n]=[0:20] :')
  47. if(y3 == y4)
  48. disp('This function is linear since y3[n] = y4[n]')
  49. else
  50. disp('This function is not linear since y3[n] is not equal to y4[n]')
  51. end
  52. %Checking for Time Invariance
  53. x1 = n;
  54. x2 = x1+1;
  55. y2 =(x2).^2;
  56.  
  57.  
  58. y1_shifted = (x1+1).^2;
  59. if(y1_shifted == y2)
  60. disp('This function is Time-Invariant since y1[n+shift] = y2[n] where x2 = x1 +shift')
  61. else
  62. disp('This function is not Time-Invariant since y1[n+shift] is not equal to y2[n]')
  63. end
  64.  
  65.  
  66.  
  67. %part b)(i) with range x[n]=[0:1]
  68. n = [0:1];
  69. x1 = n;
  70. x2 = n;
  71. %if y[n] = 2*x[n] + 5*delta[n]
  72. y1 = 2*x1;
  73. y1(1) = y1(1) + 5; % +5*delta[n]
  74. y2 = 2*x2;
  75. y2(1) =y2(1)+ 5; % +5*delta[n]
  76. %if x3[n] = x1[n] + x2[n]
  77. x3 = x1+x2;
  78. y3 = 2*x3;
  79. y3(1) =y3(1)+ 5; % +5*delta[n]
  80. y4=y1+y2;
  81. subplot(2,2,1)
  82. stem(n,x1)
  83. hold
  84. stem(n,y1)
  85. title('x1[n] and y1[n]')
  86. xlabel('n')
  87. ylabel('x1 and y1')
  88. subplot(2,2,2)
  89. stem(n,x2)
  90. hold
  91. stem(n,y2)
  92. title('x2[n] and y2[n]')
  93. xlabel('n')
  94. ylabel('x2 and y2')
  95. subplot(2,2,3)
  96. stem(n,x3)
  97.  
  98. hold
  99. stem(n,y3)
  100. title('x3[n] and y3[n]')
  101. xlabel('n')
  102. ylabel('x3 and y3')
  103. subplot(2,2,4)
  104. stem(n,y1)
  105. title('x4[n] and y4[n]')
  106. xlabel('n')
  107. ylabel('y4')
  108.  
  109. disp(' ') %create line spacing
  110. disp('For the system y[n] = 2*x[n] + 5*delta[n] with input x[n]=[0,1] :')
  111. if(y3 == y4)
  112. disp('This function is linear since y3[n] = y4[n]')
  113. else
  114. disp('This function is not linear since y3[n] is not equal to y4[n]')
  115. end
  116. %Checking for Time Invariance
  117. x1 = n;
  118. x2 = x1+1;
  119. y2 =(x2).^2;
  120. y1_shifted = (x1+1).^2;
  121. if(y1_shifted == y2)
  122. disp('This function is Time-Invariant since y1[n+shift] = y2[n] where x2 = x1 +shift')
  123. else
  124. disp('This function is not Time-Invariant since y1[n+shift] is not equal to y2[n]')
  125. end
  126. %part b) (i) with range x[n]=[0:20]
  127. n = [0:20];
  128. x1 = n;
  129. x2 = n;
  130. %if y[n] = 2*x[n]
  131. y1 =x1.^2;
  132. y2 = x2.^2;
  133. %if x3[n] = x1[n] + x2[n]
  134. x3 = x1+x2;
  135. y3 = x3.^2;
  136. y4=y1+y2;
  137. disp(' ') %create line spacing
  138. disp('For the system y[n] = 2*x[n] + 5*delta[n] with input x[n]=[0:20] :')
  139. if(y3 == y4)
  140. disp('This function is linear since y3[n] = y4[n]')
  141. else
  142. disp('This function is not linear since y3[n] is not equal to y4[n]')
  143. end
  144.  
  145. %Checking for Time Invariance
  146. x1 = n;
  147. x2 = x1+1;
  148. y2 =(x2).^2;
  149. y1_shifted = (x1+1).^2;
  150. if(y1_shifted == y2)
  151. disp('This function is Time-Invariant since y1[n+shift] = y2[n] where x2 = x1 +shift')
  152. else
  153. disp('This function is not Time-Invariant since y1[n+shift] is not equal to y2[n]')
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement