Advertisement
Guest User

afe

a guest
Oct 19th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. % A1 , A2
  2. R = [1e4, 1e4, 1e4];
  3. C = [1e-6, 1e-6];
  4. %Determine coefficients for characteristic equation:
  5. A = [1, (1/R(1)+1/R(2)+1/R(3))/C(2), 1/(R(1)*R(2)*C(1)*C(2))];
  6. %Determine characteristic roots:
  7. lambda1 = roots(A);
  8. poly(lambda1);
  9.  
  10. f1 = @(t) exp(lambda1(1)*t) + exp(lambda1(2)*t);
  11. t = (0:0.0005:0.1);
  12. grid;
  13. plot(t,f1(t));
  14.  
  15. % A3
  16. figure;
  17. R = [1e4, 1e4, 1e4];
  18. C = [1e-9, 1e-6];
  19. %Determine coefficients for characteristic equation:
  20. A = [1, (1/R(1)+1/R(2)+1/R(3))/C(2), 1/(R(1)*R(2)*C(1)*C(2))];
  21. %Determine characteristic roots:
  22. lambda2 = roots(A);
  23. f2 = @(t) exp(lambda2(1)*t) + exp(lambda2(2)*t);
  24. t = (0:0.0005:0.1);
  25. grid;
  26. plot(t,f2(t));
  27.  
  28. % B1
  29. figure;
  30. figure(1) % Create figure window and make visible on screen
  31. u = @(t) 1.0*(t>=0);
  32. x = @(t) 1.5*sin(pi*t).*(u(t)-u(t-1));
  33. h = @(t) 1.5*(u(t)-u(t-1.5))-u(t-2)+u(t-2.5);
  34. dtau = 0.005; tau = -1:dtau:4;
  35. ti = 0; tvec = -.25:.1:3.75;
  36. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  37. for t = tvec,
  38. ti = ti+1; % Time index
  39. xh = x(t-tau).*h(tau); lxh = length(xh);
  40. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  41. subplot(2,1,1),plot(tau,h(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
  42. axis([tau(1) tau(end) -2.0 2.5]);
  43. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  44. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  45. [.8 .8 .8],'edgecolor','none');
  46. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  47. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  48. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  49. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  50. axis([tau(1) tau(end) -1.0 2.0]); grid;
  51. drawnow;
  52. end
  53.  
  54. % B2
  55. figure;
  56. u = @(t) 1.0*(t>=0);
  57. x = @(t) 1*(u(t)-u(t-2));
  58. h = @(t) (t+1).*(u(t+1)-u(t));
  59. dtau = 0.005; tau = -1:dtau:4;
  60. ti = 0; tvec = -.25:.1:3.75;
  61. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  62. for t = tvec,
  63. ti = ti+1; % Time index
  64. xh = x(t-tau).*h(tau); lxh = length(xh);
  65. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  66. subplot(2,1,1),plot(tau,h(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
  67. axis([tau(1) tau(end) -2.0 2.5]);
  68. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  69. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  70. [.8 .8 .8],'edgecolor','none');
  71. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  72. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  73. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  74. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  75. axis([tau(1) tau(end) -1.0 2.0]); grid;
  76. drawnow;
  77. end
  78.  
  79. % B3 a)
  80. figure;
  81. u = @(t) 1.0*(t>=0);
  82. x1 = @(t) 1*(u(t-4)-u(t-6));
  83. x2 = @(t) 2*(u(t+5)-u(t+4));
  84. dtau = 0.005; tau = -7:dtau:4;
  85. ti = 0; tvec = -.25:.1:3.75;
  86. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  87. for t = tvec,
  88. ti = ti+1; % Time index
  89. xh = x1(t-tau).*x2(tau); lxh = length(xh);
  90. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  91. subplot(2,1,1),plot(tau,x2(tau),'k-',tau,x1(t-tau),'k--',t,0,'ok');
  92. axis([tau(1) tau(end) -2.0 2.5]);
  93. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  94. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  95. [.8 .8 .8],'edgecolor','none');
  96. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  97. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  98. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  99. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  100. axis([tau(1) tau(end) -1.0 2.0]); grid;
  101. drawnow;
  102. end
  103.  
  104. % B3 b)
  105. figure;
  106. u = @(t) 1.0*(t>=0);
  107. x1 = @(t) 1*(u(t-3)-u(t-5));
  108. x2 = @(t) 2*(u(t+5)-u(t+3));
  109. dtau = 0.005; tau = -7:dtau:4;
  110. ti = 0; tvec = -.25:.1:3.75;
  111. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  112. for t = tvec,
  113. ti = ti+1; % Time index
  114. xh = x1(t-tau).*x2(tau); lxh = length(xh);
  115. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  116. subplot(2,1,1),plot(tau,x2(tau),'k-',tau,x1(t-tau),'k--',t,0,'ok');
  117. axis([tau(1) tau(end) -2.0 2.5]);
  118. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  119. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  120. [.8 .8 .8],'edgecolor','none');
  121. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  122. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  123. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  124. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  125. axis([tau(1) tau(end) -1.0 2.0]); grid;
  126. drawnow;
  127. end
  128.  
  129. % B3 h)
  130. figure;
  131. u = @(t) 1.0*(t>=0);
  132. x1 = @(t) exp(t).*(u(t+2)-u(t));
  133. x2 = @(t) exp(-2*t).*(u(t)-u(t-1));
  134. dtau = 0.005; tau = -3:dtau:4;
  135. ti = 0; tvec = -.25:.1:3.75;
  136. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  137. for t = tvec,
  138. ti = ti+1; % Time index
  139. xh = x1(t-tau).*x2(tau); lxh = length(xh);
  140. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  141. subplot(2,1,1),plot(tau,x2(tau),'k-',tau,x1(t-tau),'k--',t,0,'ok');
  142. axis([tau(1) tau(end) -2.0 2.5]);
  143. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  144. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  145. [.8 .8 .8],'edgecolor','none');
  146. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  147. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  148. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  149. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  150. axis([tau(1) tau(end) -1.0 2.0]); grid;
  151. drawnow;
  152. end
  153.  
  154. %C1
  155. t = (-1:0.001:5);
  156. figure;
  157. u = @(t) 1.0*(t>=0);
  158. h1 = @(t) exp(t/5).*u(t);
  159. plot(t,h1(t));
  160. xlabel('t');
  161. ylabel('h1(t)');
  162. grid;
  163.  
  164.  
  165. figure;
  166. u = @(t) 1.0*(t>=0);
  167. h2 = @(t) 4*exp(-t/5).*u(t);
  168. plot(t,h2(t));
  169. xlabel('t');
  170. ylabel('h2(t)');
  171. grid;
  172.  
  173. figure;
  174. u = @(t) 1.0*(t>=0);
  175. h3 = @(t) 4*exp(-t).*u(t);
  176. plot(t,h3(t));
  177. xlabel('t');
  178. ylabel('h3(t)');
  179. grid;
  180.  
  181. figure;
  182. u = @(t) 1.0*(t>=0);
  183. h4 = @(t) 4*(exp(-t/5) - exp(-t)).*u(t);
  184. plot(t,h4(t));
  185. xlabel('t');
  186. ylabel('h4(t)');
  187. grid;
  188.  
  189. %C2
  190.  
  191. % h1(t): lambda = 1/5
  192. % h2(t): lambda = -1/5
  193. % h3(t): lambda = -1
  194. % h4(t): lambda = -1/5 , -1
  195.  
  196. %C3
  197.  
  198. figure;
  199. u = @(t) 1.0*(t>=0);
  200. h1 = @(t) exp(t/5).*u(t);
  201. x = @(t) u(t) - u(t-3);
  202. dtau = 0.005; tau = 0:dtau:20;
  203. ti = 0; tvec = 0:.1:20;
  204. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  205. for t = tvec,
  206. ti = ti+1; % Time index
  207. xh = x(t-tau).*h1(tau); lxh = length(xh);
  208. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  209. subplot(2,1,1),plot(tau,h1(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
  210. axis([tau(1) tau(end) -2.0 2.5]);
  211. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  212. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  213. [.8 .8 .8],'edgecolor','none');
  214. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  215. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  216. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  217. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  218. axis([tau(1) tau(end) -1.0 2.0]); grid;
  219. drawnow;
  220. end
  221.  
  222. figure;
  223. u = @(t) 1.0*(t>=0);
  224. h2 = @(t) 4*exp(-t/5).*u(t);
  225. x = @(t) u(t) - u(t-3);
  226. dtau = 0.005; tau = 0:dtau:20;
  227. ti = 0; tvec = 0:.1:20;
  228. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  229. for t = tvec,
  230. ti = ti+1; % Time index
  231. xh = x(t-tau).*h2(tau); lxh = length(xh);
  232. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  233. subplot(2,1,1),plot(tau,h2(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
  234. axis([tau(1) tau(end) -2.0 2.5]);
  235. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  236. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  237. [.8 .8 .8],'edgecolor','none');
  238. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  239. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  240. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  241. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  242. axis([tau(1) tau(end) -1.0 2.0]); grid;
  243. drawnow;
  244. end
  245.  
  246. figure;
  247. u = @(t) 1.0*(t>=0);
  248. h3 = @(t) 4*exp(-t).*u(t);
  249. x = @(t) u(t) - u(t-3);
  250. dtau = 0.005; tau = 0:dtau:20;
  251. ti = 0; tvec = 0:.1:20;
  252. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  253. for t = tvec,
  254. ti = ti+1; % Time index
  255. xh = x(t-tau).*h3(tau); lxh = length(xh);
  256. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  257. subplot(2,1,1),plot(tau,h3(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
  258. axis([tau(1) tau(end) -2.0 2.5]);
  259. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  260. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  261. [.8 .8 .8],'edgecolor','none');
  262. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  263. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  264. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  265. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  266. axis([tau(1) tau(end) -1.0 2.0]); grid;
  267. drawnow;
  268. end
  269.  
  270. figure;
  271. u = @(t) 1.0*(t>=0);
  272. h4 = @(t) 4*(exp(-t/5) - exp(-t)).*u(t);
  273. x = @(t) u(t) - u(t-3);
  274. dtau = 0.005; tau = 0:dtau:20;
  275. ti = 0; tvec = 0:.1:20;
  276. y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
  277. for t = tvec,
  278. ti = ti+1; % Time index
  279. xh = x(t-tau).*h4(tau); lxh = length(xh);
  280. y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
  281. subplot(2,1,1),plot(tau,h4(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
  282. axis([tau(1) tau(end) -2.0 2.5]);
  283. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
  284. [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
  285. [.8 .8 .8],'edgecolor','none');
  286. xlabel('\tau'); title('h(\tau) [solid], x(t-\tau) [dashed], h(\tau)x(t-\tau) [gray]');
  287. c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
  288. subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
  289. xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau');
  290. axis([tau(1) tau(end) -1.0 2.0]); grid;
  291. drawnow;
  292. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement