Sie sind auf Seite 1von 11

# DIGITAL COMMUNICATION

(MATLAB EXPERIMENTS)

SUBMITTED BY:

Vinay Garg
118/EC/07
EC-2

1
INDEX

## S.NO. EXPERIMENT PAGE NO.

2
EXPERIMENT – I
AIM: Compute the SQNR for uniform/μ-law companding
quantization on speech. Plot the SQNR v/s number of
quantization level.

QUANTIZATION CODE:

A LAW
m=0:1/500:1;
i=1:5;
A(i)=[1 5 10 100 1000];
for i=1:5
for j=1:501
if m(j)<1/A(i)
v(j)=(A(i).*m(j))/(1+log10(A(i)));
else
v(j)=(1+log10(A(i)*m(j)))/(1+log10(A(i)));
end
end
plot(m,v);
hold on;
end
title('A law');
xlabel('normalized i/p');
ylabel('normalized o/p');
A law
1

0.9

0.8

0.7
normalized o/p

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalized i/p

3
U LAW
m=0:1/500:1;
i=1:5;
mu(i)=[1 5 10 100 1000];
for i=1:5
for j=1:501
v(j)=(log10(1+ mu(i)*m(j)))/log10(1+mu(i));
end
plot(m,v);
hold on;
end
title('u law');
xlabel('normalized i/p');
ylabel('normalized o/p');
u law
1

0.9

0.8

0.7
normalized o/p

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalized i/p

QUANTIZATION(part a)

a=10;
k=1:1000;
b(k)=a*sin(2*pi*k/1000);
R=3;
L=(2^R);
diff=(max(b)-min(b))/L;

4
for i=1:1000
for j=1:L
if b(i)>(min(b)+(j-1)*diff) & b(i)<(min(a)+j*diff)
x(i)=min(b)+(j-.5)*diff;
end
end
end
for i=1:1000
s(i)=x(i)-b(i);
end
subplot(2,1,1)
plot(k,b)
hold on;
subplot(2,1,1)
plot(k,x)
subplot(2,1,2)
plot(k,s)
axis([0 1000 -2 2]);
p=(a^2)/2;
sig=(diff^2)/12
snr=p/sig
snrdb=10*log10(snr)

## OUTPUT: sig =0.5208

snr = 96
snrdb =19.8227

10

-5

-10
0 100 200 300 400 500 600 700 800 900 1000

-1

-2
0 100 200 300 400 500 600 700 800 900 1000

5
QUANTIZATION (part b)

a=10;
n=1000;
k=1:n;
b(k)=a*sin(2*pi*k/n);
for R=1:8
L=(2^R);
diff=(max(b)-min(b))/L;
for i=1:n
for j=1:L
if b(i)>(min(b)+(j-1)*diff) & b(i)<(min(a)+j*diff)
x(i)=min(b)+(j-.5)*diff;
end
end
end
for i=1:n
s(i)=x(i)-b(i);
end
p=(a^2)/2;
sig=(diff^2)/12;
snr(R)=1.5*(2^(2*R));
snrdb(R)=10*log10(snr(R))
end
plot(snrdb)
xlabel('Number of Bits / Sample , R');
ylabel('Signal-to-Noise Ratio(db)');
title('Signal-to-Quantization Noise Ratio for Varying Number
of Representation Levels');
Signal-to-Quantization Noise Ratio for Varying Number of Representation Levels
50

45

40
Signal-to-Noise Ratio(db)

35

30

25

20

15

10

5
1 2 3 4 5 6 7 8
Number of Bits / Sample , R

6
EXPERIMENT – II
AIM: To evaluate the performance of Differential Pulse Code
Modulation (DPCM) and Delta Modulation (DM).

DPCM CODE:

length = 100;
N = 10;
S = N;
corr = 1.2;
xuc = randn(1,length);
C = zeros(1,length);
for i = 1:S
C(1,i) = 1/(i)^corr;
end
K = toeplitz(C,C);
L =chol(K);
Xc = xuc*L;
Ci = C(1,2:length);
Ck = C(1,1:length-1);
Kinv = toeplitz(Ck,Ck);
Kinv = inv(Kinv);
w = Ci*Kinv;
%modulation
%variable decleration
Xe = zeros(1,length);
e = zeros(1,length);
eq = zeros(1,length);
for j = 1:length
for i = 1:N-1
if (j-i) > 0
Xe(1,j) = Xe(1,j)+w(1,i)*Xc(1,j-i);
end
end
e(1,j) = Xc(1,j) - Xe(1,j);
%quantize e(1,j)
end
% pulse code modulation
range = 0.5;
%quantiser initialisation
range = 2;
resolution = 64;
val = zeros(1,resolution);
for i = 1:resolution
val(1,i) = -range + range/resolution*i*2;
end
% quantize
for j = 1:length
for k = 1:resolution
if val(1,k) > e(1,j)
eq(1,j) = val(1,k);

7
break
elseif k == resolution
eq(1,j) = val(1,k);
end
end
end
% demodulation
Xr = zeros(1,length);
for j = 1:length
Xr(1,j) = eq(1,j);
for i = 1:N-1
if (j-i) > 0
Xr(1,j) = Xr(1,j)+w(1,i)*Xr(1,j-i);
end
end
end
signal_power = 0;
for i = 1:length
signal_power = (Xc(1,i))^2 + signal_power;
end
qnoise_power = 0;
for i = 1:length
qnoise_power = (Xc(1,i)-Xr(1,i))^2 + qnoise_power;
end
snr = signal_power/qnoise_power;

## OUTPUT: snr = 99.5565

8
EXPERIMENT – III
AIM: To evaluate the performance of M-ary ASK (Amplitude Shift
Keying), PSK (Phase Shift Keying) and FSK (Frequency Shift
Keying) signal in the presence of Additive White Gaussian
Noise.

## AMPLITUDE SHIFT KEYING:

X = rand(10,1);
X=X-0.5;
Ai = 5;
fc = 1000;
Tb = 0:.00001:.002; %Bit duration
for i=1:length(X),
if X(i)>0
X(i)=1;
else
X(i)=0;
end;
for(j = 1:length(Tb))
Y(j+(i-1)*length(Tb)) = Ai*X(i)*sin(2*pi*fc*Tb(j));
end;
end;
plot(1:length(Y),Y);
clear all;

OUTPUT:
5

-1

-2

-3

-4

-5
0 500 1000 1500 2000 2500

9
PHASE SHIFT KEYING:

X = rand(10,1);
X=X-0.5;
Ai = 5;
fc = 1000;
Tb = 0:.00001:.002; %Bit duration
for i=1:length(X),
if X(i)>0
X(i)=1;
else
X(i)=0;
end;
for(j = 1:length(Tb))
Y(j+(i-1)*length(Tb)) = Ai*sin(2*pi*fc*Tb(j)+X(i)*pi);
end;
end;
plot(1:length(Y),Y);
title('PSK')
clear all;

OUTPUT:

PSK
5

-1

-2

-3

-4

-5
0 500 1000 1500 2000 2500

10
FREQUENCY SHIFT KEYING :

X = rand(10,1);
X=X-0.5;
Ai = 5;
fc = 1000;
Tb = 0:.00001:.002; %Bit duration
for i=1:length(X),
if X(i)>0
X(i)=1;
else
X(i)=0;
end;
for(j = 1:length(Tb))
Y(j+(i-1)*length(Tb)) =
Ai*sin(2*pi*(fc+X(i)*fc)*Tb(j));
end;
end;
plot(1:length(Y),Y);
title('FSK')
clear all;

OUTPUT:
FSK
5

-1

-2

-3

-4

-5
0 500 1000 1500 2000 2500

11