function xbincomm(u, p, pf, samples, seed) % xbincomm(u, p, pf, samples, seed) Binary channel experiment: a Bernoulli % signal with random noise. The first plot is a parametric plot of the % probability of a detection and the probability of a false detection as % functions of the threshold value, as it goes from 0 to u. The second % plot is the error probability versus the threshold value. Both plots % are done against the theoretically predicted curves. % % u value for a positive on the Bernoulli signal % p probability of a positive on the Bernoulli signal % pf probability function for noise: must have mean of 0 % samples number of experimental samples to use % seed seed for random number generator if u<=0 error('u must be > 0') end if samples<=0 error('samples must be > 0') end if ispf(pf)==0 error('not a valid probability function') end if inrange(mmean(pf), 0, 1e-4)==0 error('noise probability function must have mean 0') end t=[0:u/100:u]; PD=zeros(size(t)); PF=PD; PE=PD; PPD=PD; PPF=PD; PPE=PE; pff=pf; x=xvals(pf); pfd=pf; pfd(2:length(x)+1,1)=(x+u)'; cff=getcf(pff); cfd=getcf(pfd); N=rvgen(cff, 1, 2*samples, seed); NF=N(1:samples); ND=N(samples+1:2*samples)+u; for i=1:length(t) f=find(NF>=t(i)); PF(i)=length(f)/samples; NF=NF(f); f=find(ND>=t(i)); PD(i)=length(f)/samples; ND=ND(f); end PPD=1-pval(cfd, t); PPF=1-pval(cff, t); PE=p.*(1-PD)+(1-p).*PF; PPE=p.*(1-PPD)+(1-p).*PPF; f=find(PE==min(PE)); topt=t(f(1)); f=find(PPE==min(PPE)); ptopt=t(f(1)); subplot(1, 2, 1); plot(PF, PD, 'r'); hold on plot(PPF, PPD); hold off xlabel('PF'); ylabel('PD'); subplot(1, 2, 2); plot(t, PE, 'r'); hold on plot(t, PPE); hold off xlabel('threshold'); ylabel('PE'); s=sprintf('\"Best\" threshold was %1.4f - predict %1.4f', topt, ptopt); disp(s);