MarouaneTheViper

Untitled

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