MarouaneTheViper

Untitled

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