Professional Documents
Culture Documents
Digital Communication: LAB File
Digital Communication: LAB File
Digital Communication: LAB File
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
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);
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
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
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
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
s = (1 / sqrt(2)) * sy;
n = 1 / sqrt(2) * (randn(1, N) + 1i*randn(1, N)); %Random Noise
Generation
%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
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);
OUTPUT:
Experiment 7
CODE:
clc;
close all;
clear all;
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
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: