th0m45s5helby

DC new

Feb 25th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. %>>>>>>>>> MATLAB code for binary PSK modulation and de-modulation >>>>>>>%
  2.  
  3. clc;
  4. clear all;
  5. close all;
  6.  
  7.  
  8. x=[ 1 0 0 1 1 0 1]; % Binary Information
  9. bp=.000001; % bit period
  10. disp(' Binary information at Trans mitter :');
  11. disp(x);
  12.  
  13. %XX representation of transmitting binary information as digital signal XXX
  14. bit=[];
  15. for n=1:1:length(x)
  16. if x(n)==1;
  17. se=ones(1,100);
  18. else x(n)==0;
  19. se=zeros(1,100);
  20. end
  21. bit=[bit se];
  22.  
  23. end
  24. t1=bp/100:bp/100:100*length(x)*(bp/100);
  25. subplot(3,1,1);
  26. plot(t1,bit,'lineWidth',2.5);grid on;
  27. axis([ 0 bp*length(x) -.5 1.5]);
  28. ylabel('amplitude(volt)');
  29. xlabel(' time(sec)');
  30. title('transmitting information as digital signal');
  31.  
  32.  
  33.  
  34. %XXXXXXXXXXXXXXXXXXXXXXX Binary-PSK modulation XXXXXXXXXXXXXXXXXXXXXXXXXXX%
  35. A=5; % Amplitude of carrier signal
  36. br=1/bp; % bit rate
  37. f=br*2; % carrier frequency
  38. t2=bp/99:bp/99:bp;
  39. ss=length(t2);
  40. m=[];
  41. for (i=1:1:length(x))
  42. if (x(i)==1)
  43. y=A*cos(2*pi*f*t2);
  44. else
  45. y=A*cos(2*pi*f*t2+pi); %A*cos(2*pi*f*t+pi) means -A*cos(2*pi*f*t)
  46. end
  47. m=[m y];
  48. end
  49. t3=bp/99:bp/99:bp*length(x);
  50. subplot(3,1,2);
  51. plot(t3,m);
  52. xlabel('time(sec)');
  53. ylabel('amplitude(volt)');
  54. title('waveform for binary PSK modulation coresponding binary information');
  55.  
  56.  
  57.  
  58.  
  59. %XXXXXXXXXXXXXXXXXXXX Binary PSK demodulation XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  60. mn=[];
  61. for n=ss:ss:length(m)
  62. t=bp/99:bp/99:bp;
  63. y=cos(2*pi*f*t); % carrier siignal
  64. mm=y.*m((n-(ss-1)):n);
  65. t4=bp/99:bp/99:bp;
  66. z=trapz(t4,mm) % intregation
  67. zz=round((2*z/bp))
  68. if(zz>0) % logic level = (A+A)/2=0
  69. %becouse A*cos(2*pi*f*t+pi) means -A*cos(2*pi*f*t)
  70. a=1;
  71. else
  72. a=0;
  73. end
  74. mn=[mn a];
  75. end
  76. disp(' Binary information at Reciver :');
  77. disp(mn);
  78.  
  79.  
  80. %XXXXX Representation of binary information as digital signal which achived
  81. %after PSK demodulation XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  82. bit=[];
  83. for n=1:length(mn);
  84. if mn(n)==1;
  85. se=ones(1,100);
  86. else mn(n)==0;
  87. se=zeros(1,100);
  88. end
  89. bit=[bit se];
  90.  
  91. end
  92. t4=bp/100:bp/100:100*length(mn)*(bp/100);
  93. subplot(3,1,3)
  94. plot(t4,bit,'LineWidth',2.5);grid on;
  95. axis([ 0 bp*length(mn) -.5 1.5]);
  96. ylabel('amplitude(volt)');
  97. xlabel(' time(sec)');
  98. title('recived information as digital signal after binary PSK demodulation');
  99.  
  100.  
  101.  
  102. %>>>>>>>>>>>>>>>>>>>>>>>>>> end of program >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
Add Comment
Please, Sign In to add comment