SHARE
TWEET

Untitled

bl4desofglory Oct 22nd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. % 23.10.2019
  2. % 165678 Tomasz Kisielewski
  3. % Zadanie 2 Modulator/demodulator sygnalu GMSK
  4.  
  5. N = 20; % symobli
  6. M = 20; % sampli
  7. BT = 0.5;
  8.  
  9. input=randi([0,1],[1,N]);
  10.  
  11. figure
  12. plot(1:1:N, Wektor_Wejsciowy, 'k*');
  13. title('Modulator - Wektor wejsciowy');
  14. xlabel('Numer probki');
  15. ylabel('Wartosc probki');
  16. axis([1 N -0.5 1.5]);
  17. ax = gca;
  18. ax.YTick = [0 1];
  19.  
  20. samples = zeros(1,M*N);
  21. for i = 1:1:N
  22.     if input(1,i) == 0
  23.         samples(1,i) = -1;
  24.     end
  25. end
  26.  
  27. samples = repelem(input,M);
  28.  
  29. impulse_response_gaussian = zeros(1,2*M+1);
  30. delta = sqrt(log10(2)/(2*pi*BT));
  31. j = 1;
  32.  
  33. for i = -M:1:M
  34.     t = i/M;
  35.     j = j+1;
  36.     impulse_response_gaussian(1,j) = exp((-t^2)/(2*(delta^2)))/(sqrt(2*pi)*delta);
  37. end
  38.  
  39. filtered_samples = conv(samples, impulse_response_gaussian, 'same');
  40.  
  41. figure
  42. plot(1:1:M*N, filtered_samples);
  43. title('Modulator - Filtr Gaussa');
  44. xlabel('Numer probki');
  45. ylabel('Wartosc probki');
  46.  
  47. integral_samples = zeros(1,N*M);
  48.  
  49. integral_samples(1,1) = filtered_samples(1,1);
  50. for i = 2:1:N*M
  51.     integral_samples(1,i) = integral_samples(1,i-1) + filtered_samples(1,i);
  52. end
  53.  
  54. sin_integral_samples = zeros(1,N*M);
  55. cos_integral_samples = zeros(1,N*M);
  56. for i = 1:1:N*M
  57.     sin_integral_samples(1,i) = sin(integral_samples(1,i)/M);
  58.     cos_integral_samples(1,i) = cos(integral_samples(1,i)/M);
  59. end
  60.  
  61. s = zeros(1, M*N);
  62. c = zeros(1, M*N);
  63. fi = 0;
  64. for i=1:1:N*M
  65.     s(1,i) = sin(fi);
  66.     c(1,i) = cos(fi);
  67.     fi = fi + 0.4*pi;
  68. end
  69.  
  70. s_samples = sin_integral_samples.*s;
  71. c_samples = cos_integral_samples.*c;
  72. mod_out_samples = s_samples + c_samples;
  73.  
  74. figure
  75. plot(1:1:M*N, mod_out_samples);
  76. title('Modulator - Wektor Wyjsciowy');
  77. xlabel('Numer probki');
  78. ylabel('Wartosc probki');
  79.  
  80. % =========================================
  81.  
  82. d_in_samples = mod_out_samples;
  83. d_s_samples = d_in_samples.*c;
  84. d_c_samples = d_in_samples.*s;
  85.  
  86. f_lp = zeros(1, N*M);
  87. fi = -20*pi;
  88. for n = 1:1:N*M
  89.     f_lp(1,n) = sin(fi)/fi;
  90.     fi = fi + pi/10;
  91. end
  92.  
  93. d_f_lp_I = conv(d_s_samples, f_lp, 'same');
  94. d_f_lp_Q = conv(d_c_samples, f_lp, 'same');
  95.  
  96. figure
  97. plot(1:1:M*N, d_f_lp_I, 'k-', 1:1:M*N, d_f_lp_Q, 'r-');
  98. title('Demodulator - I i Q po filtrze dolnoprzepustowym');
  99. xlabel('Numer probki');
  100. ylabel('Wartosc probki');
  101.  
  102. d_f_lp_I_diff = zeros(1,N*M);
  103. d_f_lp_Q_diff = zeros(1,N*M);
  104. d_f_lp_I_diff(1,1) = d_f_lp_I(1,1);
  105. d_f_lp_Q_diff(1,1) = d_f_lp_Q(1,1);
  106. for i = 2:1:N*M
  107.     d_f_lp_I_diff(1,i) = d_f_lp_I(1,i) - d_f_lp_I(1,i-1);
  108.     d_f_lp_Q_diff(1,i) = d_f_lp_Q(1,i) - d_f_lp_Q(1,i-1);
  109. end
  110.  
  111. d_f_lp_I_diff_Q = d_f_lp_I.*d_f_lp_Q_diff;
  112. d_f_lp_Q_diff_I = d_f_lp_Q.*d_f_lp_I_diff;
  113.  
  114. d_diff_IQ = d_f_lp_I_diff_Q - d_f_lp_Q_diff_I;
  115.  
  116. figure
  117. plot(1:1:M*N, d_diff_IQ);
  118. title('Demodulator - I i Q zsumowane');
  119. xlabel('Numer probki');
  120. ylabel('Wartosc probki');
  121.  
  122. d_int_diff = zeros(1, N);
  123.  
  124. for i=1:1:N
  125.     for j=1:1:M
  126.         d_int_diff(1,i) = d_int_diff(1,i) + d_diff_IQ(1,(i-1)*M + j);
  127.     end
  128. end
  129.  
  130. d_out = zeros(1, N);
  131. for i = 1:1:N
  132.     if(d_int_diff(1,i) < 0)
  133.         d_out(1,i) =  0;
  134.     elseif(d_int_diff(1,i) > 0)
  135.         d_out(1,i) =  1;
  136.     end
  137. end
  138.  
  139. figure
  140. plot(1:1:N, d_out, 'k*');
  141. title('Demodulator - Wektor wyjsciowy ');
  142. xlabel('Numer probki');
  143. ylabel('Wartosc probki');
  144. axis([1 N -0.5 1.5]);
  145. ax = gca;
  146. ax.YTick = [0 1];
  147.  
  148. if(isequal(input, d_out))
  149.     disp('Wektor wejsciowy i wyjsciowy sa rowne');
  150. else
  151.     disp('Odebrany sygnal nie jest nadanym!')
  152. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top