title: Plot Bit-Error-rate (BER) vs Eb_N0 of a discrete BPSK signal passed through integrator in MATLAB
body: <p>I am a novice to communication systems but I am in need to solve this question. I would appreciate inputs in this regard. Apologies if you my question lengthy.</p>
  
  <p>I have a BPSK signal such that the input to a low pass filter(LPF) is of the form</p>
  
  <pre><code>s(k) = A + nk (read n subscript k where k = 0,1...)
  </code></pre>
  
  <p>where A is a constant and nk, k=0,1....are independent zero-mean normal random variables with variance σ2.<br>
  Suppose the LPF is an integrator of the form</p>
  
  <pre><code>y=  1/N { ∑(k=0 to N-1)[s(k)] }  ( read ∑ from k = 0 as lower bound to N-1 as upper bound)
  </code></pre>
  
  <p>After applying this LPF the output y is a test statistic with bit-energy-tonoise
  ratio Eb/N0. We know that for BPSK the probability that we make a
  wrong decision using this test statistic is <code>Pb = theoretical BER = 0.5 erfc{sqrt(Eb/N0)}</code>
  If an Infinite impulse response(IIR) filter corresponds to </p>
  
  <pre><code>y ̃ (n)= (1 - α)s(n)+ αy ̃  (n - 1),n = 0,1....N-1    where y ̃ (-1) = 0
  </code></pre>
  
  <p>How can I use Matlab to simulate the signal s(k) and the filter operation producing y and y ̃ (n) respectively above for N = 8 and plot simulated bit error rate vs. Eb/N0 and theoretical BER vs. Eb/N0 to compare. Eb/N0 range should be from 0 to 10 dB.</p>
  
  <p>Note: For the IIR filter I have already determined α = (N-1)/(N+1)</p>
  
  <p>My code fails to achieve desired results as I am unaware of how to simulate a WGN with variance = σ2. The one I have coded is for zero variance. Additionally I don't know how to pass my signal through the filters mentioned above.
  Could somebody please help me rectify this piece of code. If yo could help with code snippet, would be a significant step forward for me. Thanks in advance!
  Here is my approach. </p>
  
  <pre><code>clc;
  clear all;
  close all;
  N=8; % Number of Bits to be processed
  Eb_N0_dB = 0 : 1: 10;
  for i = 1:length(Eb_N0_dB)
      x = rand(1,N)&gt;0.5;  %generating 0,1s
      xpolar = 2*x -1; %BPSK modulation
      noise = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; %noise
      y = xpolar + 10^(-Eb_N0_dB(i)/20)*noise;
      xdecode = real(y)&gt;0;  %receiver hard decison decoding
      nErr(i) = size(find([x - xdecode]),2);
  end
  simulatedBER = nErr/N; %simulated BER
  theoryBER = 0.5erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical BER
  %plot
  figre
  semilogy(Eb_N0_dB,simulatedBER,'bs-');
  hold on
  semilogy(Eb_N0_dB,theoryBER,'mx-');
  axis([0 10 10^-5 0.5])
  grid on
  </code></pre>