Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.30 KB | None | 0 0
  1. %% ELE 632 Lab 1 Report
  2. % *Author:*  Scott Goddard 500723518
  3. %
  4. %% A.1)
  5. delta = @(n) 1.0.*(n==3);
  6. u = @(n) 1.0.*(n>=-1);
  7. x = @(n) cos((pi*n)/5.0).*u(n);
  8. x1 = @(n) x(n-3);
  9. x2 = @(n) x(-n);
  10. n = (-20:20)';
  11.  
  12. figure(1);
  13. stem(n,delta(n)); grid on; title('I.'); xlabel('n');
  14.  
  15. figure(2);
  16. stem(n,u(n)); grid on; title('II.'); xlabel('n');
  17.  
  18. figure(3);
  19. stem(n,x(n)); grid on; title('III.'); xlabel('n');
  20.  
  21. figure(4);
  22. stem(n,x1(n)); grid on; title('IV.'); xlabel('n');
  23.  
  24. figure(5);
  25. stem(n,x2(n)); grid on; title('V.'); xlabel('n');
  26.  
  27. % x1[n] is translating x[n] 3 units right.
  28. % x2[n] is horizontally mirroring x[n] across the y axis.
  29.  
  30. %% A.2)
  31. n = [-10:70];
  32. u = @(n) 1.0.*(n>=0);
  33. y = @(n) 5.0.*exp(-1.0*n/8).*(u(n)-u(n-10));
  34. y1 = @(n) y(3.*n);
  35. y2 = @(n) y(n/3);
  36.  
  37. figure(6);
  38. stem(n,y(n)); grid on; title('I.'); xlabel('n');
  39. axis([-10 70 0 6]);
  40.  
  41. figure(7);
  42. stem(n,y1(n)); grid on; title('II.'); xlabel('n');
  43. axis([-10 70 0 6]);
  44.  
  45. figure(8);
  46. stem(n,y2(n)); grid on; title('III.'); xlabel('n');
  47. axis([-10 70 0 6]);
  48.  
  49. % y1[n] is horizontally compressing x[n] by 3.
  50. % y2[n] is horizontally stretch x[n] by 3.
  51.  
  52. %% A.3)
  53. t = [-10:0.1:70];
  54. u = @(t) 1.0.*(t>=0);
  55. z = @(t) 5.0.*exp(-1.0*t/8).*(u(t)-u(t-10));
  56. y3 = @(t) z(t./3);
  57.  
  58. n = [-10:70];
  59.  
  60. figure(9);
  61. stem(n,y3(n)); grid on; title('I.'); axis([-10 70 0 6]);
  62.  
  63. % II. y3[n] is not the same as y2[n] because it was sampled after the
  64. % signal was generated, so it has more values.
  65.  
  66. %% B.2)
  67. n = 1:13;
  68. y = [2000,zeros(1,length(n)-1)];
  69. i = 1.02;
  70. for j = 1:13
  71.     y(j+1) = i*y(j);
  72. end
  73. figure(10);
  74. stem(n,y(n)); grid on;
  75. xlabel('Month'); ylabel('Balance [$]'); title('B.2');
  76. axis([0 14 1000 12000]);
  77.  
  78. %% B.3)
  79. n = 1:13;
  80. y = [2000,zeros(1,length(n)-1)];
  81. x = @(n) 100.*n;
  82. i = 1.02;
  83. for j = 1:13
  84.     y(j+1) = i*y(j) + x(j);
  85. end
  86. figure(11);
  87. stem(n,y(n)); grid on;
  88. xlabel('Month'); ylabel('Balance [$]'); title('B.3');
  89. axis([0 14 1000 12000]);
  90.  
  91. %% C.1)
  92. delta = @(n) 1.0.*(n==0);
  93. x = @(n) cos(pi*n./5)+delta(n-20)-delta(n-35);
  94. n = 0:44;
  95.  
  96. figure(12);
  97. stem(n,x(n)); title('Input signal'); xlabel('n'); grid on;
  98.  
  99. %  Matlab function given below
  100. %
  101. %  function [y] = maximum(x,N)
  102. %    M = length(x);
  103. %    y = [zeros(1,M)];
  104. %    x2 = [zeros(1,(N-1)),x];
  105. %    for i = 1:M
  106. %        out = max(x2(i:(i+N-1)));
  107. %        y4(i) = out;
  108. %    end  
  109.  
  110. %% C.2)
  111. figure(13);
  112. y = maximum(x(n),4);
  113. stem(n,y); title('N = 4'); xlabel('n'); grid on;
  114.  
  115. figure(14);
  116. y = maximum(x(n),8);
  117. stem(n,y); title('N = 8'); xlabel('n'); grid on;
  118.  
  119. figure(15);
  120. y = maximum(x(n),12);
  121. stem(n,y); title('N = 12'); xlabel('n'); grid on;
  122.  
  123.  
  124. %% C.3)
  125.  
  126. % For each value of N the signal is essentially taking the max value for
  127. % the last N points. That means a local maximum will persist for N values.
  128. % We lose a lot of information about the signal by increasing N.
  129.  
  130. %% D.1)
  131.  
  132. % Function given below:
  133. %
  134. % function [e,p] = enpow(x)
  135. %    sq = abs(x).^2;
  136. %    en = 0;
  137. %    for i = 1:length(x)
  138. %        en = en + sq(i);
  139. %    end
  140. %    e = en
  141. %
  142. %    N0 = length(x)+1;
  143. %    N = (length(x)-1)/2;
  144. %    pow = 0;
  145. %    for i = 1:N
  146. %        pow = pow + sq(i);
  147. %    end
  148. %   p = N0^(-1)*pow
  149. % end
  150.  
  151. %% D.2)
  152. u = @(n) 1.0.*(n>=0);
  153. x = @(n) 3.0.*n.*(u(n+3)-u(n-4));
  154. n = -3:3;
  155. figure(16);
  156. stem(n,x(n));title('x[n] original'); xlabel('n'); grid on;
  157. enpow(x(n));
  158.  
  159.  
  160.  
  161. %%% HINT = USE MOD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement