You are on page 1of 1

% qam important is m file code in matlab with modulator and demodulate to Crea

te a 16 QAM ( you can change M to 4 , 16 , 32 , 64, ...)


% where M = 16 Size of signal constellation , it is a teaching file for learni
ng .
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M = 16;
% Size of signal constellation
k = log2(M);

% Number of bits per symbol

n = 3e4;

% Number of bits to process

nSyms = n/k;

% Number of symbols

hMod = modem.qammod(M);
% Create a 16-QAM modulator
hMod.InputType = 'Bit';
% Accept bits as inputs
hMod.SymbolOrder = 'Gray';
% Accept bits as inputs
hDemod = modem.qamdemod(hMod); % Create a 16-QAM based on the modulator
x = randi([0 1],n,1); % Random binary data stream
tx = modulate(hMod,x);
EbNo = 0:10; % In dB
SNR = EbNo + 10*log10(k);
rx = zeros(nSyms,length(SNR));
bit_error_rate = zeros(length(SNR),1);
for i=1:length(SNR)
rx(:,i) = awgn(tx,SNR(i),'measured');
end
rx_demod = demodulate(hDemod,rx);
for i=1:length(SNR)
[~,bit_error_rate(i)] = biterr(x,rx_demod(:,i));
end
theoryBer = 3/(2*k)*erfc(sqrt(0.1*k*(10.^(EbNo/10))));
figure;
semilogy(EbNo,theoryBer,'-',EbNo, bit_error_rate, '^-');
grid on;
legend('theory', 'simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for 16-QAM modulation');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

You might also like