Digital Communication: LAB File

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

DIGITAL COMMUNICATION

LAB File

Sarthak Pal
2019UEC2616
Experiment 1

AIM:
1. Observe the output of PCM encoder when a DC
voltage is applied to its input.
2. Observe the effect when a sinusoidal signal is
passed through PCM encoder and reconstructed
using PCM decoder.

EQUIPMENTS:
1. Emona telecoms trainer 101 (plus power pack)
2. Dual channel 20Mhz oscilloscope
3. Three Emona telecoms trainer 101 oscilloscope
leads
4. Assorted Emona telecoms trainer 101 patch leads

Part 1
PROCEDURE:
OUTPUT WAVEFORMS:
Part 2
PROCEDURE:
OUTPUT WAVEFORM:
OUTPUT WAVEFORM:
Experiment 2

AIM: Evaluate the performance of Non-Linear


Quantizer when used to quantize a speech sample.

CODE:
clear all; close all;
[X fs] = audioread('Intro2.wav');
Xmax = max(X);
X = X';
[m n] = size(X);

%% Uniform quantisation
L = 16;
Xq = uniform_quantiser(X, n, L);

%% Non-uniform quantisation
cf = 255;
L = 16;
Xc = sign(X) .* log(1 + ((abs(X) ./ Xmax) .* cf)) ./ log(1 + cf);
Xcq = uniform_quantiser(Xc, n, L);

subplot(3, 1, 1); plot(X);


xlabel('Time'); ylabel('Speech sample')
subplot(3, 1, 2); plot(Xq);
xlabel('Time'); ylabel('Uniform quantised')
subplot(3, 1, 3); plot(Xcq);
xlabel('Time'); ylabel('Non-uniform quantised')

function y = uniform_quantiser(x, n, L)
% y -> quantised vector
% x -> input vector
% n -> length of the quantised (should be same as x)
% L -> number of levels for step size
xmin = min(x);
step = (max(x) - xmin)/ L;
y = zeros(1, n); % quantised
for i = 1 : n
s = xmin;
while (s < x(i))
s = s + step;
end
if (s == x(i))
y(i) = s;
else
y(i) = s - step;
end
end
end
OUTPUT:
Experiment 3

AIM: Observe the performance of Binary ASK signal


in the presence of noise.

EQUIPMENTS:
1. Emona telecoms trainer 101 (plus power pack)
2. Dual channel 20Mhz oscilloscope
3. Three Emona telecoms trainer 101 oscilloscope
leads
4. Assorted Emona telecoms trainer 101 patch leads

PROCEDURE:
EXPECTED WAVEFORM:

OUTPUT WAVEFORM:
OUTPUT WAVEFORM:
Experiment 4

AIM: Observe the performance of Binary FSK signal in


the presence of noise.

EQUIPMENTS:
1. Emona telecoms trainer 101 (plus power pack)
2. Dual channel 20Mhz oscilloscope
3. Three Emona telecoms trainer 101 oscilloscope
leads
4. Assorted Emona telecoms trainer 101 patch leads

PROCEDURE:
EXPECTED WAVEFORM:

OUTPUT WAVEFORM:
With Noise:

Demodulation:
EXPECTED WAVEFORM:
OUTPUT WAVEFORM:
Experiment 5

AIM: Evaluate the performance of QPSK modulated


wave in the presence of AWGN.

CODE:
clc;
clear all;
close all;
N = 2 * 10^5;
Eb_N0_dB = 2 : 20;
sy_hat = zeros(1, N);
nerr = zeros(1, N);
%Signal Transmission and Detection
for i=1:length(Eb_N0_dB)
si = (2 * (rand(1, N) > 0.5) - 1); %In-Phase Symbol Generation ||
rand(1, N) > 0.5 -> Gives logical Array of 0s and 1s
sq = (2 * (rand(1, N) > 0.5) - 1); %Quadrature Symbol Generation

sy = si + 1i*sq; %Adding the two Symbols

s = (1 / sqrt(2)) * sy;
n = 1 / sqrt(2) * (randn(1, N) + 1i*randn(1, N)); %Random Noise
Generation

y = 10 ^ (Eb_N0_dB(i) / 20) * s + n; %Received Signal


si_ = real(y);
sq_ = imag(y);

sy_hat(si_ < 0 & sq_ < 0) = -1 + -1 * 1i;


sy_hat(si_ >= 0 & sq_ > 0) = 1 + 1 * 1i;
sy_hat(si_ < 0 & sq_ >= 0) = -1 + 1 * 1i;
sy_hat(si_ >= 0 & sq_ < 0) = 1 + -1 * 1i;

%BER Calculation
nerr(i) = size(find((sy - sy_hat)), 2); %No. of Errors
end
simu = nerr / N;
theory = erfc(sqrt(0.5 * (10 .^ (Eb_N0_dB/10)))) - (1/4) * (erfc(sqrt(0.5
* (10 .^ (Eb_N0_dB) / 10)))) .^ 2;
semilogy(Eb_N0_dB, theory, 'b-');
hold on;
semilogy(Eb_N0_dB, simu(2:20), 'k+');
axis([2 14 10^-5 1])
grid on
legend('Theory QPSK', 'Simulated QPSK');
xlabel('SNR(dB)');
ylabel('BER');
title('BER for QPSK modulation in AWGN');
OUTPUT:
Experiment 6

AIM: Generate the symbols with the following


probabilities:
x1=0.1, x2=0.4, x3=0.3, x4=0.1, x5=0.6
Using Huffman technique find the codes and the
compression ratio.

CODE:
clc;
clear all;
close all;
n = input('Number of Symbols:');
p = zeros(1, n);
for i=1:n
fprintf('Give the probability for %dth symbol:', i);
p(i) = input('');
end
[p, I] = sort(p, 'descend');
codes = getCodes(p);
Lk_pk = zeros(1, n);
for i=1:length(codes)
fprintf('\nCode for %dth Symbol: ', I(i));
fprintf('%g ', codes{i});
fprintf('\n');
Lk_pk(i) = length(codes{i}) * p(i);
end
avg_L = sum(Lk_pk);
Entropy = 0;
for i=1:n
Entropy = Entropy + (-1 * p(i) * log2(p(i)));
end
fprintf('\nEntropy: %f\n', Entropy);
efficiency = (Entropy / avg_L) * 100;
fprintf('\nEfficiency: %f\n', efficiency);
function codes=getCodes(p)
if (length(p) == 2)
codes = {[0]; [1]};
else
len = length(p);
p_new = [p(1:len-2), p(len - 1) + p(len)];
p_new = sort(p_new, 'descend');

codes = getCodes(p_new);
codeLen = length(codes);

pos = find(p_new==(p(len - 1) + p(len)));


pos = pos(1);
codes = [codes(1:pos - 1); codes(pos + 1:codeLen); codes(pos);
codes(pos)];
codeLen = length(codes);
codes{codeLen} = [codes{codeLen}, 1];
codes{codeLen - 1} = [codes{codeLen - 1}, 0];
end
end

OUTPUT:
Experiment 7

AIM: Generate the symbols with the following


probabilities:

x1=1#2, x2=1#4, x3=1#8, x4=1#8


Using Shannon Fano Encoding technique find the codes
and the compression ratio.

CODE:
clc;
close all;
clear all;

m=input('enter the numbers of message ensembles : ');


z=[];
h=0;
l=0;
display('enter the probabilities in descending order');
for i=1:m
fprintf('ensemble %d\n',i);
p(i)=input('');
end

a(1)=0;
for j=2:m
a(j)=a(j-1)+p(j-1);
end
fprintf('\n alpha matrix');
display(a);

for i=1:m
n(i)=ceil(-1*(log2(p(i))));
end
fprintf('\n code length matrix');
display(n);

for i=1:m
int=a(i);
for j=1:n(i)
frac=int*2;
c=floor(frac);
frac=frac-c;
z=[z c];
int=frac;
end
fprintf('codeword %d', i);
display(z);
z=[];
end
fprintf('average code length');
for i=1:m
x=p(i)*n(i);
l=l+x;
x=p(i)*log2(1/p(i));
h=h+x;
end
display(l);
fprintf('entropy');
display(h);
fprintf('efficiency');
display(100*h/l);

OUTPUT:
EXPERIMENT 8

AIM: Generate (7,4) Linear Block Code given a


generator Matrix G =
[1101000; 0110100; 1110010; 1010001 ]
Assume that the received vector is 1 0 0 1 0 0 1. Find
the Syndrome.

CODE:
n=7;
k=4;
G = [1,1,0,1,0,0,0;
0,1,1,0,1,0,0;
1,1,1,0,0,1,0;
1,0,1,0,0,0,1]
parityMatrix = G(:,1:3)
id = eye(n-k);
H = [id transpose(parityMatrix)]
r = [1,0,0,1,0,0,1];
syndrome = mod(r*transpose(H), 2)
% disp(syndrome);

OUTPUT:

You might also like