sorry for my late reply........ i tried to start to implement the energy detection technique with a simple code using QPSK but there was a different between the simulated curve and the theoretical curve ........ i designed the code based on constant false alarm rate , please help me in finding the problem in the code
here is the code :
clear all
clc
N1=1024;
% N = [100:100:1000]; % number of bits or symbols
Eb_N0_dB=-12 ;
Eb_N0=db2pow(Eb_N0_dB);
detect=0;
ip = randint(1,2*N1);
pf=0:.01:1;
for i=1:length(pf)
% s = 2*ip-1;
a=modem.pskmod(4);
a.inputtype='bit';
s=modulate(a,ip.').';
% for i = 1:length(pfvbv)
for m=1:50 %%% number of observations
n = 1/sqrt(2)*[randn(1,N1) + j*randn(1,N1)];
% Noise addition
w=10^(-Eb_N0_dB/20)*n;
y = s+w; % additive white gaussian noise
%%%%%% secondary user%%%%%%%
varn(i)=var(w); %%%%% noise variance
th(i)=varn(i)*(qfuncinv(pf(i))*sqrt(2*N1)+N1); %%%% threshold calculation
%%%%% number of samples N=1024
yf=fft
;
en(m)=sum(abs(yf).^2)/N1;%%% Calculating energy
a1(i)=(th(i)/varn(i))-(N1*(Eb_N0+1));
b(i)=(sqrt(2*N1))*(Eb_N0+1);
if en(m)>th(i)
detect=detect+1;
end
end
pd_sim(i)=detect/m;
detect=0;
pd_th(i)=qfunc(a1(i)/b(i));
end
plot(pf,pd_th)
hold on
plot(pf,pd_sim,'r')
legend('theroy','simulated')
% end
% clear all
% clc
% pf=0:.01:1;
% snr_dB=-12;
% n=1024
% for i=1:length(pf)
% snrlin=db2pow(snr_dB);
% varn=1/snrlin;
% lamda(i)=varn*(qfuncinv(pf(i))*sqrt(2*n)+n);
% a(i)=lamda(i)-n*(1+varn);
% b(i)=sqrt(2*n*(1+varn)^2);
% pd(i)=qfunc(a(i)/b(i));
% pdi(i)=qfunc(qfuncinv(pf(i)-1));
% end