Download - Comm Lab File
-
8/10/2019 Comm Lab File
1/32
1
DIGITAL COMMUNICATION LAB
Submitted By
Kodamanchili Rahul
60/EC/09
-
8/10/2019 Comm Lab File
2/32
2
CONTENTS
S. No Experiment Teachers Sign
1To evaluate the performance and compute the
SNR of Uniform and -law companding
quantizer
2 To evaluate the performance of DPCM and DM
schemes
3 To perform M-ary ASK/FSK/PSK Modulation
4
Generate four symbols with the given
probabilities a = 0.4, b = 0.3, c = 0.2, d = 0.1. Do
Huffman Coding and decoding of the signal and
compute the data rate compression
5
Generate a random sequence of 0s and 1s.
Generate the linear block code, add noise and
perform decoding
6To sample a signal of given amplitude and
frequency using Flat top and natural sampling
and reconstruct it back at the receiver
7Convert a sine wave to PCM data stream using
PCM encoder and reconstruct it back at the
receiver using PCM decoder
8 To observe the effect of limited bandwidth on
transmission of digital data
9
To evaluate performance of M-ary
ASK/PSF/FSK/QPSK/QAM signal and evaluate
its performance in the presence of Additive
White Gaussian Noise
-
8/10/2019 Comm Lab File
3/32
3
EXPERIMENT 1
Aim: - To evaluate the performance and compute the SNR of Uniform and -law compandingquantizer
[I] Uniform Quantizer
MATLAB Code: -
clear all;
clc;
N=2000;
a=rand(1,N)-0.5;
b=a;
for L=3:80
Linv=1/L;
for n=1:N
c(n)=0;
d(n)=0;
for j=0:L-1
if ( ( a(n)>(j*Linv-0.5) ) & ( a(n)
-
8/10/2019 Comm Lab File
4/32
4
Output: -
0 10 20 30 40 50 60 70 800
1000
2000
3000
4000
5000
6000
7000
Quantisation Levels---->
SNR
----
>
Uniform Quantizer
[II] -Law Companding Quantizer
MATLAB Code: -
clear all;
clc;
A = 10000; %Number of valuesMax =256; %Maximum value with minimum = 0
DATA = Max*rand(1,A);
Power=0;
for i=1:length(DATA)
Power = Power + DATA(i).^2;
end
Power;
u=1;
for i=1:length(DATA)
b(i)=Max*((log10((DATA(i)/Max)*u+1)) / (log10(1+u)));
endT = 100;%Number of maximum levels
N = zeros(1,T);
for z = 2:T
L = z;%Number of levels
d = zeros(1,length(b));
Diff = zeros(1,length(b));
M = (max(b))/L; %Interval
for i=1:length(b),
j=1;
-
8/10/2019 Comm Lab File
5/32
5
while b(i) > (j*M)
d(i) = d(i) + M;
j = j+1;
end
end
Diff = DATA-d;
Noise = 0;for i=1:length(Diff)
Noise = Noise + Diff(i).^2;
end
N(z)=Noise;
SNR(z) = Power/N(z);
end
plot(SNR,'k')
xlabel('Number of levels---->');
ylabel('SNR');
title('u Law quantizating');
Output: -
0 10 20 30 40 50 60 70 80 90 1000
50
100
150
200
250
Number of levels---->
SNR
u Law quantizating
-
8/10/2019 Comm Lab File
6/32
6
EXPERIMENT 2
Aim: - To evaluate the performance of DPCM and DM schemes.
[I] DPCM (Differential Pulse Code Modulation)
MATLAB Code: -
%perform DPCM
% 7 level quantizer
clear all;
clc;
N = 100;
X = rand(N,1);
X = X-1/2;
for i = 1:length(X)
if(i>3)
Xp(i) = 0.3*u(i-1)+0.2*u(i-2)+0.5*u(i-3); %Depends upon past 3 valueselse
Xp(i) = 0;
end
e(i) = X(i)-Xp(i);
if (e(i)>5/12)
eq(i) = 3/6;
elseif (e(i)>3/12)
eq(i) = 2/6;
elseif (e(i)>1/12)
eq(i) = 1/6;
elseif (e(i)>-1/12)
eq(i) = 0;
elseif (e(i)>-3/12)
eq(i) = -1/6;
elseif (e(i)>-5/12)
eq(i) = -2/6;
else
eq(i) = -3/6;
end
u(i)=eq(i)+Xp(i);
end
plot(1:length(X),X,1:length(u),u)
xlabel('x--->');ylabel('y--->');
title('DPCM');
figure(2)
stem(e,eq)
xlabel('Vin--->');
ylabel('Vo--->');
title('Transfer Characteristic');
%proceed further
QN = 0;
-
8/10/2019 Comm Lab File
7/32
7
SN = 0;
for i= 1:length(e)
QN = QN + (X(i)-u(i))^2;
SN = SN + u(i)^2;
end
QN = QN/length(QN);
SN = SN/length(SN);SNR = SN/QN
Outputs: -
SNR = 12.63
-
8/10/2019 Comm Lab File
8/32
8
[II] DM
MATLAB Code: -
%perform DM
% 2 level quantizer
clear all;
clc;
N = 100;
X = sin(0.05*(1:N));X = X-1/2;
for i = 1:length(X)
if(i>1)
Xp(i) = u(i-1);
else
Xp(i) = 0;
end
e(i) = X(i)-Xp(i);
if (e(i)>0)
eq(i) = 1/9;
else
eq(i) = -1/9;
end
u(i)=eq(i)+Xp(i);
end
plot(1:length(X),X,1:length(u),u)
xlabel('x--->');
ylabel('y--->');
title('DM');
-
8/10/2019 Comm Lab File
9/32
9
figure(2)
stem(e,eq)
xlabel('Vin--->');
ylabel('Vo--->');
title('Transfer Characteristic');
%proceed further
QN = 0;
SN = 0;
for i= 1:length(e)
QN = QN + (X(i)-u(i))^2;
SN = SN + u(i)^2;
end
QN = QN/length(QN);
SN = SN/length(SN);
SNR = SN/QN
Outputs: -
SNR = 122.53
-
8/10/2019 Comm Lab File
10/32
10
-
8/10/2019 Comm Lab File
11/32
11
Experiment 3
Aim: - To perform M-ary ASK/FSK/PSK Modulation
[I] Binary ASK
MATLAB Code: -
clc;
clear all;
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)>0X(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,'k');
xlabel('Time--->');
ylabel('Amplitude--->');
title('ASK');
Output: -
0 200 400 600 800 1000 1200 1400 1600 1800 2000-5
-4
-3
-2
-1
0
1
2
3
4
5
Time--->
Amp
litude--
->
ASK
-
8/10/2019 Comm Lab File
12/32
12
[II] Binary PSK
MATLAB Code: -
clc;
clear all;
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,'k');
xlabel('Time--->');
ylabel('Amplitude--->');
title('PSK');
axis([0 2000 -5 5]);
Output: -
0 200 400 600 800 1000 1200 1400 1600 1800 2000-5
-4
-3
-2
-1
0
1
2
3
4
5
Time--->
Amp
litude--->
PSK
-
8/10/2019 Comm Lab File
13/32
-
8/10/2019 Comm Lab File
14/32
14
[IV] 4-ary ASK
MATLAB Code: -
clc;clear all;
n=2;
X = rand(20,1);
X=X-0.5;
Ai = 5;
fc = 1000;
Tb = 0:.00001:.002;%Bit duration/half symbol duration
for i=1:length(X),
if X(i)>0
X(i)=1;
elseX(i)=0;
end;
if(mod(i,2)==0)
for(j = 1:length(Tb))
for(p=1:n)
Y(j+(i-p)*length(Tb)) = Ai*(X(i)+2*X(i-1))*sin(2*pi*fc*Tb(j));
end
end;
end
end;
plot(1:length(Y),Y,'k');
xlabel('Time--->');
ylabel('Amplitude--->');
title('ASK');
axis([0 4003 -16 16]);
-
8/10/2019 Comm Lab File
15/32
15
Output: -
0 500 1000 1500 2000 2500 3000 3500 4000
-15
-10
-5
0
5
10
15
Time--->
Amp
litude--->
ASK
[V] 4-ary PSK
MATLAB Code: -
clc;
clear all;
n=2;
X = rand(10,1);
X=X-0.5;
Ai = 5;
fc = 1000;
Tb = 0:.000001:.002;%Bit duration/half symbol duration
for i=1:length(X),if X(i)>0
X(i)=1;
else
X(i)=0;
end;
if(mod(i,2)==0)
for(j = 1:length(Tb))
for(p=1:n)
Y(j+(i-p)*length(Tb)) = Ai*sin(2*pi*fc*Tb(j)+(((X(i)+2*X(i-1)))*pi/2));
end;
end
end
end;
plot(1:length(Y),Y,'k');
xlabel('Time--->');
ylabel('Amplitude--->');
title('PSK');
axis([0 20003 -6 6]);
-
8/10/2019 Comm Lab File
16/32
16
Output: -
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-6
-4
-2
0
2
4
6
Time--->
Amp
litude--->
PSK
[VI] 4-ary FSK
MATLAB Code: -
clc;
clear all;
clc;
clear all;
n=2;
X = rand(10,1);
X=X-0.5;
Ai = 5;
fc = 1000;Tb = 0:.000001:.002; %Bit duration/half symbol duration
for i=1:length(X),
if X(i)>0
X(i)=1;
else
X(i)=0;
end;
if(mod(i,2)==0)
for(j = 1:length(Tb))
for(p=1:n)
Y(j+(i-p)*length(Tb)) = Ai*sin(2*pi*(fc+200*(X(i)+2*X(i-1)))*Tb(j));
end
end;
end
end;
plot(1:length(Y),Y,'k');
xlabel('Time--->');
ylabel('Amplitude--->');
title('FSK');
axis([0 20003 -6 6]);
-
8/10/2019 Comm Lab File
17/32
17
Output: -
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 10
4
-6
-4
-2
0
2
4
6
Time--->
Amp
litude--->
FSK
-
8/10/2019 Comm Lab File
18/32
-
8/10/2019 Comm Lab File
19/32
19
Outputs: -
H = 1.8464
Sym = 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0
Tx = 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0
Lbar = 1.9000
Efficiency = 97.1810
Tx(j+1)=0;
Tx(j+2)=0;j=j+3;
endend
TxLbar=1*p(1)+2*p(2)+3*p(3)+3*p(4)Efficiency=H*100/Lbar
-
8/10/2019 Comm Lab File
20/32
20
[II] Huffman Decoder
MATLAB Code: -
clc;clear all;num=10;
% Probabilities a=0.4, b=0.3, c=0.2, d=0.1j=1;
X=rand(1,num);
for i=1:numif(X(i)0.9)Rx(j)=1;
Rx(j+1)=0;
Rx(j+2)=0;j=j+3;
endend
j=1;i=1;% for i=1:length(Rx)while(i~=length(Rx)+1)
if(Rx(i)==0)Sym(j)=0;
Sym(j+1)=0;
j=j+2i=i+1
elseif(Rx(i)==1)if((Rx(i+1)==0)&&(Rx(i+2)==1))
Sym(j)=1;Sym(j+1)=0;
j=j+2i=i+3
elseif((Rx(i+1)==0)&&(Rx(i+2)==0))
Sym(j)=1;S m +1 =1;
-
8/10/2019 Comm Lab File
21/32
21
Outputs: -
Rx= 1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 1 1 0 1
Sym = 1 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 1 0 1 0
j=j+2
i=i+3elseif(Rx(i+1)==1)
Sym(j)=0;
Sym(j+1)=1;j=j+2
i=i+2end
endend
-
8/10/2019 Comm Lab File
22/32
22
EXPERIMENT 5
Aim: - Generate a random sequence of 0s and 1s. Generate the linear block code, add noiseand perform decoding.
[I] Linear Block Code
MATLAB Code: -
clear all;clc;
a=rand(1,4);for i=1:length(a)
if(a(i)
-
8/10/2019 Comm Lab File
23/32
23
Outputs: -
DATA =
0 1 1 0
C =
1 0 0 0 1 1 0
R =
0 0 0
S =
1 1 0 0 0 1 0
E =
0 0 1
-
8/10/2019 Comm Lab File
24/32
-
8/10/2019 Comm Lab File
25/32
25
Observations:
Natural sampling of Sine Wave Flat top sampling of Sine Wave
Natural Sampling at higher sampling frequency Reconstruction of message signal
Input Signal and the Reconstructed Signal
-
8/10/2019 Comm Lab File
26/32
26
EXPERIMENT 7
Aim: - Convert a sine wave to a PCM data stream using PCM encoder and reconstruct the
message at the receiver using PCM decoder
Apparatus:Emona Telecoms Kit 101, BNC Connectors, Digital Storage Oscillicope, Patch leads
Theory:
In Pulse Code Modulation, a message signal is represented by a sequence of coded pulses,
which is accomplished by representing in discrete form in both time and amplitude. The basic
operations performed in the transmitter of a PCM system are sampling, quantizing and
encoding, the low pass filter before sampling the signal is used for preventing aliasing of the
message signal. The quantizing and encoding operations are usually performed in the same
circuit, which is called an analog-to-digital converter. The basic operations in the receiver are
regeneration of impaired signals, decoding and reconstruction of the train of quantized
samples. When TDM is used, it becomes necessary to synchronize the receiver to thetransmitter for the overall system to operate satisfactorily.
Pulse Code Encoding
Pulse Code Decoding
In combining the processes of sampling and quantization, the specification of a continuous
message baseband signal becomes limited to a discrete set of values, but not in the form best
suited to transmission over a telephone line or radio path. To exploit the advantages of
sampling and quantizing for the purpose of making the transmitted signal more robust to noise,
interference and other channel impairments, we require use of encoding process to translatethe discrete set of values to a more appropriate form of digital signal. Maximum advantage
over the effects of noise in a medium is obtained by using a binary code because a binary
symbol withstands high level of noise and is easy to regenerate.
-
8/10/2019 Comm Lab File
27/32
27
Observations:
Sampling frequency for PCM Encoder
PCM Encoded Sine Wave
PCM Decoded Sine wave at the receiver and the input sine wave
-
8/10/2019 Comm Lab File
28/32
28
EXPERIMENT 8
Aim:- To observe the effect of limited bandwidth on the transmission of digital data
Apparatus:Emona Telecoms Kit 101, BNC Connectors, Digital Storage Oscillicope, Patch leads
Theory:
In classical model, intelligence moves from transmitter to a receiver over a channel. A number
of transmission media can be used for the channel including metal conductors. Regardless of
the medium used, all channels have a bandwidth. That is, the medium lets a range of signal
frequencies pass relatively unaffected while frequencies outside the range are mode smaller.
The issue has important implications. If the mediums bandwidth isnt wide enough some of the
sine waves are attenuated and others are lost completely.
Square Wave through a channel through a band limited channel
Bandwidth limiting in a channel can distort digital signals and upset the operation of the
receiver. A solution to the problem of limited bandwidth of the channel is to use a transmission
medium that has a sufficiently wide bandwidth for the digital data. As digital technologyspreads there are demands to push more data down existing channels. To do so without
slowing things down requires that the transmission bit rate be increased. This ends up having
the same basic effect as reducing the channels bandwidth.
Eye diagrams give us idea about the signals quality and the channels bandwidth. As bandwidth
limiting degrades the signals quality the eyes begin to close.
Eye Diagram
-
8/10/2019 Comm Lab File
29/32
29
Observations:
PCM Data with full bandwidth PCM Data with restricted bandwidth using a LPF
Eye Diagram
Restored Digital Signal using Comparator
-
8/10/2019 Comm Lab File
30/32
30
EXPERIMENT 9
Aim:- To generate binary ASK/FSK/QPSK signal and evaluate its performance in the presence of
Additive White Gaussian Noise
Apparatus:Emona Telecoms Kit 101, BNC Connectors, Digital Storage Oscillicope, Patch leads
Theory:
Amplitude-shift keying is a form of modulation that represents digital data as variations in
the amplitude of a carrier wave. The amplitude of an analog carrier signal varies in accordance
with the bit stream (modulating signal), keeping frequency and phase constant. The level of
amplitude can be used to represent binary logic 0s and 1s.
The simplest and most common form of ASK operates as a switch, using the presence of a
carrier wave to indicate a binary one and its absence to indicate a binary zero. This type of
modulation is called on-off keying, and is used at radio frequencies to transmit Morse code(referred to as continuous wave operation).
More sophisticated encoding schemes have been developed which represent data in groups
using additional amplitude levels. For instance, a four-level encoding scheme can represent
two bits with each shift in amplitude; an eight-level scheme can represent three bits; and so on.
These forms of amplitude-shift keying require a high signal-to-noise ratio for their recovery, as
by their nature much of the signal is transmitted at reduced power.
Frequency-shift keying (FSK)is a frequency modulation scheme in which digital information is
transmitted through discrete frequency changes of a carrier wave. The simplest FSK is
binary FSK(BFSK). BFSK literally implies using a pair of discrete frequencies to transmit binary
(0s and 1s) information. With this scheme, the "1" is called the mark frequency and the "0" iscalled the space frequency.
Phase-shift keying (PSK)is a digital modulation scheme that conveys data by changing, or
modulating, the phase of a reference signal (the carrier wave). Any digital modulation scheme
uses a finite number of distinct signals to represent digital data. PSK uses a finite number of
phases, each assigned a unique pattern of binary digits. Usually, each phase encodes an equal
number of bits. Each pattern of bits forms the symbol that is represented by the particular
phase. The demodulator, which is designed specifically for the symbol-set used by the
modulator, determines the phase of the received signal and maps it back to the symbol it
represents, thus recovering the original data.
Alternatively, instead of using the bit patterns to setthe phase of the wave, it can instead be
used to changeit by a specified amount. The demodulator then determines the changesin the
phase of the received signal rather than the phase itself. Since this scheme depends on the
difference between successive phases, it is termed differential phase-shift keying (DPSK). DPSK
can be significantly simpler to implement than ordinary PSK since there is no need for the
demodulator to have a copy of the reference signal to determine the exact phase of the
received signal (it is a non-coherent scheme). In exchange, it produces more erroneous
demodulations. The exact requirements of the particular scenario under consideration
determine which scheme is used.
http://en.wikipedia.org/wiki/Signal_(electrical_engineering)http://en.wikipedia.org/wiki/Signal_(electrical_engineering) -
8/10/2019 Comm Lab File
31/32
31
Observations:
Digital Signal and its ASK Signal
Input Signal and its Regenerated signal after ASK
Digital Signal and its FSK modulation
-
8/10/2019 Comm Lab File
32/32
32
Demodulated FSK Signal and input signal Cleaned up demodulated signal and input signal
Signal Demodulated from the BPSK version BPSK (Even and Odd bits)