Cycle 1 Dclab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

PES2201800220

DATE:29/3/2020

DIGITAL COMMUNICATION LABORATORY


UE18EC355
CYCLE 1 REPORT
EXPERIMENTS (1-5)

NAME: CHARITHA T S
USN: PES2201800220
SEMISTER: 6th
SECTION: A
BRANCH: ELECTRONICS AND COMMUNICATION
PES2201800220

EXPERIMENT 1:
TITLE: Delta Modulation
AIM OF THE EXPERIMENT: Below steps have to be performed using Delta
Modulation

THEORY: The sampling rate of a signal should be higher than the


Nyquist rate, to achieve better sampling. If this sampling interval in
Differential PCM is reduced considerably, the sample to-sample
amplitude difference is very small, as if the difference is 1-bit
quantization, then the step-size will be very small i.e., Δ delta.
The type of modulation, where the sampling rate is much higher and in
which the step size after quantization is of a smaller value Δ, such a
modulation is termed as delta modulation.

DM is a special case of DPCM. DM is the one bit or version of DPCM. DM


quantizes the difference between a sample and it's latest approximation
using only one bit of quantization. If there is only one bit of quantization,
the differences are being coded into two levels only. Let it be +𝛿 and −𝛿
respectively corresponding to positive or negative differences.
PES2201800220

MATLAB CODE:
1)
clc;
clear all;
close all;
tr=0.001; %%Time resolution
%%Time Intervals
t0=-1:tr:0;
t1=0:tr:2;
t2=2:tr:3;
t=[t0 t1 t2]; %%Vector representing the time intervals
%%Message signal
x0=zeros(size(t0));
x1=sin(2*pi*t1)-cos(4*pi*t1);
x2=zeros(size(t2));
x=[x0 x1 x2]; %%Vector representing the Message Signal
%%Plotting the signal
figure;
plot(t,x);
xlabel("Time");
ylabel("x(t)");
title("Message Signal");
xlim([0 2]) ;

SIMULATED WAVEFORMS:
PES2201800220

2)
clc;
clear all;
close all;
delta=0.1;
ts=0.01;
t0=-1:ts:0;
t1=0:ts:2;
t2=2:ts:3;
t=[t0 t1 t2]; %% Vector representing the time intervals
x0=zeros(size(t0));
x1=sin(2*pi*t1)-cos(4*pi*t1);
x2=zeros(size(t2));
x=[x0 x1 x2]; %% Vector representing the Message Signal
for n=1:length(x)
if n==1
e(n)=x(n);
eq(n)=delta*sign(e(n));
xq(n)=eq(n);
else
e(n)=x(n)-xq(n-1);
eq(n)=delta*sign(e(n));
xq(n)=eq(n)+xq(n-1);
end
end
figure;
plot(t,x,'r');
hold on;
stairs(t,xq,"blue")
xlabel("Time")
title("Delta Modulation with Ts=0.01 and delta=0.1")
xlim([0.2 1.8])
PES2201800220

SIMULATED WAVEFORMS:

3)
clc;
clear all;
close all;
delta=0.1;
ts=0.01;
%time intervals
t0=-1:ts:0;
t1=0:ts:2;
t2=2:ts:3;
t=[t0 t1 t2]; %vector representing the time intervals
%message signals
x0=zeros(size(t0));
x1=(2*sin(2*pi*t1))+cos(4*pi*t1);
x2=zeros(size(t2));
x=[x0 x1 x2]; % vector representating the message signal
% delta modulation
for n=1:length(x)
if n==1
e(n)=x(n);
eq(n)=delta*sign(e(n));
xq(n)=eq(n);
else
e(n)=x(n)-xq(n-1);
eq(n)=delta*sign(e(n));
xq(n)=eq(n)+xq(n-1);
end
end
PES2201800220

%plotting the signals


figure;
plot(t,x,'r');
hold on;
stairs(t,xq,"blue");
xlabel("time");
title("delta modulation with Ts=0.01 and delta=0.1");
xlim([0.2 1.8])

SIMULATED WAVEFORMS:

4a)
clc;
clear all;
close all;
delta=0.2;
ts=0.01;

