0% found this document useful (0 votes)
342 views

ADC Part B Programs

The document describes three programs for digital communication systems lab: 1. Generation of NRZ, RZ, and raised cosine signals and their eye diagrams using Matlab code and functions. 2. Generation and demodulation of PCM signals including analog to digital conversion, quantization, encoding, and decoding. 3. Binary DPSK modulation and demodulation of random data using Matlab code with modulation, transmission through channel, and demodulation functions.

Uploaded by

Sahana Shavi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
342 views

ADC Part B Programs

The document describes three programs for digital communication systems lab: 1. Generation of NRZ, RZ, and raised cosine signals and their eye diagrams using Matlab code and functions. 2. Generation and demodulation of PCM signals including analog to digital conversion, quantization, encoding, and decoding. 3. Binary DPSK modulation and demodulation of random data using Matlab code with modulation, transmission through channel, and demodulation functions.

Uploaded by

Sahana Shavi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Part B : ADC Lab Programs

Program 1 : NRZ, RZ and Raised Cosine generation and their eye diagrams
1. Unipolar NRZ Matlab Code
bits = [1 0 1 0 0 0 1 1 0];
bitrate = 1;
figure;
[t,s] = unrz(bits,bitrate);
plot(t,s,'LineWidth',3);
axis([0 t(end) -0.1 1.1])
grid on;
title(['Unipolar NRZ: [' num2str(bits) ']']);

Function file(To be written in separate script file


and save it as unrz)

function [t,x] = unrz(bits, bitrate)


T = length(bits)/bitrate; % full time of bit sequence
n = 200;
N = n*length(bits);
dt = T/N;
t = 0:dt:T;
x = zeros(1,length(t)); % output signal
for i = 0:length(bits)-1
if bits(i+1) == 1
x(i*n+1:(i+1)*n) = 1;
else
x(i*n+1:(i+1)*n) = 0;
end
end

Output

2. Unipolar RZ Matlab Code

bits = [1 0 1 0 0 0 1 1 0];
bitrate = 1;
figure;
[t,s] = urz(bits,bitrate);
plot(t,s,'LineWidth',3);
axis([0 t(end) -0.1 1.1])
grid on;
title(['Unipolar RZ: [' num2str(bits) ']']);

Function file(To be written in separate script file


and save it as urz)

function [t,x] = urz(bits, bitrate)


T = length(bits)/bitrate; % full time of bit sequence
n = 200;
N = n*length(bits);
dt = T/N;
t = 0:dt:T;
x = zeros(1,length(t)); % output signal
for i = 0:length(bits)-1
if bits(i+1) == 1
x(i*n+1:(i+0.5)*n) = 1;
x((i+0.5)*n+1:(i+1)*n) = 0;
else
x(i*n+1:(i+1)*n) = 0;
end
end

Output:

3. Raised Cosine Matlab Code


clc;
clear all;
close all;
Nsym = 6; % Filter span in symbol durations
beta = 0.5; % Roll-off factor
sampsPerSym = 8; % Upsampling factor
rctFilt = comm.RaisedCosineTransmitFilter(...
'Shape', 'Normal', ...
'RolloffFactor', beta, ...
'FilterSpanInSymbols', Nsym, ...
'OutputSamplesPerSymbol', sampsPerSym)

% Visualize the impulse response


fvtool(rctFilt, 'Analysis', 'impulse')

Waveform
Impulse Response

0.35

0.3

0.25
Amplitude

0.2

0.15

0.1

0.05

-0.05
0 5 10 15 20 25 30 35 40 45
Samples
Eye Diagram for NRZ, RZ and Raised Cosine Matlab Code
Main Program

% (binary_eye.m)
% this program uses the four different pulses to generate eye diagrams of
% binary polar signaling
clear all; close all; clc;
data=sign(randn(1,100)); % generate 400 random bits
Tau=64; % define the symbol period
for i=1:length(data)
dataup((i-1)*64+1:i*64)=[data(i),zeros(1,63)];% Generate impluse train
end
% dataup=upsample(date,Tau);% Generate impluse train
yrz=conv(dataup,prz(Tau));% Return to zero polar signal
yrz=yrz(1:end-Tau+1);
ynrz=conv(dataup,pnrz(Tau));% Non-return to zero polar
ynrz=ynrz(1:end-Tau+1);
Td=4; % truncating raised cosine to 4 periods
yrcos=conv(dataup,prcos(0.5,Td,Tau));% rolloff factor=0.5
yrcos=yrcos(2*Td*Tau:end-2*Td*Tau+1);% generating RC pulse train
eye1=eyediagram(yrz,2*Tau,Tau,Tau/2);title('RZ eye-diagram');
eye2=eyediagram(ynrz,2*Tau,Tau,Tau/2);title('NRZ eye-diagram');
eye4=eyediagram(yrcos,2*Tau,Tau);title('Raised-cosine eye-diagram');

Function files (Write each function file in separate


script file)

Function File 1
% (pnrz.m)
% generating a rectangular pulse of width T
% usage function pout=pnrz(T);
function pout=pnrz(T);
pout=ones(1,T);
end

