Lab 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Digital Communication Systems

EEE353

Lab Manual

Name Sania Tariq

RegistrationNumber FA14-BET-089

Class BET(7B)

Instructor’sName WAJIHA SHARIQ


Lab # 4Generation of PCM Line codes and analyzing
their Power Spectral Density.
OBJECTIVES:
The students will be able to develop an understanding of what line codes are and why they are
used. They will be taught about the power spectral densities and will be able to develop codes
regarding different PCM line codes.

PRE_LAB:

Power Spectral Density:


Power Spectral Density (PSD) of a random process is defined as the Fourier transform of its
autocorrelation function. The area under a given frequency band of the PSD function gives the
amount of average power contained in that frequency band which makes PSD a very strong tool
for the analysis of random processes. The PSD of an Ergodic random process can be expressed
in terms of the Fourier transform of one of its sample function. Let X(t) be an ergodic random
process, let x(t,T) be one of its sample function which is observed in the interval [0,T]. Let
X(f,T) be the Fourier transform of x(t,T). Then the periodogram of x(t,T) is defined as
1 2
¿ X ( f ,T )∨¿ ¿. The PSD of X(t) can be expressed as
2T

1
S X ( f )=lim T → ∞ E¿ ]
2T

Hence average of periodograms can be used to approximate the PSD of a random process.

PWELCH Function:
The pwelch function in MATLAB is used to approximate the PSD of a signal. The function
divides the input signal into overlapping segments and then computes their respective
periodograms and then finds the average, hence the output is an approximation of the PSD of the
input signal. The syntax of the pwelch function is

[pxx,f ] = pwelch(input_signal,window_size,overlap_size,FFTsize,sampling_freq).

Where pxx is the approximated PSD and f in the frequency vector against which PSD can be
plotted. A possible usage of pwelch maybe

[pxx,f] = pwelch(x,33,[],[],fs). The empty matrix is used so that pwelch may use its default
values for overlap and fft size and 33 specifies the length of the segment.

PCM Line Codes


There are different types of PCM line codes available for transmission of digitized data. Each
line code has its own advantages and disadvantages which make it suitable for some specific
application. In this lab we will generate five different line codes.

Polar NRZ:
In polar NRZ a ‘1’ is represented by a pulse of ‘+V volts’ and a ‘0’ is represented by a pulse of ‘-
V volts’.

Unipolar NRZ:
In unipolar RZ a ‘1’ is represented by a pulse of ‘+V volts’ whereas a ‘0’ is represented by a
pulse of ‘0 volts’.

Unipolar RZ:
In unipolar RZ a ‘1’ is represented by a pulse of ‘+V volts’ for half the bit duration and ‘0 volts’
for the rest of bit duration. A 0 is represented by ‘0 volts’ for complete bit duration.
Manchester Code:
In this type of coding a ‘1’ is represented by a pulse of ‘+V volts’ for first half of bit duration and
‘-V volts’ for the other half. A ‘0’ is represented by a pulse of ‘-V volts’ and ‘+V volts’ for the
other half.

Delay Modulation:
In delay modulation a ‘1’ is represented by a transition at the mid point of the bit duration
whereas a ‘0’ is represented by no transition unless it is followed by another ‘0’, in that case a
transition is placed at the end of bit interval of the first zero.

LAB TASK:

TASK A:
1. Define a random data of some length >100 containing 1s and 0s. Also define a test data
[1 0 1 1 0 0 0 1 1 0 1].
2. Define a pulse duration say 1msec and a high sampling time to approximate analog
signals say 0.1msec.
3. Convert the random data and test data into the line codes defined above.
4. Plot these line codes for the test data. Verify your implementation.

