100% found this document useful (1 vote)
156 views15 pages

Advanced Communication Lab (15ECL76)

The document summarizes simulations of digital communication techniques: 1) NRZ, RZ, half-sinusoid and raised cosine pulses are simulated and eye diagrams are generated for binary polar signaling. 2) A pulse code modulation and demodulation system is simulated. The waveforms are displayed. 3) A QPSK transmitter and receiver are simulated. The signals and constellation diagram are plotted.

Uploaded by

kimberly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
156 views15 pages

Advanced Communication Lab (15ECL76)

The document summarizes simulations of digital communication techniques: 1) NRZ, RZ, half-sinusoid and raised cosine pulses are simulated and eye diagrams are generated for binary polar signaling. 2) A pulse code modulation and demodulation system is simulated. The waveforms are displayed. 3) A QPSK transmitter and receiver are simulated. The signals and constellation diagram are plotted.

Uploaded by

kimberly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Advanced Communication Lab

(15ECL76)

1. Simulate NRZ, RZ, half-sinusoid and raised cosine pulses and generate
eye diagram for binary polar signalling.

a. Polar NRZ (Non-Return to Zero)


Code:
clc;
clear all;
close all;
h=input('Enter bit sequence:');
n=1;
l=length(h);
h(l+1)=1;
while (n<=length(h)-1)
t=n-1:0.001:n;
if (h(n)==0)
if(h(n+1)==0)
y=-(t<n)-(t==n);
else
y=-(t<n)+(t==n);

end
disp('zero');

else
if(h(n+1)==0)
y=(t<n)-1*(t==n);