Function File 2
% (prcos.m)
% Usage y=prcos(rollfac,length, T)
function y=prcos(rollfac,length, T)
% rollfac = 0 to 1 is the rolloff factor
% length is the onesided pulse length in the number of Trcos
% length = 2T+1
% T is the oversampling rate
y=rcosfir(rollfac, length, T, 1, 'normal');
end

Function File 3
% (prz.m)
% generating a rectangular pulse of wisth T/2
% usage function pout=prz(T);
function pout=prz(T);
pout=[zeros(1,T/4) ones(1,T/2) zeros(1,T/4)];
end

Output

RZ eye-diagram
1

0.8

0.6

0.4

0.2
Amplitude

-0.2

-0.4

-0.6

-0.8

-1
-30 -20 -10 0 10 20 30
Time
NRZ eye-diagram
1

0.8

0.6

0.4

0.2
Amplitude

-0.2

-0.4

-0.6

-0.8

-1
-30 -20 -10 0 10 20 30
Time
Raised-cosine eye-diagram
1.5

0.5
Amplitude

-0.5

-1

-1.5
-30 -20 -10 0 10 20 30
Time

Program 2 : PCM Generation and Demodulation


Matlab Code
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;

% % Signal Generation
% x=0:1/100:4*pi;
% y=8*sin(x); % Amplitude Of signal is 8v
% subplot(2,2,1);
% plot(x,y);grid on;
% Sampling Operation
x=0:2*pi/n1:4*pi; % n1 nuber of samples have tobe selected
s=8*sin(x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Sinal'); ylabel('Amplitude--->');
xlabel('Time--->');

% Quantization Process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax
with difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized valuses
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q
contain quantized values
l1=length(ind);
l2=length(q);

for i=1:l1
if(ind(i)~=0) % To make index as binary decimal
so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value
inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Encoding Process
figure
code=de2bi(ind,'left-msb'); % Cnvert the decimal to binary
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j); % convert code matrix to a coded row
vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stairs(coded); % Display the encoded signal
axis([0 100 -2 3]); title('Encoded Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Demodulation Of PCM signal

qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb'); % Getback the index in decimal
form
q=del*index+vmin+(del/2); % getback Quantized values
subplot(2,1,2); grid on;
plot(q); % Plot Demodulated signal
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

Output:
Enter n value for n-bit PCM system : 8
Enter number of samples in a period : 8
Program 3: Binary DPSK Modulation and Demodulation
Matlab Code
clc;
close all;
clear all;
M = 2; % Alphabet size
dataIn = randi([0 M-1],50,1); % Random message
txSig = dpskmod(dataIn,M); % Modulate
rxSig = txSig*exp(2i*pi*rand());
dataOut = dpskdemod(rxSig,M);
errs = symerr(dataIn,dataOut)
errs = symerr(dataIn(2:end),dataIn(2:end))
subplot(4,1,1);
stem(dataIn,'linewidth',3), grid on;
title(' Input data in DPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude');
subplot(4,1,2);
stem(txSig,'linewidth',3), grid on;
title(' Modulated data in DPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude');
subplot(4,1,3);
stem(rxSig,'linewidth',3), grid on;
title(' received data after channel in DPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude');
subplot(4,1,4);
stem(dataOut,'linewidth',3), grid on;
title(' Output data in DPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude');

Output Waveform

Input data in DPSK modulation


1
amplitude

0.5

0
0 5 10 15 20 25 30 35 40 45 50
time(sec)
-14
x 10 Modulated data in DPSK modulation
5
amplitude

-5
0 5 10 15 20 25 30 35 40 45 50
time(sec)
received data after channel in DPSK modulation
1
amplitude

-1
0 5 10 15 20 25 30 35 40 45 50
time(sec)
Output data in DPSK modulation
1
amplitude

0.5

0
0 5 10 15 20 25 30 35 40 45 50
time(sec)

Program 4: QPSK Modulation and Demodulation


Matlab Code

clc;
clear all;
close all;
data=[0 1 0 1 1 1 0 0 1 1]; % information
%Number_of_bit=1024;
%data=randint(Number_of_bit,1);
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting ');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for QPSK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
% QPSK modulation
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=y; % transmitting signal after modulation
tt=T/99:T/99:(T*length(data))/2;
figure(2)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title(' wave form for inphase component in QPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title(' wave form for Quadrature component in QPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('QPSK modulated signal (sum of inphase and Quadrature phase signal)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
% QPSK demodulation
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received & inphase carred signal

Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodial rull


if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end

%Quadrature coherent dector


Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived & Quadphase carred signal

Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodial rull


if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end

Rx_data=[Rx_data Rx_in_data Rx_qd_data]; % Received Data vector


end
figure(3)
stem(Rx_data,'linewidth',3)
title('Information after Receiveing ');
axis([ 0 11 0 1.5]), grid on;

Output
Information before Transmiting
1.5

0.5

0
0 1 2 3 4 5 6 7 8 9 10 11
wave form for inphase component in QPSK modulation

amplitude(volt0
1

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time(sec) -6
x 10
wave form for Quadrature component in QPSK modulation
amplitude(volt0

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time(sec) -6
x 10
QPSK modulated signal (sum of inphase and Quadrature phase signal)
amplitude(volt0

-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time(sec) -6
x 10

Information after Receiveing


1.5

0.5

0
0 1 2 3 4 5 6 7 8 9 10 11

You might also like