t0=-1:ts:0;
t1=0:ts:2;
t2=2:ts:3;
t=[t0 t1 t2]; %% Vector representing the time intervals

x0=zeros(size(t0));
x1=sin(2*pi*t1)-cos(4*pi*t1);
x2=zeros(size(t2));
x=[x0 x1 x2]; %% Vector representing the Message Signal
PES2201800220

for n=1:length(x)
if n==1
e(n)=x(n);
eq(n)=delta*sign(e(n));
xq(n)=eq(n);
else
e(n)=x(n)-xq(n-1);
eq(n)=delta*sign(e(n));
xq(n)=eq(n)+xq(n-1);
end
end

figure;
plot(t,x,'r');
hold on;
stairs(t,xq,"blue")
xlabel("Time")
title("Delta Modulation with Ts=0.01 and delta=0.2")
xlim([0.2 1.8])

SIMULATED WAVEFORMS:
PES2201800220

4b)
clc;
clear all;
close all;
delta=0.3;
ts=0.02;
%% Time Intervals
t0=-1:ts:0;
t1=0:ts:2;
t2=2:ts:3;
t=[t0 t1 t2]; %% Vector representing the time intervals
%% Message signal
x0=zeros(size(t0));
x1=sin(2*pi*t1)-cos(4*pi*t1);
x2=zeros(size(t2));
x=[x0 x1 x2]; %% Vector representing the Message Signal
%% DELTA MODULATION
for n=1:length(x)
if n==1
e(n)=x(n);
eq(n)=delta*sign(e(n));
xq(n)=eq(n);
else
e(n)=x(n)-xq(n-1);eq(n)=delta*sign(e(n));
xq(n)=eq(n)+xq(n-1);
end
end
%% Plotting the signals
figure;
plot(t,x,'r');
hold on;
stairs(t,xq,"blue")
xlabel("Time")
title("Delta Modulation with Ts=0.02 and delta=0.3")
xlim([0.2 1.8])
PES2201800220

SIMULATED WAVEFORMS:

4c)
clc;
clear all;
close all;
delta=0.5;
ts=0.02;
%% Time Intervals
t0=-1:ts:0;
t1=0:ts:2;
t2=2:ts:3;
t=[t0 t1 t2]; %% Vector representing the time intervals
%% Message signalx0=zeros(size(t0));
x0=zeros(size(t0));
x1=sin(2*pi*t1)-cos(4*pi*t1);
x2=zeros(size(t2));
x=[x0 x1 x2]; %% Vector representing the Message Signal
%% DELTA MODULATION
for n=1:length(x)
if n==1
e(n)=x(n);
eq(n)=delta*sign(e(n));
xq(n)=eq(n);
else
e(n)=x(n)-xq(n-1);
eq(n)=delta*sign(e(n));
xq(n)=eq(n)+xq(n-1);
PES2201800220

end
end
%% Plotting the signals
figure;
plot(t,x,'r');
hold on;
stairs(t,xq,"blue")
xlabel("Time")
title("Delta Modulation with Ts=0.02 and delta=0.5")
xlim([0.2 1.8])

SIMULATED WAVEFORMS:

RESULT:Delta modulation is performed on x(t) for different values of Ts


and delta and the corresponding waveforms have been obtained using
MATLAB.
PES2201800220

EXPERIMENT 2:
EXPERIMENT TITLE: Pulse shaping with Nyquist pulses
AIM OF THE EXPERIMENT:

THEORY: pulse shaping is the process of changing the waveform of


transmitted pulses. Its purpose is to make the transmitted signal better
suited to its purpose or the communication channel, typically by limiting
the effective bandwidth of the transmission. By filtering the transmitted
pulses this way, the intersymbol interference caused by the channel can
be kept in control. In RF communication, pulse shaping is essential for
making the signal fit in its frequency band.
Nyquist ISI criterion describes the conditions which, when satisfied by a
communication channel (including responses of transmit and receive
filters), result in no ISI. It provides a method for constructing band-
limited functions to overcome the effects of intersymbol interference.The
Nyquist theorem relates this time domain condition to an equivalent
frequency domain condition.
PES2201800220

