Visit Main Website [Click Here ↗]
MATLAB Script
%%% Code starts here %%%
clc;clear all;close all;
M = 4; % Number of levels after quantization / size of signal constellation
k = log2(M); % Number of bits per symbol
rng(1) %assaining the value of seed integer
N =5000; % Number of bits to process
dataIn = randi([0 1],1,N); % Generating randon bits
dataInMatrix = reshape(dataIn,length(dataIn)/k,k); % Reshape data into binary k-tuples, k = log2(M)
dataSymbolsIn = bi2de(dataInMatrix); % Convert binary to decimal
for n= 1:N/k
if dataSymbolsIn(n)==0
QAM(n)= complex(1,1);
elseif dataSymbolsIn(n)==1
QAM(n)= complex(-1,1);
elseif dataSymbolsIn(n)==2
QAM(n)= complex(1,-1);
else
QAM(n)= complex(-1,-1);
end
end
display(dataIn,'First fifty bits');
display(QAM,'first twenty-five4-QAM symbols');
%Transmission of 4QAM data over AWGN channel
snrdB =8;
Y=awgn(QAM,snrdB); %received signal
%Threshold Detection
for n= 1:N/k
if (real(Y(n))>0 && imag(Y(n))>0)
Z(n)=complex(1,1);
elseif (real(Y(n))>0 && imag(Y(n))<0)
Z(n)=complex(1,-1);
elseif (real(Y(n))<0 && imag(Y(n))>0)
Z(n)=complex(-1,1);
else
Z(n)=complex(-1,-1);
end
end
sPlotFig = scatterplot(Y,1,0,'g.');
hold on
scatterplot(QAM,1,0,'k*',sPlotFig)
legend('received','transmitted')
Comments
Post a Comment