Sunteți pe pagina 1din 15

QUESTION:

1.Write program and compare the BER for different modulation techniques. (Use MATLAB for
simulation analysis)

2.Using simulink verify the BER plot for different modulation schemes stated above.

MATLAB CODE:
1. PROBABILITY OF BIT ERROR FOR BPSK MODULATION:

clc;
clear all;
close all;

s=randn(1,10000)- 0.5;% random signal s whose amp is varying from -0.5 to 0.5
sp = var(s); % calculates the signal power
x=[];
for i=1:length(s)
if(s(i)>0)
x(i)=1;
else
x(i)=-1;
end
end
eb=1;

snr=2:1:12; % snr is varying from 2 to 12


for i=1:length(snr)
np(i)=sp*10^(-snr(i)/10); % depending on the value of snr np is being calculated

y=awgn(x,snr(i),np(i));%additive white gaussian noise is being added to the signal x

for j=1:length(y) %the signal is received from the awgn channel


if (y(j) > 0)
r(j)=1;
else
r(j)=-1;
end
end

cp=[];
for k=1:length(s) %comparator compares the signal x before awgn channel and after
if(x(k)==r(k))
cp(k)=0;
else
cp(k)=1;
end
end

ner(i)=sum(cp); %counts the number of error

end
eb_no = 10*log10(eb./np) % calculates the Eb/No in dB
pe = ner./length(s) %pe is the ratio of no of errors by no of bits transmitted
pe_theo =(1/2)*erfc(sqrt(eb./np)) %pe using theoretical formula
snr
np
ner

semilogy(eb_no,pe_theo,'r o')
hold on
semilogy(eb_no,pe,'*');
hold off
axis([2 16 10^(-9) 10^(-1)])
grid on
title('plot of probability of error vs Eb/No in dB for BPSK ')
xlabel('Eb/No in dB')
ylabel('probability of error Pe')
legend('theoretical pe','montecarlo simulation pe');

Result:

eb_no =

Columns 1 through 7

1.9915 2.9915 3.9915 4.9915 5.9915 6.9915 7.9915

Columns 8 through 11

8.9915 9.9915 10.9915 11.9915

pe =

Columns 1 through 7

0.1237 0.0891 0.0678 0.0467 0.0247 0.0150 0.0064

Columns 8 through 11
0.0033 0.0009 0.0001 0

pe_theo =

Columns 1 through 7

0.0376 0.0230 0.0126 0.0060 0.0024 0.0008 0.0002

Columns 8 through 11

0.0000 0.0000 0.0000 0.0000

snr =

2 3 4 5 6 7 8 9 10 11 12

np =

Columns 1 through 7

0.6322 0.5022 0.3989 0.3168 0.2517 0.1999 0.1588

Columns 8 through 11

0.1261 0.1002 0.0796 0.0632

ner =

Columns 1 through 6

1237 891 678 467 247 150

Columns 7 through 11

64 33 9 1 0
2. PROBABILITY OF BIT ERROR FOR QPSK MODULATION

clc;
clear all;
close all;

sa=[-1 -1]; % for [0 0]


sb=[-1 1]; % for [0 1]
sc=[1 -1]; % for [1 0]
sd=[1 1]; % for [1 1]

N=10000;
s=rand(N,1);

eb=1; %energy per bit


sp=eb; % if T=1 % signal power is same as energy per bit
x=[];

for i=1:length(s)
if((s(i)<0.25))
x(i,:)=sa;
elseif((s(i)<0.50))
x(i,:)=sb;
elseif((s(i)<0.75))
x(i,:)=sc;
elseif((s(i)<=1))
x(i,:)=sd;
end
end
eb=1;

snr=1:1:12; % snr is varying from 1 to 12

for j=1:length(snr)
np(j)=sp*10^(-snr(j)/10); % depending on the value of snr np is being calculated
y=awgn(x,snr(j),np(j));%additive white gaussian noise is being added to the signal x
mn=mean(y); % finds out the mean for comparing
for i=1:length(y)
if(y(i,1) < mn(1))
r(i,1) =-1 ;
else
r(i,1)=1;
end

if(y(i,2) < mn(2))


r(i,2) = -1;
else
r(i,2)=1;
end

end

cp=[];
for k=1:N %comparator compares the signal x before awgn channel and after
if (x(k,:)==r(k,:))
cp(k)=0;
else
cp(k)=1;
end
end

ner(j)=sum(cp); %counts the number of error

end
eb_no = 10*log10(eb./np) % calculates the Eb/No in dB
pe = ner./N %pe is the ratio of no of errors by no of bits transmitted
pe_theo =(1/2)*erfc(sqrt(eb./np)) %pe using theoretical formula

snr
np
ner

semilogy(eb_no,pe_theo,'r o')
hold on
semilogy(eb_no,pe,'*');
hold off
%axis([2 15 10^(-9) 10^(0)])
grid on
title('plot of probability of error vs Eb/No in dB for QPSK ')
xlabel('Eb/No in dB')
ylabel('probability of error Pe')
legend('theoretical pe','montecarlo simulation pe');

