Académique Documents
Professionnel Documents
Culture Documents
clearall;
closeall;
fismat=readfis(main.fis);
%PU STATUS
pu=input(Enter status of the PU (1=Present/0=Absent):);
% SCATTER PLOT
% Considering a geographic area with random number of CR terminals. Random
% count is generated by the following function
count=randi([25 50],1,1);
% Random x-y coordinates are generated for all CR terminals
X=randi([0 9],1,count)+0.01*randi([0 100],1,count);
Y=randi([0 9],1,count)+0.01*randi([0100],1,count);
% Scatter Plot showing location of all CR terminals
scatter(X,Y,100,g);
% The first CR terminal is selected as the central node and the distance
s
% from all otehr terminals to the central node are calculated and stored
in
% an array
for k=1:countdistanceunsort(k)=sqrt(((X(1)-X(k))^2)+((Y(1)-Y(k))^2));
end;
% The two closest neighbours are selected after sorting the distance array
distance=sort(distanceunsort);
for xx=1:3
forij=1:count
if ( distance(xx)== distanceunsort(ij))
x(xx)=X(ij);
y(xx)=Y(ij);
end
end
end
% Location of central node and neighbours in the scatter plot are
% displayed
for m=2:3
line([x(1),x(m)],[y(1),y(m)]);
pause(0.5);
end;
% Zoomed view of central node and its neighbours
figure;
scatter(x,y,100,g);
for m=2:3
line([x(1),x(m)],[y(1),y(m)]);
pause(1);
end;
for ii=1:3
% CHANNEL MODELING
c = r a yl e i g h c h a n ( 1 / 1 0 0 0 , 1 0 0 ) ; % R a yl e i g h F a d i n g C h a n n e l M o d e l
if(pu==1)
y=filter(c,bpsk_w); % Convolution of transmitted signal with Rayleigh
Fa
else
y = 0 ; % N o t r a n s m i s s i o n ( A b s e n c e o
f P r i m a r y U s e r )
end;
% Random SNR generation between -25.00dB and 10.00dB
snr=randi([-25 9],1,1)+0.01*randi([0 100],1,1);
% Adding White Gaussian Noise with a defined value for SNR
q=awgn(y,snr);
% RECEIVER
% Band Pass Filter
ww=fdesign.bandpass(N,F3dB1,F3dB2,2,0.7e9,1.1e9,10e10); % Design BPF by specifyin
g
Hd=design(ww,butter); % Butterworth filter
z = f i l t e r ( H d , q ) ; % C o n v o l u t e d O u t p u t
% Power Detector
d a = f f t ( z ) ; % T a k i n g F F T o f r e c e i v e
d s i g n a l
v = d a . ^ 2 ; % S q u a r i n g a l l
t e r m s
% Taking average of all terms to obtain Power of received signal
power(ii)=20*log10(abs(mean(v)));
% Storing SNR of central node and neighbours
snnr(ii)=snr;
% Demodulator
we=z.*cos(2*pi*fc*t);
% Multiplying with carrier
%Low Pass Butterworth Filter - Integrator
wqq=fdesign.lowpass(N,Fc,4,1e9,10e10);
Hd2=design(wqq,butter);
zqq=filter(Hd2,we); %Convolution
end;
end;
% FUZZY FILE
disp(CR1 Power (in dB): ); disp(power(1));
disp(CR1 SNR (in dB): ); disp(snnr(1));
disp(CR2 Power (in dB): ); disp(power(2));
disp(CR3 Power (in dB): ); disp(power(3));
% Single Node Decision
if (power(1)>30 &pu==1)
% sncount=sncount+1;
end;
% Fuzzy Decision
if(evalfis([power(1) snnr(1) power(2) power(3)],fismat)>=0.5)
disp(PU is Present);
else
disp(PU is Absent);
end;