Advertisement
Guest User

HW 2

a guest
May 29th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.25 KB | None | 0 0
  1. %% Homework 2
  2. %% Problem 1
  3. close all
  4. n=[1];
  5. d=conv([1 1],[1 1 20]);
  6. hw=tf(n,d)
  7. t=0:1/1000:10*pi;
  8. x=cos(3.0*t).*heaviside(t)+2*heaviside(t)+cos(10.0*t).*exp(-t).*heaviside(t);
  9. figure
  10. bode(hw)
  11. figure
  12. asymp(hw)
  13. figure
  14. lsim(hw,x,t)
  15.  
  16. [m3,p3]=bode(hw,3)
  17. [m0,p0]=bode(hw,0)
  18.  
  19. %% Problem 2
  20. close all
  21. n=[0.1];
  22. d=conv([1 -0.9],[1 -1.8 0.9]);
  23. hw=tf(n,d,1)
  24. t=0:1:300;
  25. x=sin(0.1*t).*heaviside(t+1)+2*heaviside(t);
  26. % figure
  27. % step(hw)
  28. figure
  29. bode(hw)
  30. figure
  31. lsim(hw,x,t)
  32.  
  33. [mp1,pp1]=bode(hw,0.1)
  34. [m0,p0]=bode(hw,0)
  35.  
  36. %% Problem 3
  37. close all;
  38. fc=10;
  39. wc=1;
  40. [b,a]=butter(2,wc,'high','s')
  41. hw=tf(b,a)
  42. figure
  43. bode(hw)
  44. [m,p,f]=bode(hw);
  45.  
  46. freq=0;
  47. for i = 1:1:length(m)
  48.     if m(i) >= 0.99
  49.         freq=f(i);
  50.         break
  51.     end
  52. end
  53.  
  54.  
  55. freq
  56. wc=2*pi*fc/freq
  57. [b,a]=butter(2,wc,'high','s')
  58. hw=tf(b,a)
  59. figure
  60. bode(hw,{0.1,1000})
  61. [m,p]=bode(hw,0.1*2*pi);
  62. atten=20*log10(m)
  63.  
  64. %% Problem 4
  65. close all;
  66. fc=10;
  67. fs=20000;
  68. fn=1000;
  69. Ts=1/fs;
  70. wc=2*pi*fc;
  71.  
  72. min_wn = 99999;
  73. omega = wc*Ts;
  74. for wn = omega:0.0001:0.05
  75.     m = bode(tf([wn],[1 wn-1],1),omega);
  76.     if m >= 0.99
  77.         if wn < min_wn
  78.             min_wn = wn;
  79.         end
  80.     end
  81. end
  82.  
  83. wn=min_wn
  84. hw=tf([wn],[1 wn-1],1)
  85. figure
  86. bode(hw)
  87. m = bode(hw,2*pi*fn*Ts)
  88. atten=20*log10(m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement