Aim:
To simulate and analyze the performance of QAM in AWGN environment. To calculate
i)SNR
ii)PSD
iii)BER
iv)Constellation plot

Program:
clc;
clear all;
close all;
f=100;
t = 0:1e-4:1/f;
w = 2*pi*f;
sig1 =2*sin(w*t);
figure,subplot(221); plot(t,sig1);title('Message
signal');xlabel('time');ylabel('Amplitude');
fs=1500 ;
Ts = 1/fs;
t2=(0:Ts:1/f);
sig =2*sin(w*t2);
subplot(223); stem(t2,sig);title('Sampled
signal');xlabel('time');ylabel('Amplitude');
Vh=max(sig);Vl=min(sig);
N=4;M=2^N;S=(Vh-Vl)/M;
partition = [Vl+S:S:Vh-S];
codebook = [Vl+S/2:S:Vh-S/2];
[index,quantized_sig,distor] = quantiz(sig,partition,codebook);
subplot(222); stem(t2,quantized_sig);title('Quantized
signal');xlabel('time');ylabel('Amplitude');
codedsig=de2bi(index,'left-msb');
codedsig=codedsig';
txbits=codedsig(:);
tt=[0:N*length(t2)-1];
subplot(224);stairs(tt,txbits); axis([0 30 -2 3]);title('PCM
waveform');xlabel('time');ylabel('Amplitude');
txbits=txbits';
nbit=length(txbits);
M=input('Enter the value of M array for QAM modulation : ');
%XX representation of transmitting binary information as digital signal XXX
x=txbits;
bp=.000001;
bit=[];
for n=1:1:length(x)
if x(n)==1
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
figure,subplot(221);plot(t1,bit);grid on;axis([0 bp*length(x) -.5 1.5]);
ylabel('Amplitude(volt)');xlabel(' Time(sec)');title('transmitting
information as digital signal');
% binary information convert into symbolic form for M-array QAM modulation
msg_reshape=reshape(txbits,nbit/log2(M),log2(M));
for(j=1:1:nbit/log2(M))
for(i=1:1:log2(M))
a(j,i)=num2str(msg_reshape(j,i));
end
end
as=bin2dec(a);
ass=as';
subplot(223),stem(ass);title('serial symbol for M-array QAM modulation at
transmitter');
xlabel('n(discrete time)');ylabel(' magnitude');
disp('symbolic form information for M-array QAM ');disp(ass);
% %XXXXXXXXXXXXXX Mapping for M-array QAM modulation XXXXXXXXXXXXXXXXXXXXXXXX
sym=0:1:M-1;
pp=qammod(sym,M);
subplot(222),plot(real(pp),imag(pp),'*'),grid on;title('Constellation diagram
for M-array QAM');
% %XXXXXXXXXXXXXXXXXXXXXX M-array QAM modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXX
RR=real(pp);
II=imag(pp);
sp=bp*2;
sr=1/sp;
f=sr*2;
t=sp/100:sp/100:sp;
ss=length(t);
m=[];
for(k=1:1:length(RR))
yr=RR(k)*cos(2*pi*f*t); % inphase or real component
yim=II(k)*sin(2*pi*f*t); % Quadrature or imagenary component
y=yr+yim;
m=[m y];
end
tt=sp/100:sp/100:sp*length(RR);
subplot(224);plot(tt,m);xlabel('time(sec)');ylabel('amplitude(volt)');
title('waveform for M-array QAM modulation acording to symbolic information');
num_bit=length(m);
SNRdB=-4:1:24;
SNR=10.^(SNRdB/10);
for(k=1:length(SNRdB))
y=awgn(complex(m),SNRdB(k));
error=0;
for(c=1:num_bit)
if (y(c) - m(c) > 1)
error=error+1;
end
end
error=error/num_bit;
z(k)=error;
end
k=log2(M);
BER_th=2/k*(1-1/sqrt(M))*erfc(sqrt(3*SNR*k/(2*(M-1))));
figure,semilogy(SNRdB,z,'o','linewidth',2.5),grid on,hold on;
semilogy(SNRdB,BER_th,'r','linewidth',2.5),grid on,hold on;
title(' Curve of Bit Error Rate Vs SNR for M-PSK modulation');
xlabel('SNR(dB)'),ylabel('BER'),legend('Simulation','Th
eoretical'),axis([0 10 10^-5 1]);
figure,subplot(211),pwelch(m,'psd')
subplot(212),pwelch(y,'psd')