function xproberr(threshold, rangelow, rangehigh, p, pf, samples, seed) % xproberr(threshold, rangelow, rangehigh, p, pf, samples, seed) Signal to % noise ratio experiment for a Bernoulli signal with random noise. The % signal to noise ratio is swept over the given range, and the % experimental and theoretical error probability are plotted against it. % % threshold threshold ratio for exeriment % rangelow low end of signal to noise range (in db) % rangehigh high end of signal to noise range (in db) % p probability of a positive on 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 rangelow>=rangehigh error('invalid range') end if ispf(pf)==0 error('invalid probability function') end if inrange(mmean(pf), 0, 1e-4)==0 error('noise probability function must have mean 0') end v=var(pf); snr=[rangelow:3:rangehigh]; u=sqrt((10.^(snr./10)).*v); pfs=mfberni(p); ncf=getcf(pf); S=rvgen(getcf(pfs), 1, samples, seed); N=rvgen(ncf, 1, samples, rem(seed^2, 10000)); PE=zeros(size(snr)); PPE=(1-p)*(1-pval(ncf, threshold.*u))+p.*pval(ncf, (threshold-1).*u); for i=1:length(snr), SN=S.*u(i)+N; D=(SN>=threshold*u(i)); PE(i)=(samples-sum(D==S))/samples; end subplot(1,1,1) snr2=(u.^2)./(v^2); loglog(snr2, PPE) hold on loglog(snr2, PE, 'r') hold off xlabel('Signal to Noise Ratio') ylabel('P(E), Prob of Error')