Discussion:
matlab code for probability of detection and false alarm in cognitive radio
(too old to reply)
Jamal
2013-05-24 09:39:08 UTC
Permalink
Hi,
I work on cooperative spectrum sensing for cognitive radio, energy detection;
I have this code there is somthing wrong which I can't find it
anyone can tell me whats wrong in this code

clc; clear all; close all;
u = 5;
sigma = 0:0.2:5;
snr = 20;

pf = gammainc(u,sigma/2)/gamma(u);

g=0;
h=0;

for p=0:(u-2)
gg = (1/factorial(p)) * (sigma./2).^p;
g = g + gg;
hh = (1/factorial(p)) * ((sigma.*snr)/(2*(1+snr))).^p;
h = h + hh;
end

pd = exp(-(sigma/2)) .* g + ((1+snr)./snr)^(u-1) .*(exp(-(sigma./(2+(1+snr)))) - exp(-(sigma/2)) .* h);

pm = 1 - pd;

loglog(pf,pm)

xlabel('Pf: Probability of Fals alarm');
ylabel('Pm: Probability of missed detection');
legend('20 dB');

grid on
t***@gmail.com
2013-11-13 02:00:25 UTC
Permalink
clc; clear all; close all;
m = 2;
lamda = 1:0.001:18;
pf = gammainc(m,lamda/2)/gamma(m);
gama= 10;
g=0;
h=0;

for p=0:m
gg = (1/factorial(p)) * (lamda./2).^p;
g = g + gg;
hh = (1/factorial(p)) * ((lamda.*m*gama)/(2*(1+m*gama))).^p;
h = h + hh;
end
pd = gammainc(m-1,lamda/2)/gamma(m-1)+exp(-(lamda/2)) .* g + ((1+gama)./gama)^(m-1) .*(exp(-(lamda./(2*(1+gama)))) - exp(-(lamda/2)) .* h);

pm = 1 - pd;

loglog(pf,pm)

xlabel('Pf');
ylabel('Pm');

grid on;

Do you code rayleigh fading?
I'm don't thing you wrong at sigma but it is not suitble
e***@gmail.com
2014-03-12 01:12:25 UTC
Permalink
Dear Trung;

Im working on matlab code for probability of detection and false alarm in cognitive radio I have this code :
clc; clear all; close all;
u = 2;
lamda = 1:0.001:18;
pf = gammainc(u,lamda/2)/gamma(u);
y = 10;

for n=0:100;

z=((gammainc((n+u),lamda/2))/(gamma(n+u))*((y/(1+y))^n));

end
w=1/(1+y);

pd=w*z;

pm=1-pd;

loglog(pf,pm,'r-')

xlabel('Pf');
ylabel('Pm');

grid on;

This is for rayleigh fading but the curve cant show correct

thanks,,
Sanket Kalamkar
2015-02-10 19:49:08 UTC
Permalink
I guess there is a problem with the calculation of pf, i.e., use of gammainc function.
You can find the code that work at the following link:

http://in.mathworks.com/matlabcentral/fileexchange/49608-energy-detection-theory--rayleigh-channel
Post by Jamal
Hi,
I work on cooperative spectrum sensing for cognitive radio, energy detection;
I have this code there is somthing wrong which I can't find it
anyone can tell me whats wrong in this code
clc; clear all; close all;
u = 5;
sigma = 0:0.2:5;
snr = 20;
pf = gammainc(u,sigma/2)/gamma(u);
g=0;
h=0;
for p=0:(u-2)
gg = (1/factorial(p)) * (sigma./2).^p;
g = g + gg;
hh = (1/factorial(p)) * ((sigma.*snr)/(2*(1+snr))).^p;
h = h + hh;
end
pd = exp(-(sigma/2)) .* g + ((1+snr)./snr)^(u-1) .*(exp(-(sigma./(2+(1+snr)))) - exp(-(sigma/2)) .* h);
pm = 1 - pd;
loglog(pf,pm)
xlabel('Pf: Probability of Fals alarm');
ylabel('Pm: Probability of missed detection');
legend('20 dB');
grid on
j***@gmail.com
2018-03-06 08:06:21 UTC
Permalink
sir am working in cooperative spectrum sensing in cognitive radio. i have problem to find probability of false alarm in matlab simulation. i need simulation formula for Pf in matlab. my mail id is ***@gmail.com
Loading...