bl4desofglory

Untitled

Oct 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. % 154994 2 �liwowski Hubert
  2.  
  3. clear all
  4. %------------------------------Modulator-------------------------
  5. N = 20; %d�ugo�� wektora wej�ciowego
  6. M = 20; %ilo�� pr�bek
  7.  
  8. %Generowanie symboli
  9. Wektor_Wejsciowy = randi([0 1],1,N);
  10. %Wykres 1
  11. figure
  12. plot(1:1:N, Wektor_Wejsciowy, 'k*');
  13. title('Modulator - Wektor wej�ciowy');
  14. xlabel('Numer pr�bki');
  15. ylabel('Warto�� pr�bki');
  16. axis([1 N -0.5 1.5]);
  17. ax = gca;
  18. ax.YTick = [0 1];
  19. %Koniec 'Wykres 1'
  20.  
  21. %Zamiana 0 na -1
  22. Wektor_Wejsciowy_bez0_Mprobek = zeros(1,N*M);
  23. for i=1:1:N
  24. if(Wektor_Wejsciowy(i) == 1)
  25. Wektor_Wejsciowy_bez0_Mprobek(1,1 + (i-1)*20:i*20) = ones([1,20]);
  26. elseif(Wektor_Wejsciowy(i) == 0)
  27. Wektor_Wejsciowy_bez0_Mprobek(1,1 + (i-1)*20:i*20) = -ones([1,20]);
  28. end
  29. end
  30.  
  31. %Filtr Gausowski
  32. OdpowiedzImpulsowaFiltruGausowskiego = zeros(1,40);
  33. BT = 0.5;
  34. delta = sqrt(log10(2)/(2*pi*BT)); %Obliczenie delta
  35. krok = 0;
  36. for j=-M:1:M
  37. t = j/M;
  38. krok = krok + 1;
  39. OdpowiedzImpulsowaFiltruGausowskiego(1,krok) = exp((-t^2)/(2*(delta^2)))/(sqrt(2*pi)*delta);
  40. end
  41.  
  42. %-----splot-----
  43. Wektor_Po_Filtrowaniu = conv(Wektor_Wejsciowy_bez0_Mprobek, OdpowiedzImpulsowaFiltruGausowskiego, 'same');
  44. %Wykres 2
  45. figure
  46. plot(1:1:M*N, Wektor_Po_Filtrowaniu);
  47. title('Modulator - Filtr Gaussa');
  48. xlabel('Numer pr�bki');
  49. ylabel('Warto�� pr�bki');
  50. %Koniec 'Wykres 2'
  51.  
  52. %Ca�kowanie
  53. Wektor_Po_Calkowaniu = zeros(1, N*M);
  54. Wektor_Po_Calkowaniu(1,1) = Wektor_Po_Filtrowaniu(1,1);
  55. for i=2:1:N*M
  56. Wektor_Po_Calkowaniu(1,i) = Wektor_Po_Calkowaniu(1,i-1) + Wektor_Po_Filtrowaniu(1,i);
  57. end
  58.  
  59. %Oblicznie sinusa z wektora po ca�kowaniu
  60. Wektor_Po_Sinus = zeros(1,N*M);
  61. Wektor_Po_Cosinus = zeros(1,N*M);
  62. for i=1:1:N*M
  63. Wektor_Po_Sinus(1,i) = sin(Wektor_Po_Calkowaniu(1,i)/100);
  64. Wektor_Po_Cosinus(1,i) = cos(Wektor_Po_Calkowaniu(1,i)/100);
  65. end
  66.  
  67. %Obliczanie sinus�w oraz iloczynu z wektorem
  68. Sinus0 = zeros(1, M*N);
  69. Sinus90 = zeros(1, M*N);
  70. kat = 0;
  71. for n=1:1:N*M
  72. Sinus0(n) = sin(kat);
  73. Sinus90(n) = cos(kat);
  74. kat = kat + 0.4*pi;
  75. end
  76.  
  77. Wektor_Po_Sinus0 = Wektor_Po_Sinus.*Sinus0;
  78. Wektor_Po_Sinus90 = Wektor_Po_Cosinus.*Sinus90;
  79. Wektor_Wyjsciowy = Wektor_Po_Sinus0 + Wektor_Po_Sinus90;
  80. %Wykres 3
  81. figure
  82. plot(1:1:M*N, Wektor_Wyjsciowy);
  83. title('Modulator - Wektor Wyjsciowy');
  84. xlabel('Numer pr�bki');
  85. ylabel('Warto�� pr�bki');
  86.  
  87. %---------------DEMODULATOR----------------
  88. Wektor_Demodulator_Wejscie = Wektor_Wyjsciowy;
  89. %Mno�enie sinus0 i sinus90
  90. Wektor_Demodulator_Sinus0 = Wektor_Demodulator_Wejscie.*Sinus90;
  91. Wektor_Demodulator_Sinus90 = Wektor_Demodulator_Wejscie.*Sinus0;
  92.  
  93. %Filtr Dolnoprzepustowy
  94. Filtr_Dolnoprzepustowy = zeros(1, N*M);
  95. kat = -20*pi;
  96. for n=1:1:N*M
  97. Filtr_Dolnoprzepustowy(n) = sin(kat)/kat;
  98. kat = kat + pi/10;
  99. end
  100.  
  101. %Filtracja Filtem Dolnoprzepustowym
  102. Wektor_Demodulator_FDP_I = conv(Wektor_Demodulator_Sinus0, Filtr_Dolnoprzepustowy, 'same');
  103. Wektor_Demodulator_FDP_Q = conv(Wektor_Demodulator_Sinus90, Filtr_Dolnoprzepustowy, 'same');
  104. %Wykres 4
  105. figure
  106. plot(1:1:M*N, Wektor_Demodulator_FDP_I, 'k-', 1:1:M*N, Wektor_Demodulator_FDP_Q, 'r-');
  107. title('Demodulator - I i Q po filtrze dolnoprzepustowym');
  108. xlabel('Numer pr�bki');
  109. ylabel('Warto�� pr�bki');
  110.  
  111. %R�niczki i odejmowanie
  112. Wektor_Demodulator_FDP_I_rozniczka = zeros(1, N*M);
  113. Wektor_Demodulator_FDP_Q_rozniczka = zeros(1, N*M);
  114. Wektor_Demodulator_FDP_I_rozniczka(1) = Wektor_Demodulator_FDP_I(1);
  115. Wektor_Demodulator_FDP_Q_rozniczka(1) = Wektor_Demodulator_FDP_Q(1);
  116. for i=2:1:N*M
  117. Wektor_Demodulator_FDP_I_rozniczka(i) = Wektor_Demodulator_FDP_I(i) - Wektor_Demodulator_FDP_I(i-1);
  118. Wektor_Demodulator_FDP_Q_rozniczka(i) = Wektor_Demodulator_FDP_Q(i) - Wektor_Demodulator_FDP_Q(i-1);
  119. end
  120.  
  121. Wektor_Demodulator_FDP_I_dQ = Wektor_Demodulator_FDP_I.*Wektor_Demodulator_FDP_Q_rozniczka;
  122. Wektor_Demodulator_FDP_Q_dI = Wektor_Demodulator_FDP_Q.*Wektor_Demodulator_FDP_I_rozniczka;
  123.  
  124. Wektor_Demodulator_Po_Sumatorze = Wektor_Demodulator_FDP_I_dQ - Wektor_Demodulator_FDP_Q_dI;
  125. %Wykres5
  126. figure
  127. plot(1:1:M*N, Wektor_Demodulator_Po_Sumatorze);
  128. title('Demodulator - I i Q zsumowane');
  129. xlabel('Numer pr�bki');
  130. ylabel('Warto�� pr�bki');
  131.  
  132. %Ca�kowanie
  133. Wektor_Demodulator_Po_Calkowaniu = zeros(1, N);
  134. for i=1:1:N
  135. for j=1:1:M
  136. Wektor_Demodulator_Po_Calkowaniu(i) = Wektor_Demodulator_Po_Calkowaniu(i) + Wektor_Demodulator_Po_Sumatorze((i-1)*M + j);
  137. end
  138. end
  139.  
  140. %Uk�ad decyzyjny
  141. Wektor_Demodulator_Wyjsciowy = zeros(1, N);
  142. for i=1:1:N
  143. if(Wektor_Demodulator_Po_Calkowaniu(i) < 0)
  144. Wektor_Demodulator_Wyjsciowy(i) = 0;
  145. elseif(Wektor_Demodulator_Po_Calkowaniu(i) > 0)
  146. Wektor_Demodulator_Wyjsciowy(i) = 1;
  147. end;
  148. end
  149. %Wykres6
  150. figure
  151. plot(1:1:N, Wektor_Demodulator_Wyjsciowy, 'k*');
  152. title('Demodulator - Wektor wyjsciowy ');
  153. xlabel('Numer pr�bki');
  154. ylabel('Warto�� pr�bki');
  155.  
  156. if(isequal(Wektor_Wejsciowy, Wektor_Demodulator_Wyjsciowy))
  157. disp('s154994_2: Wektor wejsciowy i odebrany sa takie same !');
  158. end
Add Comment
Please, Sign In to add comment