Cognitive Radio System: 1. Square-Root Raised Cosinefilter User Define Function
Cognitive Radio System: 1. Square-Root Raised Cosinefilter User Define Function
1. close all;
2. clear all;
3. clc
4. disp(' ');
5. disp(' This program simulate a cognitive radio spectrum sensing
system: ');
6. disp(' ----------------------------------------------------------
------ ');
7. disp(' ');
8. disp(' - The system first received a signal from channel ');
9. disp(' ');
84
Appendix
85
Appendix
56. rt = rt + 1;
57. end
58. end
59. % % Transmit Filter %
60. % pT=sr_cos_p(N,L,alpha); % Transmit filter:
61.
62. overSampling_Factor=8;
63.
64. pT = srrc(overSampling_Factor,alpha); % impulse response of
SRRC filter
65.
66. Input_bit_os=upsample(RR,8); %oversampling
67. % Input=double(Input_bit_os); %conv not work with binary
convert it to double
68.
69. xT=conv(Input_bit_os,pT); %Transmit signal (the user signal
send it pt_dt)
70. % xT=conv(Input_bit_os,pT); % Transmit signal
71.
72. % % Modulation %
73. display('Select Type of Modulation');
74. display('1. BPSK'); display('2. QPSK');
75. Mod_Type = input('Plz Enter the Type of Modulation:','s');
76.
77. snr = input('Plz Enter the SNR');
78.
79. Carrier = [];
80. % % BPSK Modulation %
81. if (Mod_Type=='1')
82. m=582370;
83. display('Binary PSK');
84. for ii = 1:1:length(T)
85. car1(ii) = sin((2*pi*f*T(ii))); %CARRIER
TO BE TRANSMITTED
86. end
87. for ii = 1:1:length(xT)
88. ifxT(ii) == '0'
89. car = -1*car1;
90. else
91. car = 1*car1;
92. end
93. Carrier = [Carrier car];
94. end
95. % % QPSK Modulation %
96. elseif(Mod_Type=='2')
97. m=10907;
98. display('Quadrature PSK');
99. for ii = 1:1:length(T)
100. car1(ii) = sin((2*pi*f*T(ii))+360); %CARRIER TO
BE TRANSMITTED
86
Appendix
87
Appendix
6. HpsdFreq = Hpsd.Frequencies;
7. Hpsddata = Hpsd.data;
8.
9.
10. figure
11. hold on
12. plot(Hpsd)
13.
14. %%%%%%%%% threshold line %%%%%%%%%%
15. for ii=1:1:11
16. xmax(ii)=10*log10(m);
17. end
18. c=0:0.2:2;
19.
20. plot(c,xmax,'k:')
21. axis([0 2 -80 80]);
22. legend('Data PSD','Threshold');
23. grid off
24. hold off
25.
26.
27.
28. if (max(Hpsddata)> m)
29. disp('primary user is present');
30. else
31. disp('primary user is absent');
32. end
33. figure
1. for ii = 1:1:length(T)
2. car1(ii) = sin((2*pi*f*T(ii))+360); %CARRIER TO BE
TRANSMITTED
3. car2(ii) = sin((2*pi*f*T(ii))+90); %CARRIER TO BE
TRANSMITTED
4. car3(ii) = sin((2*pi*f*T(ii))+180); %CARRIER TO BE
TRANSMITTED
5. car4(ii) = sin((2*pi*f*T(ii))+270); %CARRIER TO BE
TRANSMITTED
6. end
7.
8. res1= xcorr(xR(1:20),car1)* 10^14;
9. res2= xcorr(xR(1:20),car2)* 10^14;
10. res3= xcorr(xR(1:20),car3)* 10^14;
11. res4= xcorr(xR(1:20),car4)* 10^14;
12.
13. r1=mean(res1)*10000;
14. r2=mean(res2)*10000;
88
Appendix
15. r3=mean(res3)*10000;
16. r4=mean(res4)*10000;
17. disp(' ');
18. disp('2. Matched filter sensing technique');
19. disp(' ');
20. if ((r1>1690)&& (r2<-560) && (r3>1250) && (r4<-2300))
21. %Primary user is present
22. display ('primary user is present');
23. else%Primary user is absent
24. display ('primary user is absent');
25. end
26. disp(' ');
27.
28. r1
29. r2
30. r3
31. r4
32. subplot(2,1,1)
33. plot(res1+res2+res3+res4)
34. legend('Received Signal')
35. axis([0 40 -10^15 10^15]);
36.
37. xlabel('Time (sec)')
38. ylabel('Amplitude')
39.
40.
41. %%_________________________________________________________
_________________________
42.
43.
44.
45. % %threshold SOURCE: Take input data from user for
transmission %
46. % pt_dt = input('Data you want to send:','s');
47. % R = isempty(pt_dt);
48. RR1=[33 33];
49. bb = 1;
50. Rp1 = dec2bin(RR1,8);
51. [TA1, TC1] = size(Rp1);
52. forll = 1:1:TA1
53. forlg = 1:1:TC
54. msg1(bb) = Rp1(ll,lg);
55. bb = bb + 1;
56. end
57. end
58. rt = 1;
59. ht = 1;
60. forls = 1:1:TA1
61. forll = 1:2:(TC1)
89
Appendix
90
Appendix
91