vengat
Posts:
4
From:
pondy
Registered:
1/6/12
|
|
Re: cognitive radio
Posted:
Jan 7, 2012 9:21 PM
|
|
HI I get ur MATLAB coding for my project but it shows error in signal generation of BPSK. Since I'm new to MATLAB I'm unable to recover, can u suggest me some idea. And also I need MATLAB coding for Co-operative spectrum sensing for probability of false alarm detection. I've some code pl go thro' it and tel wat correction i need to do.
clear all; close all; clc
u=1000;%time bandwidth factor N=2*u;%samples a=2;%path loss exponent C=2;%constant losses Crs=10; %Number of cognitive radio users PdAnd=0; %----------Pfa------------% Pf=0.01:0.01:1; Pfa=Pf.^2; %---------signal-----% t=1:N; s1 = cos(pi*t); % s1power=var(s1);
%-------- SNR ----------% % Snrdb=-15:1:15; Snrdb=15; Snreal=power(10,Snrdb/10);%Linear Snr
% while Snrdb<15 for i=1:length(Pfa) lamda(i)=gammaincinv(1-Pfa(i),u)*2; %theshold % lamdadB=10*log10(lamda);
%---------Local spectrum sensing---------%
for j=1:Crs %for each node detect=0; % d(j)=7+1.1*rand(); %random distanse d=7:0.1:8; PL=C*(d(j)^-a); %path loss
for sim=1:10%Monte Carlo Simulation for 100 noise realisation
%-------------AWGN channel--------------------% noise = randn(1,N); %Noise production with zero mean and s^2 var noise_power = mean(noise.^2); %noise average power amp = sqrt(noise.^2*Snreal); s1=amp.*s1./abs(s1); % SNRdB_Sample=10*log10(s1.^2./(noise.^2)); Rec_signal=s1+noise;%received signal localSNR(j)=mean(abs(s1).^2)*PL/noise_power;%local snr Pdth(j,i)=marcumq(sqrt(2*localSNR(j)),sqrt(lamda(i )),u);%Pd for j node
%Computation of Test statistic for energy detection Sum=abs(Rec_signal).^2*PL; Test(j,sim)=sum(Sum); if (Test(j,sim)>lamda(i)) detect=detect+1; end
end %END Monte Carlo
Pdsim(j)=detect/sim; %Pd of simulation for the j-th CRuser
end PdAND(i)=prod(Pdsim); PdOR(i)=1-prod(1-Pdsim);
end
PdAND5=(Pdth(5,:)).^5; Pmd5=1-PdAND5; PdANDth=(Pdth(Crs,:)).^Crs; PmdANDth=1-PdANDth; %Probability of miss detection Pmdsim=1-PdAND; figure(1); plot(Pfa,Pmdsim,'r-*',Pfa,PmdANDth,'k-o',Pfa,Pmd5,'g-*'); title('Complementary ROC of Cooperative sensing with AND rule under AWGN'); grid on axis([0.0001,1,0.0001,1]); xlabel('Probability of False alarm (Pfa)'); ylabel('Probability of Missed Detection (Pmd)'); legend('Simulation','Theory n=10','Theory n=5');
Expecting reply with thanks
"sesham srinu" <seshamsrinu83@gmail.com> wrote in message <hs44pp$dou$1@fred.mathworks.com>... > "Vivi Sera" <vivi.seraphic@gmail.com> wrote in message <hrmljm$htd$1@fred.mathworks.com>... > > I am doing a term project in spectrum sensing as well, probably focus on cooperative schemes, but will start with the conventional one, such as energy detection, matched filter, etc etc. If any of you have some good scripts for me to start off, would it be okay for you to share with me, please? I really appreciate it! > hai iam sesham srinu from university of hyderabad,india > %Entropy estimation of a stochastic signal for primary user detection for the matched filter case > > > clear all;clc; > > %**************************************Input parameters********************************************************************************** > > b = [ 1 0 0 1 1]; % Input bit stream > > N=[16 32 64]; > > for j=1:length(N) > snr_db=0:1:20; > g=length(snr_db); > %*************************************BPSK signal generation, Matched filtering and Sampling******************************************** > for z=1:length(snr_db) > > [signal]=bpsk(b); %BPSK signal generation > signal_fad=b_fad(signal); %fading > [s_matched signal_noise noise]=match(signal_fad,snr_db(z)); % matched filtered output of Qpsk signal > > > %************************************Entropy anlaysis after matched filter output is sampled******************************************** > > > L=N(j); %No.of bins > > s=s_matched(1:N(j)); % N no.of samples Sampled output of matched filter > > x=[ ]; > x=s(1:N(j)); %block of N samples of matched filter to make decision > > noise=noise(1:N(j)); > > K=4; > sq=sum(x.^2)/N(j); > sigma = sqrt(sum(x.^2)/N(j)); > %**********************************checking for chebyeshev inequality******************************************************************* > count=0; > for i=1:N(j) > if(abs((x(i)-mean(x)))>(K*sigma)) > count=count+1; > > else > count=count; > end > end > > if ((count/N(j))<= (1/(K^2))) > > %display('Design value of K is correct '); > > else > %display('Design value of K is incorrect and try for another value'); > > end > > % %***********************************Histogram of x************************************************************************************** > v1=(2*K*sigma)/(L); % Width of each bin > v=-K*sigma:v1 :K*sigma; % a vector specifying the centres of bins from where to start and stop. > > %***********************************Checking for no.of values of x fallong inside the kth bin******************************************** > > pa11=0; > pa01=0; y1=0;e(z)=0; > for k=1:L; > > number_samples=0; > > > > lk(k)=v(k)-(v1/2); > lkplus1(k)=v(k)+(v1/2); > > for i=1:N(j) > if((lk(k)<x(i))& (x(i)<lkplus1(k))) > number_samples=number_samples+1; > else > number_samples=number_samples+eps; > end > end > > nk=number_samples; > > y1=y1+number_samples; > %----------------------------------------Entropy caculation------------ > > if(nk~=0) > nk=nk; > else > nk=nk+eps; > > end > p(k) = -((nk/N(j))*log2(nk/N(j))); > e(z)= e(z)+p(k) ; %Entropy estimate > > > > > %********************************************computing pk(a)******************************************************************************** > a1=snr_db(z); > > a0=0; > > pk1=0;pk0=0; M=2; u(1)=1;u(2)=-1; > for m=1:M > h1(m)=0;h2(m)=0;h3(m)=0;h4(m)=0; > > h1(m)=(lk(k)-u(m)*sqrt(a1/(1+a1)))*(1+a1); > h2(m)=(lkplus1(k)-u(m)*sqrt(a1/(1+a1)))*(1+a1); > h3(m)=(lk(k)-u(m)*sqrt(a0/(1+a0)))*(1+a0); > h4(m)= (lkplus1(k)-u(m)*sqrt(a0/(1+a0)))*(1+a0); > > > > pk1=pk1+[[qfunc(h1(m))]-[qfunc(h2(m))]]; > pk0=pk0+[[qfunc(h3(m))]-[qfunc(h4(m))]]; > > end > > pka1= (1/M)*pk1+eps; > pka0= (1/M)*pk0+eps; > > %*********************************************computing log-likelihood ratio*************************************************************** > > pa11=pa11+(nk/N(j))*[log2(pka1)-log2(pka0)]; > > > end > > le(z)=pa11;%Log-likelihood ratio of entropy > end > > e1((j+(j-1)*20):j*21)=e; > le1((j+(j-1)*20):j*21)=le; > end > > > > plot(snr_db,e1(1:21),'-b*',snr_db,e1(22:42),'-ro',snr_db,e1(43:63),'-g.'); > xlabel('SNR in db'); > ylabel('Entropy'); > title('Normal entropy'); > h2=legend('N=16 BPSK','N=32 BPSK','N=64 BPSK',1); > > figure > plot(snr_db,le1(1:21),'-b*',snr_db,le1(22:42),'-ro',snr_db,le1(43:63),'-g.'); > xlabel('SNR in db'); > ylabel('Log-likelihood Entropy'); > title('log-likelihood entropy') > h2=legend('N=16 BPSK','N=32 BPSK','N=64 BPSK',1); > > >
|
|