how to get SNR in Cogntive radio
1 view (last 30 days)
Show older comments
currently my code is:
---------------------------------------------------------------------
%monte carlo simulation
function [y1,y2,y3,y4]= ed(SNRL,SNRS,SNRH,n) %ed is the energy detection
g1= SNRL:SNRS:SNRH;
g=10.^(g1/10);
beta=0.8; % is the probability pfa, it cannot be more than 1
pf1=zeros(1,length(g));
pd1=zeros(1,length(g));
pf2=zeros(1,length(g));
pd2=zeros(1,length(g));
for i=1 : length(g)
y0 = randn(n,1000000);
y1= randn(n,1000000)*sqrt(g(i))+y0;
%Tgam is the threshold of gamma distribution
Tgam = gaminv((1-beta),n/2,(2/n)*(1+g(i))); %probab of flase detection
pf1(i)= gamcdf(Tgam,n/2,(2/n)*(1+g(i))); %ho
pd1 (i) = gamcdf(Tgam,n/2,2/n); %h1 % prob of detection
pf2(i)= length (find(sum(y1.^2)/n<Tgam))/1000000;
pd2 (i) = length (find(sum(y0.^2)/n<Tgam))/1000000;
y1=pf1; y2=pd1; y3=pf2; y4=pd2;
end
% print graphs
figure (1)
plot(g1,y4,'--c','LineWidth',4);
grid on;
xlabel('sample cycles');
ylabel(' probability of detection (Pd) ');
hold on;
figure(1)
plot(g1,y2,'-k','LineWidth',2);
grid on;
hleg1 = legend('beta = 0.2 for pd2','beta = 0.2 for pd1');
hold on;
-------------------------------------------------------------------
to run the above simulation input" [y1,y2,y3,y4]= ed(0,1,25,2); " in command window.
the "g" in the code above represents the normalisation i.e it represents variance(signal)/variance (noise)
as SNR= power(signal)/power(noise) as the variance of the data is the power.
so i essentially want to "split" the g up. so substitute g= for SNR= power(signal)/power(noise)
this is so that i can add the signal power back into y1 ect.. i.e y1= randn(n,1000000)*sqrt(var(signal))+y0;
thank you for any suggestions.
0 Comments
Answers (1)
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!