Вы находитесь на странице: 1из 11

HW_3

Question 1 Code
% Author : Rahul Ekhande
% UID
: U37692717
clear all
close all
clc
% 10000 random bits generation
b = randint(1,10000);
% autocorrelation
b_corr = xcorr(b);
figure
plot(b_corr)
title('Auto-correlation of the input signal')
% repetition coding
b = [b;b;b];
b1 = reshape(b,1,numel(b));
% Shuffling of data by Inter-leaving
c = reshape(b1,300,100);
c1 = reshape(c',1,30000);
% Binary Phase Shift keying
d = 2*c1-1;
figure
plot(xcorr(d))
title('Auto-correlation of the Modulated signal')
scatterplot(d)
% Noise Figure
G = randn(1,30000)+i*randn(1,30000);
% Plotting the autocorrelation of noise
figure
plot(abs(xcorr(G)))
title('Auto-correlation of the noise')
% SNR(Given)
SNR = [0 2.5 5 7.5 10]
SYM = zeros(5,1);
% Calculation the S.D and noise addition to the signal
for i = 1:5
sig(i) = 10^(-SNR(i)/20);
% Change of variance of the noise
N(i,:) = sig(i)*G;
% adding noise and actual signal
Y(i,:) = d + N(i,:);

scatterplot(Y(i,:))
% Detection of received symbols. The real part of received signal is compared
% with zero knowing it position and decision is made
for j= 1:size(d,2)
if real(Y(i,j))>0
Yds(i,j) = 1;
else
Yds(i,j) = -1;
end
end
% errors calculation in the symbols by comparing the
% actual symbols against received symbols.
count = 0;
for j = 1:size(d,2)
if Yds(i,j) ~= d(1,j)
count = count+1;
end
end
SYM(i,1) = count;
% Detecting the received bits. The real part of received signal is compared
% with zero knowing it position and decision is made

for j= 1: size(d,2)
if Yds(i,j)>0
Ydb(i,j) = 1;
else
Ydb(i,j) = 0;
end
end
end
SER = SYM./30000
% Deinterleaving
for i = 1:5
Y1 = reshape(Ydb(i,:),100,300);
YDIL(i,:) = reshape(Y1',1,30000);
end
% Decoding
for i = 1:5
p = 1;
for j = 1:3:30000
sum = YDIL(i,j) + YDIL(i,j+1) + YDIL(i,j+2);
if sum > 1.5
YD(i,p) = 1;
else
YD(i,p) = 0;
end
p = p+1;

end
end
% BER calculation
BIT = zeros(1,5);
for i = 1:5
count = 0;
for j = 1:size(YD,2)
if YD(i,j) ~= b(1,j)
count = count+1;
end
end
BIT(i) = count;
end
BER = BIT./10000
figure
semilogy(SNR,SER,'-b.','LineWidth',1.3,'MarkerSize',15)
hold on
semilogy(SNR,BER,'-r.','LineWidth',1.3,'MarkerSize',15)
legend('SER','BER')

Auto-correlation of the input signal

6000
5000
4000
3000
2000
1000
0
-1000

0.2

0.4

0.6

0.8

1.2

1.4

1.6

1.8

2
4

x 10

Auto-correlation of the Modulated signal

x 10

2.5
2
1.5
1
0.5
0

6
4

x 10
Scatter plot
1
0.8
0.6
0.4
Quadrature

-0.5

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1

-0.5

0
In-Phase

0.5

Auto-correlation of the noise

x 10

0
0

6
4

x 10
Scatter plot
5
4
3

Quadrature

2
1
0
-1
-2
-3
-4
-5
-5

0
In-Phase

Scatter plot
4
3

Quadrature

2
1
0
-1
-2
-3
-4

-4

-2

0
In-Phase

Scatter plot
3
2

Quadrature

1
0
-1
-2
-3
-3

-2

-1

0
In-Phase

Scatter plot
2.5
2
1.5

Quadrature

1
0.5
0
-0.5
-1
-1.5
-2
-2.5
-2

-1

0
In-Phase

Scatter plot
2
1.5

Quadrature

1
0.5
0
-0.5
-1
-1.5
-2
-2

-1

0
In-Phase

10

SER
BER
-1

10

-2

10

-3

10

-4

10

10

Question 2 Code
clear all
close all
clc
% Generation of 30000 random bits
b = randint(1,10000);
% Autocorrelation
b_corr = xcorr(b);
plot(b_corr)
% Repetition coding
b = [b;b;b];
b1 = reshape(b,1,numel(b));
% Binary Phase Shift Keying
d = 2*b1-1;
figure
plot(xcorr(d))
scatterplot(d)
% Noise Generation
G = randn(1,30000)+i*randn(1,30000);
% Autocorrelation of noise
figure
plot(abs(xcorr(G)))
% SNR values given
SNR = [0 2.5 5 7.5 10]
SYM = zeros(5,1);
% Computing the S.D and adding the noise
for i = 1:5
sig(i) = 10^(-SNR(i)/20);
% Changing the variance of the noise
N(i,:) = sig(i)*G;
% Adding the noise and actual signal
Y(i,:) = d + N(i,:);
scatterplot(Y(i,:))
% Detecting the received symbols
for j= 1:size(d,2)
if real(Y(i,j))>0
Yds(i,j) = 1;
else
Yds(i,j) = -1;
end
end

% Calculating the number of errors


count = 0;
for j = 1:size(d,2)
if Yds(i,j) ~= d(1,j)
count = count+1;
end
end
SYM(i,1) = count;
% Received bits detection
for j= 1: size(d,2)
if Yds(i,j)>0
Ydb(i,j) = 1;
else
Ydb(i,j) = 0;
end
end
end
SER = SYM./30000
% Decoding
for i = 1:5
p = 1;
for j = 1:3:30000
sum = Ydb(i,j) + Ydb(i,j+1) + Ydb(i,j+2);
if sum > 1
YD(i,p) = 1;
else
YD(i,p) = 0;
end
p = p+1;
end
end
% Bit Error Rate(BER) Calculation
BIT = zeros(1,5);
for i = 1:5
count = 0;
for j = 1:size(YD,2)
if YD(i,j) ~= b(1,j)
count = count+1;
end
end
BIT(i) = count;
end
BER = BIT./10000
figure
semilogy(SNR,SER,'-b.','LineWidth',1.3,'MarkerSize',15)
hold on
semilogy(SNR,BER,'-r.','LineWidth',1.3,'MarkerSize',15)
legend('SER','BER')

10

SER
BER
-1

10

-2

10

-3

10

-4

10

10

As we can see that from the output of the last problem it can be noted that
by using the interleaving, the BER and SER values are lesser when compared
to the outputs where interleaving is not used.
All the remaining figures are similar in either of the cases.

Вам также может понравиться