Result:

eb_no =

Columns 1 through 7

1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000

Columns 8 through 12
8.0000 9.0000 10.0000 11.0000 12.0000

pe =

Columns 1 through 7 0.2821 0.2318 0.1771 0.1221 0.0838 0.0537 0.0255

Columns 8 through 12

0.0143 0.0069 0.0016 0.0007 0

pe_theo =

Columns 1 through 7

0.0563 0.0375 0.0229 0.0125 0.0060 0.0024 0.0008

Columns 8 through 12

0.0002 0.0000 0.0000 0.0000 0.0000

snr =

1 2 3 4 5 6 7 8 9 10 11 12

np =

Columns 1 through 7

0.7943 0.6310 0.5012 0.3981 0.3162 0.2512 0.1995

Columns 8 through 12

0.1585 0.1259 0.1000 0.0794 0.0631

ner =

Columns 1 through 6

2821 2318 1771 1221 838 537

Columns 7 through 12

255 143 69 16 7 0
3. PROBABILITY OF BIT ERROR FOR 16-ary QAM MODULATION

clc;
clear all;
close all;

N=10000;
M=16;
x=randint(N,1,[1,M]); % the signal is varying from 1 to 16 for N samples
sp=var(x); %signal power
d=1;
mp=[-3*d 3*d; %constellation for 16-ary QAM
-d 3*d;
d 3*d;
3*d 3*d;
-3*d d;
-d d;
d d;
3*d d;
-3*d -d;
-d -d;
d -d;
3*d -d;
-3*d -3*d;
-d -3*d;
d -3*d;
3*d -3*d];

for i=1:N
sm(i,:)=mp(x(i),:); %the signal x is mapped in the constellation for 16-ary QAM
end

eb=1; %eb is the signal energy

snr=2:1:12; % snr is varying from 2 to 12

for k=1:length(snr)
np(k)=sp*10^(-snr(k)/10); % depending on the value of snr np is being calculated
r=awgn(sm,snr(k),np(k)); %additive white gaussian noise is being added to the signal sm

for i=1:N
for j=1:length(mp)
me(j)=(r(i,1)-mp(j,1))^2+(r(i,2)-mp(j,2))^2; %the optimum detector computes the distance
metrics

end;
[min_me decis] = min(me); %finds out the minimum
r1(i,:)=mp(decis,:); % the min indices helps in mapping back to r1 for comparing
end

cp=[];
for k1=1:N %comparator compares the signal sm before awgn channel and after
if (sm(k1,:)==r1(k1,:))
cp(k1)=0;
else
cp(k1)=1;
end
end

ner(k)=sum(cp); %counts the number of error

end
eb_no = 10*log10(eb./np) % calculates the Eb/No in dB
pe = ner./N %pe is the ratio of no of errors by no of bits transmitted
pe_theo =2*(1-(1/(sqrt(M))))*erfc(sqrt(eb./(np))) %pe for M-ary QAM

snr
np
ner

semilogy(eb_no,pe_theo,'r o')
hold on
semilogy(eb_no,pe,'*');

%axis([2 15 10^(-9) 10^(0)])


grid on
title('plot of probability of error vs Eb/No in dB for 16-ary QAM ')
xlabel('Eb/No in dB')
ylabel('probability of error Pe')
legend('theoretical pe','montecarlo simulation pe');

OUTPUT:
eb_no =

Columns 1 through 7

-11.2162 -10.2162 -9.2162 -8.2162 -7.2162 -6.2162 -5.2162

Columns 8 through 11

-4.2162 -3.2162 -2.2162 -1.2162


pe =

Columns 1 through 7

0.8241 0.7649 0.6547 0.5051 0.3736 0.2327 0.1281

Columns 8 through 11

0.0552 0.0181 0.0057 0.0007

pe_theo =

Columns 1 through 7

1.0462 0.9940 0.9368 0.8743 0.8067 0.7340 0.6569

Columns 8 through 11

0.5761 0.4932 0.4098 0.3284

snr =

2 3 4 5 6 7 8 9 10 11 12

np =

Columns 1 through 7

13.2319 10.5105 8.3488 6.6317 5.2677 4.1843 3.3237

Columns 8 through 11

2.6401 2.0971 1.6658 1.3232

ner =

Columns 1 through 6

8241 7649 6547 5051 3736 2327

Columns 7 through 11

1281 552 181 57 7


USING SIMULINK:

1. PROBABILITY OF BIT ERROR FOR BPSK MODULATION


2. PROBABILITY OF BIT ERROR FOR QPSK MODULATION
3. PROBABILITY OF BIT ERROR FOR 16-ary QAM MODULATION

Submitted by:

L.Nagaraju(210EC3214)

Electronics and Instrumentation

S-ar putea să vă placă și