Simulation Experiments-Com Lab
Simulation Experiments-Com Lab
1. Write a Matlab code to simulate NRZ, RZ, half-sinusoid and raised cosine pulses
and generate eye diagram for binary polar signaling.
RZ polar signal:
N=100;
x=2*round(rand(N,1))-1;
x1 = x';
a = -5.5:1/100:1.5;
b = -3.5:1/100:3.5;
c = -1.5:1/100:5.5;
for i = 1:1:(N+2-11);
d = x1(1,i)*sinc(b);
e = x1(1,i+1)*sinc(b);f
= x1(1,i+2)*sinc(b);
hold on, plot(a,f); hold
on, plot(b,e); hold on,
plot(c,d); end
clc; close
all;clear
all;
t=linspace(0,pi,100);
y=sin(t);
plot(t,y);
h = scatterplot(sqrt(sps)*txSig(sps*span+1:end-sps*span),sps,offset,'g.');hold on
scatterplot(rxSigFilt(span+1:end-span),n,offset,'kx',h) scatterplot(dataMod,n,offset,'r*',h)
legend('Transmit Signal','Received Signal','Ideal','location','best')
eyediagram(txSig(sps*span+1:sps*span+1000),2*sps)
eyediagram(rxSig(sps*span+1:sps*span+1000),2*sps)
Expected waveforms:
Eye pattern:
2. Write a Matlab code to simulate the Pulse code modulation and demodulation system and
display the waveforms.
% 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); % Contain 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
BNMIT/T Feb – July 2021 6
B.N.M.I.T Dept. of ECE Communication Lab – 18ECL67
if(q(i)==vmin-(del/2))% To make quantize value in between 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--->');
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--->');
PCM waveforms:
3. Write a program to Compute of the Probability of bit error for coherent binary ASK, FSK and PSK for
an AWGN Channel and Compare them with their Performance curves.
clc;
clear all;
close all;
EbN0dB=0:20;
EbN0=10.^(EbN0dB/10);
pe_bpsk=0.5*erfc(sqrt(EbN0));
pe_bfsk=0.5*erfc(sqrt(EbN0/2));
pe_bask=0.5*erfc(sqrt(EbN0/4));
semilogy(EbN0dB,pe_bpsk,'r*-', EbN0dB,pe_bfsk,'k+ ',EbN0dB,pe_bask,'m>-');
legend('BPSK-C', 'BFSK-C', 'BASK-C');
xlabel('Eb/N0(dB)');
ylabel('BER');
grid on
Simulation Results:
QPSK
% QPSK Modulation
clc;
clear all;
close all;
%GENERATE QUADRATURE CARRIER SIGNAL
Tb=1;t=0:(Tb/100):Tb;fc=1;
c1=sqrt(2/Tb)*cos(2*pi*fc*t);
c2=sqrt(2/Tb)*sin(2*pi*fc*t);
%generate message signal
N=8;m=rand(1,N);
t1=0;t2=Tb
for i=1:2:(N-1)
t=[t1:(Tb/100):t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=-1*ones(1,length(t));
end
% QPSK Demodulation
t1=0;t2=Tb
for i=1:N-1
t=[t1:(Tb/100):t2]
%correlator
x1=sum(c1.*qpsk(i,:));
x2=sum(c2.*qpsk(i,:));
%decision device
if (x1>0&&x2>0)
demod(i)=1;
demod(i+1)=1;
elseif (x1>0&&x2<0)
demod(i)=1;
demod(i+1)=0;
elseif (x1<0&&x2<0)
demod(i)=0;
demod(i+1)=0;
elseif (x1<0&&x2>0)
demod(i)=0;
demod(i+1)=1;
end
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
subplot(3,2,5);stem(demod);
title('qpsk demodulated bits');xlabel('n ---- >');ylabel('b(n)');grid on;
Simulation results:
clc;
clear all;
close all;
n=100;
x=[ones(1,20) zeros(1,20) ones(1,20) zeros(1,20) ones(1,20)];
subplot(4,1,1);
plot(x);
title('input signal');
xlabel('number of samples');
ylabel('amplitude');
f=1*10^6;
fs=10*10^6;
for i=0:n-1
d(i+1)=sin(2*pi*(f/fs)*i);
end
subplot(4,1,2);
plot(d);
title('carrier signal');
xlabel('number of samples');
ylabel('amplitude');
for i=0:n-1
if(x(i+1)==0)
x(i+1)=sin(2*pi*(f/fs)*i);
else
x(i+1)=sin(2*pi*(f/fs)*i+pi);
end
end
subplot(4,1,3);
plot(x);
title('PSK Signal');
xlabel('number of samples');
ylabel('amplitude');
for i=0:n-1
if(x(i+1)==sin(2*pi*(f/fs)*i))
x(i+1)=0;
else
x(i+1)=1;
end
end
subplot(4,1,4);
plot(x);
title('demodulated Signal');
xlabel('number of samples');
ylabel('amplitude');
DPSK waveforms: