MarouaneTheViper

Untitled

Mar 22nd, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. bits = 10;
  2. bitrate = 1;
  3. rand_bits = randi([0 1], 1,bits);
  4.  
  5. N = 100;
  6. T = length(rand_bits) / bitrate;
  7. Ts = 1/N;
  8. t = 0: Ts: T;
  9. s = zeros(1, length(t));
  10.  
  11.  
  12.  
  13. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Polar NRZ
  14. for i = 0:length(rand_bits)-1
  15. if rand_bits(i+1) == 1
  16. s(i*N+1:(i+1)*N) = 1;
  17. else
  18. s(i*N+1:(i+1)*N) = -1;
  19. end
  20. end
  21. subplot (6,2,1)
  22. plot (t , s,'LineWidth', 3);
  23. axis([0 t(end) -1.1 1.1]);
  24. grid on;
  25. title([' Polar NRZ: [' num2str(rand_bits) ']']);
  26. h = spectrum.welch;
  27. t_pwelch = psd(h,s,'Fs',N);
  28. subplot(6,2,2)
  29. plot(t_pwelch);
  30. title('Power Spectral Density');
  31.  
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Inverted Polar NRZ
  33.  
  34. for i = 0:length(rand_bits)-1
  35. if rand_bits(i+1) == 1
  36. x(i*N+1:(i+1)*N) = -1;
  37. else
  38. x(i*N+1:(i+1)*N) = 1;
  39. end
  40. end
  41. subplot (6,2,3)
  42. plot (t , x,'LineWidth', 3);
  43. axis([0 t(end) -1.1 1.1]);
  44. grid on;
  45. title(['Inverted Polar NRZ: [' num2str(rand_bits) ']']);
  46. h = spectrum.welch;
  47. t_psd = psd(h,x,'Fs',N);
  48. subplot(6,2,4)
  49. plot(t_psd);
  50. title('Power Spectral Density');
  51.  
  52. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Unipolar RZ
  53. for i = 0: length(rand_bits) - 1
  54. if rand_bits(i+1) == 1
  55. s((i*N)+1:(i+1)*N) = 1;
  56. else
  57. s(i*N+1 : (i+1)*N) = 0;
  58. end
  59. end
  60. subplot(6,2,5)
  61. plot(t, s,'LineWidth', 3);
  62. axis([0 t(end) -0.1 1.1]);
  63. grid on;
  64. title(['Unipolar NRZ: [' num2str(rand_bits) ']']);
  65. h = spectrum.welch;
  66. t_psd = psd(h,x,'Fs',N);
  67. subplot(6,2,6)
  68. plot(t_psd);
  69. title('Power Spectral Density');
  70.  
  71. x = zeros(1, length(t));
  72. for i = 0 : length(rand_bits)-1
  73. if rand_bits(i+1) == 1
  74. x((i*N)+1:(i+0.5)*N) = 1;
  75. x((i+0.5)*N+1:(i+1)*N) = 0;
  76. else
  77. x(i*N+1:(i+1)*N) = 0;
  78. end
  79. end
  80. subplot(6,2,7)
  81. plot(t, s,'LineWidth', 3);
  82. axis([0 t(end) -0.1 1.1]);
  83. grid on;
  84. title(['Unipolar RZ: [' num2str(rand_bits) ']']);
  85. h = spectrum.welch;
  86. t_psd = psd(h,x,'Fs',N);
  87. subplot(6,2,8)
  88. plot(t_psd);
  89. title('Power Spectral Density');
  90.  
  91. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Polar RZ
  92.  
  93. for i = 0:length(rand_bits)-1
  94. if rand_bits(i+1) == 1
  95. x(i*N+1:(i+0.5)*N) = 1;
  96. x((i+0.5)*N+1:(i+1)*N) = 0;
  97. else
  98. x(i*N+1:(i+0.5)*N) = -1;
  99. x((i+0.5)*N+1:(i+1)*N) = 0;
  100. end
  101. end
  102.  
  103. subplot(6,2,9)
  104. plot(t, x,'LineWidth', 3);
  105. axis([0 t(end) -1.1 1.1]);
  106. grid on;
  107. title(['Polar RZ: [' num2str(rand_bits) ']']);
  108. h = spectrum.welch;
  109. t_psd = psd(h,x,'Fs',N);
  110. subplot(6,2,10)
  111. plot(t_psd);
  112. title('Power Spectral Density');
  113.  
  114. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Manchester
  115. for i = 0:length(rand_bits)-1
  116. if rand_bits(i+1) == 1
  117. x(i*N+1:(i+0.5)*N) = 1;
  118. x((i+0.5)*N+1:(i+1)*N) = -1;
  119. else
  120. x(i*N+1:(i+0.5)*N) = -1;
  121. x((i+0.5)*N+1:(i+1)*N) = 1;
  122. end
  123. end
  124. subplot(6,2,11)
  125. plot(t, x,'LineWidth', 3);
  126. axis([0 t(end) -1.1 1.1]);
  127. grid on;
  128. title(['Manchester: [' num2str(rand_bits) ']']);
  129. h = spectrum.welch;
  130. t_psd = psd(h,x,'Fs',N);
  131. subplot(6,2,12)
  132. plot(t_psd);
  133. title('Power Spectral Density');
Advertisement
Add Comment
Please, Sign In to add comment