Examples of pulse shaping filters that are commonly found in


communication systems are:

· Sinc shaped filter

· Raised cosine filter

. Gaussian filter

MATLAB CODE:
clc; clear all; close all;
Rb=100;
Tb=1/Rb;
Tmax=10*Tb; Tr=0.001;
t=[-Tmax:Tr:Tmax];
a=0;
x=1-(4*(a^2).*(Rb^2).*(t.*t));
ptr1=(sinc(Rb*t).*cos(pi*a*Rb*t))./x;
N=length(ptr1);
PFr1=fftshift(fft(ptr1,N));
b=0.5;
y=1-(4*(b^2).*(Rb^2).*(t.*t));
ptr2=(sinc(Rb*t).*cos(pi*b*Rb*t))./y;
PFr2=fftshift(fft(ptr2,N));
c=1;
z=1-(4*(c^2).*(Rb^2).*(t.*t));
ptr3=(sinc(Rb*t).*cos(pi*c*Rb*t))./z;
PFr3=fftshift(fft(ptr3,N));
f=[-N/2:N/2-1];
figure(1);

subplot(3,2,1);
plot(t,ptr1); xlabel('time');
ylabel('amplitude');
title('signal p(t) alpha=0 Tmax=10');

subplot(3,2,3);
plot(t,ptr2); xlabel('time');
ylabel('amplitude');
title('signal p(t) alpha=0.5 Tmax=10');
subplot(3,2,5);
plot(t,ptr3);
xlabel('time');
ylabel('amplitude');
title('alpha=1 Tmax=10');

figure(2);
PES2201800220

pts=sinc(Rb*t).*sinc(Rb*t);%sinc^2 function as input


N=length(pts);
PFs=fftshift(fft(pts,N));
f=[-N/2:N/2-1];
subplot(1,2,1); plot(t,pts);
xlabel('time');
ylabel('amplitude');
title('p(t)=sinc2(Rbt) tmax=10');

Tmax=3*Tb; Tr=0.001;
t=[-Tmax:Tr:Tmax];
a=0;
x=1-(4*(a^2).*(Rb^2).*(t.*t));
ptr1=(sinc(Rb*t).*cos(pi*a*Rb*t))./x;
N=length(ptr1);
PFr1=fftshift(fft(ptr1,N));
b=0.5;
y=1-(4*(b^2).*(Rb^2).*(t.*t));
ptr2=(sinc(Rb*t).*cos(pi*b*Rb*t))./y;
PFr2=fftshift(fft(ptr2,N));
c=1;
z=1-(4*(c^2).*(Rb^2).*(t.*t));
ptr3=(sinc(Rb*t).*cos(pi*c*Rb*t))./z;
PFr3=fftshift(fft(ptr3,N));
f=[-N/2:N/2-1];
figure(1);

subplot(3,2,2);
plot(t,ptr1); xlabel('time');
ylabel('amplitude');
title('signal p(t) alpha=0 Tmax=3');
subplot(3,2,4);
plot(t,ptr2); xlabel('time');
ylabel('amplitude');
title('signal p(t) alpha=0.5 Tmax=3');
subplot(3,2,6);
plot(t,ptr3);
xlabel('time');
ylabel('amplitude');
title('alpha=1 Tmax=3');

figure(2);
pts=sinc(Rb*t).*sinc(Rb*t);%sinc^2 function as input
N=length(pts);
PFs=fftshift(fft(pts,N));
f=[-N/2:N/2-1];
subplot(1,2,2); plot(t,pts);
xlabel('time');
ylabel('amplitude');
title('p(t)=sinc2(Rbt) tmax=3');
PES2201800220

SIMULATED WAVEFORMS:
PES2201800220

RESULT: Raised cosine pulses and sinc square pulses are generated and
different values of a and Tmax are plotted for above pulses
PES2201800220

EXPERIMENT 3:
EXPERIMENT TITLE: POWER SPECTRA OF WSS PROCESSES
AIM OF THE EXPERIMENT :
PES2201800220

