You are on page 1of 2

To simulate Binary Phase Shift Keying (PSK)

Source Code:
1. %Roll no:201104006
2. %Name:Amogha Kantak
3. %TE-ETC Engg ,Sem V, 2021-22,GCE
4. clc;
5. clear all;
6. %% message bits
7. b=[1 0 1 0 0 ]; %Entering bit pattern
8. tb = 1;
9. b = repelem(b, tb);
10. n= length(b); % length of bit stream and time axis depending on Tb
11.
12. %% Frequency & Time Specs
13. no_of_cycles_per_bit = 5;
14. fc = no_of_cycles_per_bit/tb;
15. fs = 500;
16. t=0:1/fs:1-1/fs;
17.
18. vc = 2*sin(2*pi*fc*t); %carrier signal
19. s1 = vc;
20. s0 = -vc;
21. %% psk modulation
22. pskm = [];
23. for i = 1:n
24. if b(i) == 1
25. y = s1;
26. else
27. y = s0;
28. end
29. pskm = [pskm y];
30. end
31. psklen = length(pskm);
32.
33. %% bpsk frequency domain
34. fs_new = psklen/n;
35. f = -fs_new/2:1/n:fs_new/2-1/n;
36. freq_psk = abs(fftshift((fft(pskm))));
37.
38. %% plotting
39. figure(1)
40. subplot(3,1,1)
41. stairs(0:n,[b(1:n) b(n)],'linewidth',1.5)
42. axis([0 n -0.5 1.5])
43. title('Message Bits');
44. grid on
45. xlabel('Time');
46. ylabel('Amplitude');
47.
48. subplot(3,1,2)
49. plot(t,vc)
50. title('Carrier signal');
51. grid on
52. xlabel('Time');
53. ylabel('Amplitude');
54.
55. t_new = 0:1/fs:n-1/fs;
56. subplot(3,1,3)
57. plot(t_new/tb,pskm)
58. title('PSK modulation');
59. grid on
60. xlabel('Time');
61. ylabel('Amplitude');
62.
63. figure(2)
64. plot(f,freq_psk)
65. title('Frequency domain');
66. grid on
67. xlabel('Frequency');
68. ylabel('Magnitude');
69. axis([-25 25 0 1300])

You might also like