Lab 4
Lab 4
Lab 4
EEE353
Lab Manual
RegistrationNumber FA14-BET-089
Class BET(7B)
PRE_LAB:
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.
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 :
Results /3
Critical Analysis /1
Comments