GENERAL CODE OF MQAM TO GENERATE BER VS SNR PLOT

버전 1.0.0.0 (2.26 KB) 작성자: raghav khandelwal
GENERAL CODE OF MQAM TO GENERATE BER VS SNR PLOT
다운로드 수: 444
업데이트 날짜: 2015/5/14

라이선스 보기

clc;
clear all;
close all;
N = 4*10^3; % number of symbols
M = 16; % size
k = log2(M); % bits/symbol

% for 16-QAM
Re = [-(2*sqrt(M)/2-1):2:-1 1:2:2*sqrt(M)/2-1];

Im = [-(2*sqrt(M)/2-1):2:-1 1:2:2*sqrt(M)/2-1];

k_QAM = 1/sqrt(10);

bdB = 3:1:13; % SNR range

sdB = bdB + 10*log10(k);

% binary to gray code

a = [0:k-1];

map = bitxor(a,floor(a/2));

[tt ind] = sort(map);

for i = 1:length(bdB)

c = rand(1,N*k,1)>0.5; % random 1's and 0's
d = reshape(c,k,N).';
bd = ones(N,1)*(2.^((k/2-1):-1:0)) ; % conversion from binary to decimal

% real

cRe = d(:,(1:k/2));
e = sum(cRe.*bd,2);
f = bitxor(e,floor(e/2));

% imaginary
cIm = d(:,(k/2+1:k));
g = sum(cIm.*bd,2);
h = bitxor(g,floor(g/2));

% mapping the Gray coded symbols into constellation
modRe = Re(f+1);
modIm = Im(h+1);

% constellation

mod = modRe + 1i*modIm;
s = k_QAM*mod;

% noise

n = 1/sqrt(2)*[randn(1,N) + 1i*randn(1,N)];

% reciever
r = s + 10^(-sdB(i)/20)*n;

% demodulation

r_re = real(r)/k_QAM;
r_im = imag(r)/k_QAM;

% rounding off


m = 2*floor(r_re/2)+1;
m(m>max(Re)) = max(Re);
m(m<min(Re)) = min(Re);

n= 2*floor(r_im/2)+1;
n(n>max(Im)) = max(Im);
n(n<min(Im)) = min(Im);

% To Decimal conversion

oRe = ind(floor((m+4)/2+1))-1;
oIm = ind(floor((n+4)/2+1))-1;

% To binary string
pRe = dec2bin(oRe,k/2);
pIm = dec2bin(oIm,k/2);

% binary string to number
pRe = pRe.';
pRe = pRe(1:end).';
pRe = reshape(str2num(pRe).',k/2,N).' ;

pIm = pIm.';
pIm = pIm(1:end).';
pIm = reshape(str2num(pIm).',k/2,N).' ;

% counting errors for real and imaginary
Err(i) = size(find([cRe- pRe]),1) + size(find([cIm - pIm]),1) ;

end
sBer = Err/(N*k);
tBer = (1/k)*3/2*erfc(sqrt(k*0.05*(10.^(bdB/10))));

% plot
figure
semilogy(bdB,tBer,'rs-','LineWidth',2);
hold on
semilogy(bdB,sBer,'kx-','LineWidth',2);
grid on
legend('theory', 'simulation');
xlabel('SNR dB')
ylabel('Bit Error Rate')
title('BER VS SNR')

인용 양식

raghav khandelwal (2024). GENERAL CODE OF MQAM TO GENERATE BER VS SNR PLOT (https://www.mathworks.com/matlabcentral/fileexchange/50850-general-code-of-mqam-to-generate-ber-vs-snr-plot), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2009b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 MQAM에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0