MATLAB CODE
fs = 100000;
f=1000;
ts = 1/f;
t=linspace(0,1/f,fs/f);
length(t)
time=linspace(0,2/f,2*fs/f);
td=[1; 0; 1; 1; 0; 0; 0; 1; 1; 0; 1];
rd=(randint(1,100))'
A=[1]
rect1=[A(1)*ones(1,length(t))]
subplot(3,1,1)
plot(t,rect1,'r')
title('signal','FontWeight','bold')
xlabel('timeperiod ')
ylabel('amplitude ')
code=(rd*rect1)'
code=code(:)
t=linspace(0,100/f,length(rd)*fs/f)
subplot(3,1,2)
plot(t,code,'r')
title('unipolar nrz for random data','FontWeight','bold'),
xlabel('timeperiod')
ylabel('amplitude')
code=(td*rect1)';
code=code(:)
t=linspace(0,10/f,length(td)*fs/f)
subplot(3,1,3)
plot(t,code,'r')
title('unipolar nrz for test data','FontWeight','bold')
xlabel('timeperiod')
ylabel('amplitude')
figure()
RESULT
signal

amplitude
2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
timeperiod -3
x 10
unipolar nrz for random data

amplitude
1

0.5

0
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
timeperiod
unipolar nrz for test data
amplitude

0.5

0
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
timeperiod

subplot(2,1,1)
h=spectrum.welch
hpsd=psd(h,code,'fs',fs)
plot(hpsd)
subplot(2,1,2),
h=spectrum.periodogram
hpsd=psd(h,code,'fs',fs)
plot(hpsd)
RESULT
TASK B
1. Use Pwelch function with a window size say 30 to approximate the PSDs of different line
codes. Comment on there bandwidth efficiencies.

MATLAB CODE

f=1/1e-3;
ts=0.1e-3;
fs=1/ts;
t1=linspace(0,1/f,fs/f);
testd=[1; 0; 0; 1; 0; 0; 0; 1; 1; 0; 1];
random=(randint(1,100))'
pulse=[ones(1,length(t1))]
subplot(3,1,1)
plot(t1,pulse);
title('signal');
code=(random*pulse)';
code=code(:)
t2=linspace(0,100/f,length(random)*fs/f)
subplot(3,1,2)
plot(t2,code);
title('unipolar rz for random data');
code=(testd*pulse)';
code=code(:)
t3=linspace(0,10/f,length(testd)*fs/f)
subplot(3,1,3)
plot(t3,code);
RESULT
subplot(2,1,1)
h=spectrum.welch
hpsd=psd(h,code,'fs',fs)
plot(hpsd)
subplot(2,1,2)
h=spectrum.periodogram
hpsd=psd(h,code,'fs',fs)
plot(hpsd)

RESULT

2. Use Pwelch function with different window sizes from 10 to 50 and comment on the
accuracy of the output as compared to the theoretical results.
MATLAB CODE

fs =1/0.1e-3;
f=1/1e-3;
ts =0.1e-3
t=linspace(0,1/f,fs/f);
length(t)
time=linspace(0,2/f,2*fs/f);
testd=[0; 0; 1; 1; 1; 1; 0; 1; 1; 0; 0];
rdata=(randint(1,100))';
pulsepos=[1*ones(1,length(t))];
pulseneg=[-1*ones(1,length(t))];
subplot(3,1,1)
plot(t,pulsepos);
title('positive pulse');
subplot(3,1,2)
plot(t,pulseneg);
title('negative pulse');
testdata=[]
for i=1:10
if testd(i)==0
testdata=[testdata ((pulseneg))]
else
testdata=[testdata ((pulsepos))]
end
end
testdata=testdata'
t=linspace(0,10/f,10*fs/f);
subplot(3,1,3)
plot(t,testdata);

RESULT
subplot(2,1,1)
h=spectrum.welch
hpsd=psd(h,code,'fs',fs)
plot(hpsd)
subplot(2,1,2)
h=spectrum.periodogram
hpsd=psd(h,code,'fs',fs)
plot(hpsd)

RESULT
CONCLUSION/CRITICAL ANALYSIS:
In this lab I have learned the knowledge of :

 Line Codes ( I have learnt RZ and NRZ in this lab)


 Power Spectral Densities (which is the fourier transform of auto-coorelation function)
 PCM line codes (used for some specific applications)
The students will be able to develop an understanding of what line codes are and why they are
used. They will be taught about the power spectral densities and will be able to develop codes
regarding different PCM line codes.

Performance Viva Total/15


(10 Marks) (5 Marks )
Performance /6

Results /3

Critical Analysis /1
Comments

You might also like