THEORY: Sense Stationary (WSS) process as a function of frequency. For a


zero mean, WSS, process X whose autocovariance function is integrable,
that is flit IRx(t)ldt < 00, we define the Power Spectral Density (PSD) Sx(f)
of X as the Fourier transform of its autocovariance function: Sx(f) =l Rx(t)e-
2irrjtdt.
MATLAB CODE:
FOR N=10^3 samples:
clc;clear all;close all;
N=10^3; % No of Samples
t=-N/2:N/2;% intervals
x=randn(1,length(t)); %% Gaussian white noise
figure;
subplot(3,1,1);
plot(t,x);
title('Gaussian White Noise')
ylabel('X(n)')
xlabel('No of samples')

%Autocorrelation
t_2= -fliplr(t);
lower=min(t)+min(t_2);
higher=max(t)+max(t_2);

t=lower:1:higher;
Rxx=xcorr(x,x)./N
tidx=(t>=-10)&(t<=10);

Rxxidx=Rxx(tidx);
subplot(3,1,2);
stem(t(tidx),Rxxidx)
title('Autocorrelation of white noise for N=10^3 samples')
xlabel('k')
ylabel('Rx(K)')
grid on;

%Power spectrum of White noise (DTFT of autocorrelation


function)
Nfft=512;
wscale=(-pi:(2*pi)/Nfft:pi-(pi/Nfft));
Sx=fftshift(fft(Rxxidx,Nfft));
subplot(3,1,3);
plot(wscale,abs(Sx));
title('Power Spectrum of white noise for N=10^3 samples')
xlabel('\omega')
ylabel('Sx(e^(j\omega))')
axis([-3.5 3.5 0 2])
PES2201800220

set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XtickLabel',{'-\pi','-\pi/2','0','\pi/2','\pi'})
grid on;

%AR-1 Process
N=1000;
alpha=0.9;
yn=zeros(N,1);
for n=2:N
yn(n)=(yn(n-1)*alpha)+x(n);
end

%Autocorrelation of AR process
k=10;
[Ry,ys]=xcorr(yn,yn,k);
Ry=Ry./N;
Sy=fftshift(fft(Ry,Nfft));
figure();
subplot(2,1,1);
stem(ys,Ry);
xlabel('k');
ylabel('Ry(k)');
title('Autocorrelation of Y(n) with N=10^3');

%Power spectrum of AR process


subplot(2,1,2);
plot(wscale,abs(Sy));
xlabel('\omega');
ylabel('S_x(e^{j\omega})');
set(gca,'XTick',-pi:pi/2:pi);
set(gca,'XTickLabel',{'-\pi','-\pi/2','0','\pi/2','\pi'});
title('Power Spectrum of Ry(k) with \alpha = 0.9 and N=10^3');
PES2201800220

SIMULATED WAVEFORM:
PES2201800220

MATLAB CODE:
FOR N=10^5 samples
clc;clear all;close all;

N=10^5; % No of Samples
t=-N/2:N/2;%intervals
x=randn(1,length(t)); %% Gaussian white noise
figure;
subplot(3,1,1);
plot(t,x);
title('Gaussian White Noise')
ylabel('X(n)')
xlabel('No of samples')

%Autocorrelation

t_2= -fliplr(t);
lower=min(t)+min(t_2);
higher=max(t)+max(t_2);

t=lower:1:higher; %% time interval for plotting


autocorrelation function
Rxx=xcorr(x,x)./N; %% Using the xcorr function to find the
autocorrelation and normalizing it
tidx=(t>=-10)&(t<=10); %% range for plotting from -10 to 10

Rxxidx=Rxx(tidx); %% Autocorrelation for the given range


subplot(3,1,2)
stem(t(tidx),Rxxidx)
title('Autocorrelation of white noise for N=10^3 samples')
xlabel('k')
ylabel('Rx(K)')
set(gca,'XTick',-10:1:10)
grid on;

