title: 16-QAM modulation and demodulation - missing one line in the graph
body: <p>I am trying to do modulation and demodulation for 16-QAM and then trying to compare theoretical and simulated BER.</p>
  
  <p>I am <strong>not</strong> getting <code>simulation</code>-line in the graph.
  <img src="https://i.stack.imgur.com/AOgbb.png" alt="Missing the &lt;simulation&gt;-line"></p>
  
  <p>I can not understand what is wrong with my code. Can anybody help me?</p>
  
  <p>here is the code:</p>
  
  <pre class="lang-matlab prettyprint-override"><code>M=16;
  SNR_db = [0 2 4 6 8 10 12];
  x = randi([0,M-1],1000,1);
  hmod = modem.qammod(16);
  hdemod = modem.qamdemod(hmod,'SymbolOrder', 'Gray');
  tx = zeros(1,1000);
  for n=1:1000
      tx(n) = modulate(hmod, x(n));
  end
  rx = zeros(1,1000);
  rx_demod = zeros(1,1000);
  for j = 1:7
      err = zeros(1,7);
      err_t = zeros(1,7);
      for n = 1:1000
          rx(n) = awgn(tx(n), SNR_db(j));
          rx_demod(n) = demodulate(hdemod, rx(n));
  
          if(rx_demod(n)~=x(n))
              err(j) = err(j)+1;
          end
      end
      % err_t = err_t + err;
  end
  theoryBer = 3/2*erfc(sqrt(0.1*(10.^(SNR_db/10))));
  figure
  semilogy(SNR_db,theoryBer,'-',SNR_db, err, '^-');
  grid on
  legend('theory', 'simulation');
  xlabel('Es/No, dB')
  ylabel('Symbol Error Rate')
  title('Symbol error probability curve for 16-QAM modulation') 
  </code></pre>