Cycle 1 Dclab
Cycle 1 Dclab
Cycle 1 Dclab
DATE:29/3/2020
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
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
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:
EXPERIMENT 2:
EXPERIMENT TITLE: Pulse shaping with Nyquist pulses
AIM OF THE EXPERIMENT:
. 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
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
%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;
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');
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);
%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');
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
SIMULATED WAVEFORMS:
PES2201800220
RESULT:
The power spectra and auto correlation of DPAM-2 signals have been
plotted using MATLAB.