ADC Part B Programs
ADC Part B Programs
ADC Part B 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) ']']);
Output
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) ']']);
Output:
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 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
% % 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--->');
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
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)
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
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
0.5
0
0 1 2 3 4 5 6 7 8 9 10 11