Smldpe55.m
Upload User: loeagle
Upload Date: 2013-03-02
Package Size: 1236k
Code Size: 1k
Development Platform:

Matlab

  1. function [p]=smldPe55(snr_in_dB)
  2. % [p]=smldPe55(snr_in_dB)
  3. % SMLDPE55  simulates the probability of error for the particular
  4. %    value of snr_in_dB, signal-to-noise ratio in dB.
  5. E=1;
  6. SNR=exp(snr_in_dB*log(10)/10);     % signal-to-noise ratio
  7. sgma=E/sqrt(2*SNR);     % sigma, standard deviation of noise
  8. N=10000;
  9. % Generation of the binary data source follows.
  10. for i=1:N,
  11.    temp=rand;           % a uniform random variable over (0,1)
  12.    if (temp<0.5),
  13.       dsource(i)=0;           % With probability 1/2, source output is 0.
  14.    else
  15.       dsource(i)=1;        % With probability 1/2, source output is 1.
  16.    end
  17. end;
  18. % The detection, and probability of error calculation follows.
  19. numoferr=0;
  20. for i=1:N,
  21.    % the matched filter outputs
  22.    if (dsource(i)==0),
  23.       r=-E+gngauss(sgma);       % if the source output is "0"
  24.    else
  25.       r=E+gngauss(sgma);      % if the source output is "1"
  26.    end;
  27.    % Detector follows.
  28.    if (r<0),
  29.       decis=0;        % Decision is "0". 
  30.    else
  31.       decis=1;        % Decision is "1". 
  32.    end;
  33.    if (decis~=dsource(i)),     % If it is an error, increase the error counter.
  34.       numoferr=numoferr+1;
  35.    end;
  36. end;
  37. p=numoferr/N;           % probability of error estimate