%Power spectrum of White noise (DTFT of autocorrelation


function)
Nfft=512;
wscale=(-pi:(2*pi)/Nfft:pi-(pi/Nfft));
Sx=fftshift(fft(Rxxidx,Nfft));
subplot(3,1,3);
plot(wscale,abs(Sx));
title('Power Spectrum of white noise for N=10^3 samples')
xlabel('\omega')
ylabel('Sx(e^(j\omega))')
axis([-3.5 3.5 0 2])
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XtickLabel',{'-\pi','-\pi/2','0','\pi/2','\pi'})
grid on;
PES2201800220

%AR-1 Process
N=10^5;
alpha=0.9;
yn=zeros(N,1);
for n=2:N
yn(n)=(yn(n-1)*alpha)+x(n);
end

%Autocorrelation of AR process
k=10;
[Ry,ys]=xcorr(yn,yn,k);
Ry=Ry./N;
Sy=fftshift(fft(Ry,Nfft));
figure();
subplot(2,1,1);
stem(ys,Ry);
xlabel('k');
ylabel('Ry(k)');
title('Autocorrelation of Y(n) with N=10^5');

%Power spectrum of AR process


subplot(2,1,2);
plot(wscale,abs(Sy));
xlabel('\omega');
ylabel('S_x(e^{j\omega})');
set(gca,'XTick',-pi:pi/2:pi);
set(gca,'XTickLabel',{'-\pi','-\pi/2','0','\pi/2','\pi'});
title('Power Spectrum of Ry(k) with \alpha = 0.9 and N=10^5');
SIMULATED WAVEFORMS:
PES2201800220

RESULT: Autocorrelation and power spectra of gaussian distribution


(white noise) with unit variance and zero mean have been plotted using
matlab.
PES2201800220

EXPERIMENT-4:
EXPERIMENT TITLE : POWER SPECTRA OF DPAM-1 SIGNALS
AIM OF THE EXPERIMENT :
To plot the autocorrelation and power spectra of the following
signals:
1. Unipolar NRZ
2. Polar NRZ
3. Bipolar NRZ
THEORY:
Pulse-amplitude modulation (PAM), is a form of
signal modulation where the message information is encoded in
the amplitude of a series of signal pulses. It is an analog pulse
modulation scheme in which the amplitudes of a train of carrier pulses
are varied according to the sample value of the message signal.
Demodulation is performed by detecting the amplitude level of the
carrier at every single period.

MATLAB CODE:
clc;
clear all;
close all;
Type='Unipolar NRZ';
Tr=0.001;
Rb=100;
Tb=1/Rb;
T=0:0.001:0.25
Ttotal=1000;
n=10^5;
NcorrA=10;
NcorrX=100;
Nfft=512;
t=[0:Tr:Ttotal];
PES2201800220

t=t(1:end-1);
Nsamples = length(t);
Nfactor=Tb/Tr;
Nbits=Ttotal*Rb;
SxfAxis = [-200 200 0 60];
At=double(randi([0 1] , [1 n]));
switch Type
case 'Unipolar NRZ'
PulseShape = ones(1,Nfactor);
SxfAxis = [-200 200 0 60];
case 'Unipolar RZ'
PulseShape = [ones(1,Nfactor/2) zeros(1,Nfactor/2)];
SxfAxis = [-250 250 0 20];
case 'Polar NRZ'
At= 2*At-1;
PulseShape = ones(1,Nfactor);
SxfAxis = [-200 200 0 20];
case 'Polar RZ'
At= 2*At-1;
PulseShape = [ones(1,Nfactor/2) zeros(1,Nfactor/2)];
SxfAxis = [-250 250 0 10];
case 'Bipolar NRZ'
Aindex = find(At);
Aindex = downsample(Aindex,2,1);
At(Aindex) = -1;
PulseShape = ones(1,Nfactor);
SxfAxis = [-200 200 0 10];
end
Xt= kron(At,PulseShape);
subplot(2,2,1);
plot(t(1:250),Xt(1:250));
grid on;
axis([0 0.25 -2 2]);
sgtitle([Type, ' with R_b = 100 bps']);
title('X(t)');
rAt = xcorr(At,NcorrA)./Nbits;
subplot(2,2,2);
stem([-NcorrA:NcorrA],rAt);
grid on;
title('R_A(n)');
rxt = xcorr(Xt,NcorrX)./Nsamples;
subplot(2,2,3);
plot((-NcorrX*Tr:Tr:NcorrX*Tr),rxt);
grid on;
title('R_X(\tau)');
%set the frequency table to display the FFt output in terms of
analogfrequency
f= ((-Nfft/2):(Nfft/2)-1)/(Nfft*Tr);
Sxf = abs(fftshift(fft(rxt,Nfft)));
subplot(2,2,4);
plot(f,Sxf);
PES2201800220

grid on
axis(SxfAxis);
title('S_X(f)');

SIMULATED WAVEFORMS:
PES2201800220

RESULT:
The autocorrelation and power spectra of the DPAM-1 signals have
been plotted using MATLAB.
PES2201800220

EXPERIMENT -5
EXPERIMENT TITLE: POWER SPECTRA OF DPAM-2 SIGNALS
AIM OF THE EXPERIMENT :
To plot the autocorrelation and power spectra of the following
signals:
1. Unipolar RZ
2. Polar RZ
3. Manchester coding
THEORY:
Pulse-amplitude modulation (PAM), is a form of signal modulation where
the message information is encoded in the amplitude of a series of signal
pulses. It is an analog pulse modulation scheme in which the amplitudes
of a train of carrier pulses are varied according to the sample value of the
message signal.

MATLAB CODE:
close all;
clear all;
Type = 'Unipolar RZ';
Rb=100;
Tr=0.001;
Tb=1/Rb;
Ttotal = 1000;
NcorrX=100;
NcorrA=10;
Nfft=512;
t=[0:Tr:Ttotal];
t=t(1:end-1);
Nsamples = length(t);
Nfactor= Tb/Tr;
Nbits=Ttotal*Rb;
At= double(randn(1,Nbits) > 0);
SxfAxis = [-200 200 0 60];
switch Type
case 'Unipolar NRZ'
PulseShape = ones(1,Nfactor);
SxfAxis = [-200 200 0 60];
case 'Unipolar RZ'
PES2201800220

PulseShape = [ones(1,Nfactor/2) zeros(1,Nfactor/2)];


SxfAxis = [-250 250 0 20];
case 'Polar NRZ'
At= 2*At-1;
PulseShape = ones(1,Nfactor);
SxfAxis = [-200 200 0 20];
case 'Polar RZ'
At= 2*At-1;
PulseShape = [ones(1,Nfactor/2) zeros(1,Nfactor/2)];
SxfAxis = [-250 250 0 10];
case 'Bipolar NRZ'
Aindex = find(At);
Aindex = downsample(Aindex,2,1);
At(Aindex) = -1;
PulseShape = ones(1,Nfactor);
SxfAxis = [-200 200 0 10];
otherwise
At = 2*At -1;
PulseShape = [ones(1,Nfactor/2) -ones(1,Nfactor/2)];
SxfAxis = [-250 250 0 10];
end
Xt= kron(At,PulseShape);
subplot(2,2,1);
plot(t(1:250),Xt(1:250));
grid on;
axis([0 0.25 -2 2]);
sgtitle([Type, ' with R_b = 100 bps']);
title('X(t)');
rAt = xcorr(At,NcorrA)./Nbits;
subplot(2,2,2);
stem([-NcorrA:NcorrA],rAt);
grid on;
title('R_A(n)');
rxt = xcorr(Xt,NcorrX)./Nsamples;
subplot(2,2,3);
plot((-NcorrX*Tr:Tr:NcorrX*Tr),rxt);
grid on;
title('R_X(\tau)');
%set the frequency table to display the FFt output in terms of
analogfrequency
f= ((-Nfft/2):(Nfft/2)-1)/(Nfft*Tr);
Sxf = abs(fftshift(fft(rxt,Nfft)));
subplot(2,2,4);
plot(f,Sxf);
grid on
axis(SxfAxis);
title('S_X(f)');
PES2201800220

SIMULATED WAVEFORMS:
PES2201800220

RESULT:
The power spectra and auto correlation of DPAM-2 signals have been
plotted using MATLAB.

You might also like