else
y=(t<n)+1*(t==n);
end
disp('one');
end
d=plot(t,y);
grid on;
title('Line Code Polar NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
n=n+1;
end
Command Window:

Enter bit sequence:[1 0 1 0 0 1 1 0 1 0]

one

zero

one

zero

zero

one

one

zero

one

zero

Output:
b. Polar RZ (Return to Zero)

Code:
clc;
clear all;
close all;
h=input('Enter bit sequence:');
n=1;
l=length(h);
h(l+1)=1;
while (n<=length(h)-1)
t=n-1:0.001:n;
if (h(n)==0)
if(h(n+1)==0)
y=-(t<n-0.5)-(t==n);
else
y=-(t<n-0.5)+(t==n);

end
disp('zero');

else
if(h(n+1)==0)
y=(t<n-0.5)-1*(t==n);

else
y=(t<n-0.5)+1*(t==n);
end
disp('one');
end
d=plot(t,y);
grid on;
title('Line Code Polar RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
n=n+1;
end

Command Window:

Enter bit sequence:[1 0 1 0 0 1 1 0 1 0]

one

zero

one

zero

zero

one

one

zero

one

zero
Output:

c. Half-Sinusoid

Code:
t = 0:0.2:2;
f=.5; %Input Signal Frequency
x=sin(2*pi*f*t); %Generate Sine Wave
x(x<0) = 0; %Rectified Positive Half Sine Wave
figure(1);
subplot(2,1,1);
plot(t,x);
title('Rectified Positive Half');
ylabel('Amplitude');
xlabel('Time');
axis([xlim -1 1]);
x=sin(2*pi*f*t);
x(x>0) = 0; %Rectified Negative Half Sine Wave
subplot(2,1,2);
plot(t,x);
title('Rectified Negative Half');
ylabel('Amplitude');
xlabel('Time');
axis([xlim -1 1]);

Output:
d. Eye Diagram

Code:
%Function prz
function pout = prz(T)
pout= [zeros(1,T/4) ones(1,T/2) zeros(1,T/4)];
end

%Function prcos
function y = prcos(rollfac,length,T)
y=rcosfir(rollfac,length,T,1,'normal');
end

%Function psine
function pout = psine(T)
pout=sin(pi*(0:T-1)/T);
end

%Function pnrz
function pout=pnrz(T)
pout = ones(1,T);
end

%Eye Diagram Code


clc;
clear all;
close all;
data=sign(randn(1,400));
T=64;
for (i=1:length(data))
daTp((i-1)*64+1:i*64)=[data(i) zeros(1,63)];
end
yrz=conv(daTp,prz(T));
yrz=yrz(1:end-T+1);
ynrz=conv(daTp,pnrz(T));
ynrz=ynrz(1:end-T+1);
ysine=conv(daTp,psine(T));
ysine=ysine(1:end-T+1);
Td=4;
yrcos=conv(daTp,prcos(0.5,Td,T));
yrcos=yrcos(2*Td*T:end-2*Td*T+1);
eye1=eyediagram(yrz,2*T,T,T/2);
title('RZ Eye-Diagram');
eye2=eyediagram(ynrz,2*T,T,T/2);
title('NRZ Eye-Diagram');
eye3=eyediagram(ysine,2*T,T,T/2);
title('Half-Sine Eye-Diagram');
eye4=eyediagram(yrcos,2*T,T);
title('Raised-Cosine Eye-Diagram');
Output:
2. Simulate the Pulse code modulation and demodulation system and
display the waveforms.

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 Signal');
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); % Contains Quantized values
[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'); % Convert 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');

Command Window:

Enter n value for n-bit PCM system : 4


Enter number of samples in a period : 8

Output:
3. Simulate the QPSK transmitter and receiver. Plot the signals and its
constellation diagram.
Code:

clc;
clear all;
close all;
d=input('Enter input bit streams: ');
ln = length(d);
x= 0:1/100:ln*2*pi;
cc=cos(x);
cs=sin(x);
k=length(cc);
k1=k/ln;
%input data odd/even test
if (mod(ln,2)~=0)
d(ln+1)=0;
ln=ln+1;
end
for i=1:ln
if(d(i)==0)
d(i)=-1;
i=i+1;
end
end
% To make odd and even bit streams
i=1; j=1;
while((i<ln)&&(j<ln))
dd1(j) = d(i);
dd1(j+1) = d(i);
dd2(j) = d(i+1);
dd2(j+1) = d(i+1);
j=j+2;
i=i+2;
end
% To make bit streams eqv to sin waveform
t=1;
for i=1:ln
for j=1:k1
dd(t)=d(i);
d1(t)=dd1(i);
d2(t)=dd2(i);
t=t+1;
j=j+1;
end
i=i+1;
end
subplot(3,1,1)
stairs(dd);
axis([0 t -2 2]);
title('Input Bit Streams');
ylabel('Amplitude');
xlabel('Time');
subplot(3,1,2);
stairs(d1);
axis([0 t -2 2]);
title('Odd Bit streams with twice clock period');
ylabel('Amplitude');
xlabel('Time');
subplot(3,1,3);
stairs(d2);
axis([0 t -2 2]);
title('Even Bit streams with twice clock period');
ylabel('Amplitude');
xlabel('Time');
figure;
subplot(2,1,1);
plot(cc);
axis([0 k -2 2]);
title('Cosine Waveforms');
ylabel('Amplitude');
xlabel('Time');
subplot(2,1,2);
plot(cs);
axis([0 k -2 2]);
title('Sine Waveforms');
ylabel('Amplitude');
xlabel('Time');
len=length(d1);
if(k<len)
len=k;
end
%odd streams multiplied with cosine waveform
%even streams multiplied with cosine waveform
for (i=1:len)
qcc(i)=cc(i)*d1(i);
qcs(i)=cs(i)*d2(i);
i=i+1;
end
figure
subplot(3,1,1);
plot(qcc);
axis([0 len -2 2]);
title('Cosine multiplied with odd bit stream waveform');
ylabel('Amplitude');
xlabel('Time');
subplot(3,1,2);
plot(qcs);
axis([0 len -2 2]);
title('Sine multiplied with odd bit stream waveform');
ylabel('Amplitude');
xlabel('Time');
%QPSK output from summer
qp=qcc+qcs;
subplot(3,1,3);
plot(qp);
axis([0 len -2 2]);
title('QPSK Waveform');
ylabel('Amplitude');
xlabel('Time');

Command Window:

Enter input bit streams: [1 0 1 0 0 1 1 0 1 0]


Output:

Code:

clc;
clear all;
close all;
num_symbols = 10;
a=1;
b=4;
int_symbols = a+(b-a)*rand(1,num_symbols);
int_symbols = round(int_symbols);
A = 1/sqrt(2);
qpsk_symbols = zeros(size(int_symbols));
qpsk_symbols(int_symbols==1)=A+1i*A;
qpsk_symbols(int_symbols==2)=A-1i*A;
qpsk_symbols(int_symbols==3)=-A+1i*A;
qpsk_symbols(int_symbols==4)=-A-1i*A;
plot(real(qpsk_symbols),imag(qpsk_symbols),'ored','linewidth',3);
xlim([-2 2]);
ylim([-2 2]);
hold on;
ezplot('x^2+y^2=1');
grid on;
title('QPSK constellation without noise');
xlabel('Real part');
ylabel('Imaginary part');
data =[0 0 1 1 0 1 1 1 0 0 1 1]; % information
figure(1);
stem(data,'linewidth',3);
grid on;
title('Information before transmitting');
axis([-2 13 -1.5 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
y=[];
y_in=[];
y_qd=[];
d=zeros(1,length(data)/2);
for (i=1:length(data)/2)
p=data(2*i);
imp=data(2*i - 1);
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
%qpsk=d;
tt=T/99:T/99:(T*length(data))/2;
figure(2)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title('Waveform for inphase component in QPSK modulation ');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title('Waveform for Quadrature component in QPSK modulation ');
xlabel('Time');
ylabel('Amplitude');
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');
ylabel('Amplitude');
Rx_data=[];
Rx_sig=Tx_sig;
for (i=1:length(data)/2)
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
Z_in_intg=(trapz(t,Z_in))*(2/T);
if(Z_in_intg>0)
Rx_in_data=1;
else
Rx_in_data=0;
end
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
Z_qd_intg=(trapz(t,Z_qd))*(2/T);
if (Z_qd_intg>0)
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_data Rx_in_data Rx_qd_data];
end
figure(3);
stem(Rx_data,'linewidth',3);
title('Information after Receiveing ');
axis([0 13 -0.5 1.5]);
grid on;
Output:
4. Test the performance of a binary differential phase shift keying system
by simulating the non-coherent detection of binary DPSK.

Code:
clc;
clear all;
close all;
%Input Fields
N = 1e6; % number of bits or symbols
EbN0dB = 6:2:16; % multiple Eb/N0 values
M=2;
figure(1);
refArray = [1.0000+0.0000i 0.0000+1.0000i -1.0000+0.0000i -0.0000-1.0000i]; %
Constellation 2-DPSK
symErrSimulated = zeros(1,length(EbN0dB));
k=log2(M); % number of bits per symbol
EsN0dB = EbN0dB + 10*log10(k);
%—Generating a uniformly distributed random numbers in the set [0,1,2,..,2M-1]
data = 2*ceil(M.*rand(N,1))-1;
%—generating differential modulated symbols
% phi[k] = phi[k-1] + Dphi[k]
data_diff = filter(1,[1 -1],data); % start with 0 phase
s = refArray(mod(data_diff,2*M)+1);
%—Place holder for Symbol Error values for each Es/N0 for particular M value–
index =1;
for (x = EsN0dB)
%Channel Noise for various Es/N0
%Adding noise with variance according to the required Es/N0
noiseVariance = 1/(10.^(x/10));%Standard deviation for AWGN Noise
noiseSigma = sqrt(noiseVariance/2);
%Creating a complex noise for adding with M-PSK modulated signal
%Noise is complex since M-PSK is in complex representation
noise = noiseSigma*(randn(1,N)+1i*randn(1,N));
received = s + noise; % additive white gaussian noise
% I-Q Branching
% non-coherent demodulation
estPhase = angle(received);
% Dphi[k] = phi[k] – phi[k-1]
est_diffPhase = filter([1 -1],1,estPhase)*M/pi;
% Decision Maker-Compute
y = mod(2*floor(est_diffPhase/2)+1,2*M); % quantizing
% Symbol Error Rate Calculation
symErrSimulated(1,index) = sum(y~=data')/(N*k);
index=index+1;
end
EbN0lin = 10.^(EbN0dB/10);
symErrTheory = 0.5*exp(-EbN0lin);
semilogy(EbN0dB,symErrSimulated,'LineWidth',1.5);
hold on;
xlabel('Eb/N0(dB)');
ylabel('Bit Error Rate (Pb)');
title('Simulation BER for DPSK Modulation');
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy