clear all; close all; clc
c = [-3-3i -3-1i -3+3i -3+1i -1-3i -1-1i -1+3i -1+1i 3-3i 3-1i 3+3i 3+1i 1-3i 1-1i 1+3i 1+1i];
M = length(c);
k = log2(M);
numBits = 10000;
SNR = 0:1:20;
numSNR = length(SNR);
berVec = zeros(3, numSNR);
mod = comm.GeneralQAMModulator(c);
demod = comm.GeneralQAMDemodulator(c);
tx = randi([0 M-1],numBits,1);
modSignal = mod(tx);
awgnChan = comm.AWGNChannel('NoiseMethod', 'Signal to noise ratio (SNR)');
errorCalc = comm.ErrorRate;
for n = 1:numSNR
reset(errorCalc)
awgnChan.SNR = SNR(n);
noisySignal = awgnChan(modSignal);
rx = demod(noisySignal);
berVec(:,n) = errorCalc(tx,rx);
end
BER = berVec(1,:);
[BERtheory, SERtheory] = berawgn(SNR,'qam',M);
semilogy(SNR,BERtheory,'b-',SNR,BER,'r*');
legend('Theoretical BER','Empirical BER');
xlabel('SNR (dB)'); ylabel('BER');
title('16-QAM over AWGN Channel');