Advertisement
Wolan1995

PTS zajęcia 2

Nov 16th, 2017
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.96 KB | None | 0 0
  1. %SPLOT ANALOGOWY
  2. function x=ACT(f1,f2,time,eps);
  3. %eps=0.01;
  4. t=0:eps:time;
  5. y=feval(f1,t);
  6. z=feval(f2,t);
  7. % convolution of analog signals, method from APPENDIX B
  8. len=length(t);
  9. splot=zeros(1,len);
  10. for i=1:len
  11.    for k=1:i
  12.       splot(i)=splot(i)+feval(f1,t(k)).*feval(f2,t(i)-t(k));
  13.    end
  14.    splot(i)=splot(i)*eps;
  15.    x=splot(i);
  16. end
  17. subplot(4,1,1),plot(t,y);grid on
  18. subplot(4,1,2),plot(t,z);grid on
  19. subplot(4,1,3:4),plot(t,splot);grid on
  20. disp('value of conv at point t=');
  21. disp(time);
  22. disp('is equal to:');
  23. disp(x);
  24.  
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26.  
  27. function y = Analogowa(t)
  28. y=2.*heaviside(t)-3.*heaviside(t-1)+heaviside(t-2);
  29. end
  30.  
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32.  
  33. function y=funkcja(t)
  34. y=2*(t+2).*heaviside(t+2)-2*t .* heaviside(t) - ((t/2)+1).*heaviside(t-2) + ((t/2)-3).*heaviside(t-4);
  35. return
  36.  
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38.  
  39. funkcja rysowanie
  40. t=-10:0.001:5;
  41. y=funkcja(t);
  42. plot (t,y); xlabel ('X'), ylabel('Y'), title('Sygnał'), grid on
  43.  
  44. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  45.  
  46. %Z wykladu dyskretny, dziala
  47. function y=splot(x1,x2,p1,p2)
  48.  
  49. %oblicz minimalna dlugosc wektora czasu dyskretnego
  50. len=length(x1)+length(x2); %wektor dlugosci sygna?ów ograniczonych
  51. minlen=len-1;
  52. mv=p1+p2
  53. dt=(p1+p2):minlen-1+(p1+p2);               % skala dyskretnego czasu
  54. % aby ?atwiej rysowa? i liczy? dope?nij wektory zerami
  55. x11=zeros(1,minlen-length(x1));
  56. x1=[x1 x11];
  57. x22=zeros(1,minlen-length(x2));
  58. x2=[x2 x22];
  59. y=zeros(1,minlen);
  60. for n=1:minlen          %petla zewnetrzna
  61.     for k=1:n           % pętla wewn?trzna
  62.         y(n)=y(n)+x1(k)*x2(n-k+1);
  63.     end
  64. end
  65. %stem(dt,y)
  66. subplot(4,1,1); stem(dt-mv+p1,x1)
  67. title('Sygnal pierwszy')
  68. subplot(4,1,2); stem(dt-mv+p2,x2)
  69. title('Sygnal drugi')
  70. subplot(4,1,3:4); stem(dt,y); grid on
  71. title('Splot sygnalów')
  72.  
  73. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement