Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Digital Communication Systems Lab Software: Meghna Rattanpal 17BEC0580

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

DIGITAL COMMUNICATION

SYSTEMS LAB SOFTWARE


PROFESSOR: Dr RAJESH A

MEGHNA RATTANPAL
17BEC0580
BASIC SIGNALS TO BE GENERATED

I) IMPULSE FUNCTION

II) UNIT STEP

III) UNIT RAMP


Sampling

• Perform the under sampling, critical sampling and over sampling for a given input signal

clf;

T = 1;

fs=2000;

t = 0:1/fs:T;

f = 13;

xa = cos(2*pi*f*t);

subplot(2,1,1) plot(t,xa);grid

xlabel('Time, msec');

ylabel('Amplitude');

title('Continuous-time signal x_{a}(t)');

axis([0 1 -1.2 1.2])

subplot(2,1,2);

T = 0.1;

n = 0:T:1;

xs = cos(2*pi*f*n);

k = 0:length(n)-1;

stem(k,xs);
grid xlabel('Time index n');

ylabel('Amplitude');

title('Discrete-time signal x[n]');

axis([0 (length(n)-1) -1.2 1.2])

 Undersampling: T<1
 Oversampling: T>1

Quantization Logic

function y=uquant(x,n)
del=((max(max(x))-(min(min(x))))/(n-1);
r=(x-min(min(x)))/del;
r=round®;
y=r*del+min(min(x));
Quantisation code

clc,
clear all;
close all;
t=0:.001:1;
y=2*sin(2*pi*t)
figure(1)
subplot(311)
plot(y)
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Input Message Signal');
q1=uquant(y,4);
subplot(312)
plot(q1)
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Quantized Signal with L = 4');
q2=uquant(y,32);
subplot(313)
plot(q2)
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Quantized Signal with L = 32');
Ps=mean(y.^2);
Pq1=mean(q1.^2);
Pq2=mean(q2.^2);
SQR1=Ps/Pq1;
SQR2=Ps/Pq2;
OUTPUT

Line coding

Generate signal using RZ

clc;
close all;
clear all;
x=[1 0 1 1 0 1];
nx=size(x,2);
sign=1;
i=1;
while i<nx+1
t = i:0.001:i+1-0.001;
unipolar_code=square(t*2*pi,100);
polar_code=square(t*2*pi,100);
bipolar_code=sign*square(t*2*pi,100);
sign=sign*-1;
manchester_code=-square(t*2*pi,50);
else
unipolar_code=0;
polar_code=-square(t*2*pi,100);
bipolar_code=0;
manchester_code=square(t*2*pi,50);
end
subplot(4,1,1);
plot(t,unipolar_code);
ylabel('unipolar code');
hold on;
grid on;
axis([1 10 -2 2]);
subplot(4,1,2);
plot(t,polar_code);
ylabel('polar code');
hold on;
grid on;
axis([1 10 -2 2]);
subplot(4,1,3);
plot(t,bipolar_code);
ylabel('bipolar code');
hold on;
grid on;
axis([1 10 -2 2]);
subplot(4,1,4);
plot(t,manchester_code);
ylabel('manchester code');
hold on;
grid on;
axis([1 10 -2 2]);
i=i+1;
ASK:

clc
clear all
close all
b=input('Enter input binary function: ');
for i=1:length(b)
if b(i)==1
a(i)=1;
else
a(i)=0;
end
end
t=0:0.01:length(a);
i=1;
for j=1:length(t)
if t(j)<=i
y(j)=a(i);
else
i=i+1;
end
end
subplot(4,1,1);plot(t,y);title('Message Signal');
fc=input('Enter carrier frequency: ');
c=2*cos(2*pi*fc*t);
x=y.*c;
subplot(4,1,2);plot(t,c,'g');title('Carrier Signal');
subplot(4,1,3);plot(t,x,'r');title('ASK Modulation Signal');
for j=1:length(x)
if x(j)==y(j)
d(j)=0;
else
d(j)=1;
end
end
subplot(4,1,4);plot(t,d);title('ASK Demodulated Signal');

FSK:

clc;
clear all;
close all;
%carrier frequency and amplitude
f1=8;f2=2;a=1;
%6 bit are used
%THE BIT SEQUENCE IS 1,0,1,1,0,0
n=[1,0,1,1,0,0];
l=length(n);
if n(l)==1
n(l+1)=1
else
n(l+1)=0
end
l1=length(n)
tn=0:l1-1;
%plot message signal
subplot(5,1,1);
stairs(tn,n);
title('Message Signal');
xlabel('Time');
ylabel('Amplitude');
%plot carrier signal
t=0:0.01:6;
y1=a*sin(2*pi*f1*t);
y2=a*sin(2*pi*f2*t);
subplot(5,1,2);
plot(t,y1);
title('Carrier Signal 1');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,3);
plot(t,y2);
title('Carrier Signal 2');
xlabel('Time');
ylabel('Amplitude');

%modulation process
for i=1:6
for j=(i-1)*100:i*100
if(n(i)==1)
s(j+1)=y1(j+1);
else
s(j+1)=y2(j+1);
end
end
end
%plot FSK modulated signal
subplot(5,1,4);
plot(t,s);
title('FSK Modulated Signal');
xlabel('Time');
ylabel('Amplitude');
%demodulation process
for i=1:6
for j=(i-1)*100:i*100
if(s(j+1)==y1(j+1))
x(j+1)=1;
else
x(j+1)=0;
end
end
end
%plot demod signal
subplot(5,1,5);
plot(t,x);
title('FSK Demodulated Signal');
xlabel('Time');
ylabel('Amplitude');
PSK:

clc;
clear all;
close all;
%carrier frequency and amplitude
f1=8;a=1;
%6 bit are used
%THE BIT SEQUENCE IS 1,0,1,1,0,0
n=[1,0,1,0,0,1];
l=length(n);
if n(l)==1
n(l+1)=1
else
n(l+1)=0
end
l1=length(n)
tn=0:l1-1;
%plot message signal
subplot(5,1,1);
stairs(tn,n);
title('Message Signal');
xlabel('Time');
ylabel('Amplitude');
%plot carrier signal
t=0:0.01:6;
y1=a*sin(2*pi*f1*t);
y2=-a*sin(2*pi*f1*t);
subplot(5,1,2);
plot(t,y1);
title('Carrier Signal 1');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,3);
plot(t,y2);
title('Carrier Signal 2');
xlabel('Time');
ylabel('Amplitude');

%modulation process
for i=1:6
for j=(i-1)*100:i*100
if(n(i)==1)
s(j+1)=y1(j+1);
else
s(j+1)=y2(j+1);
end
end
end
%plot PSK modulated signal
subplot(5,1,4);
plot(t,s);
title('PSK Modulated Signal');
xlabel('Time');
ylabel('Amplitude');
%demodulation process
for i=1:6
for j=(i-1)*100:i*100
if(s(j+1)==y1(j+1))
x(j+1)=1;
else
x(j+1)=0;
end
end
end
%plot demod signal
subplot(5,1,5);
plot(t,x);
title('PSK Demodulated Signal');
xlabel('Time');
ylabel('Amplitude');
QPSK

clc;
clear all;
close all;
cvx=input('Enter Length of Random Bit Sequence:');
d=round(rand(1,cvx))
l=cvx;
x=0:0.01:l*2*pi;
cc=cos(x);
cs=cos(x+pi/2);
k=length(cc);
k1=k/l;

for i=1:l
if(d(i)==0)
d(i)=-1;
i=i+1;
end
end

i=1;
j=1;% To segrigate odd bit streams and even bit streams
while (i<l) && (j<l) %half strem with double symbol duration
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 cycle equivalent to sinusoidal waveformt=1;
for i=1:l
for j=1:k1 %k1 sample with 1 sine period
dd(t)=d(i);
d1(t)=dd1(i);
d2(t)=dd2(i);
t=t+1;
j=j+1;
end
i=i+1;
end

subplot(6,1,1);
stairs(dd);
axis([0 t -2 2]);
title('Imput Bit Stream');
subplot(6,1,2);
stairs(d1);
axis([0 t -2 2]);
title('Odd Bit Stream');
subplot(6,1,3);
stairs(d2);
axis([0 t -2 2]);
title('Even Bit Stream');

len=length(d1);
if(k<len)
len=k;
end

for i=1:len
qcc(i)=cc(i)*d1(i);% odd streams multiplied with I waveform
qcs(i)=cs(i)*d2(i);% even streams multiplied with Q waveform
i=i+1;
end

subplot(6,1,4);
plot(qcc);
axis([0 len -2 2]);
title('Modulated Wave of I-Component');
subplot(6,1,5);
plot(qcs);
axis([0 len -2 2]);
title('Modulated Wave of Q-Component');

qp=qcc+qcs; % QPSK output from Adder


subplot(6,1,6);
plot(qp);
axis([0 len -2 2]);
title('QPSK WAVEFORM');
figure, scatter(dd1,dd2,40,'*r');
title('Constellation Diagram of QPSK');

PROBABILITY OF ERROR FOR ASK, FSK, PSK, & QPSK

CODE:

ebno=0:1:9
ecno=10.^(ebno/10)
eask=0.5*erfc(sqrt(ecno/4))
epsk=0.5*erfc(sqrt(ecno))
efsk=0.5*erfc(sqrt(ecno/2))
semilogy(ecno,eask)
title('ASK')
hold on
semilogy(ecno,epsk)
title('PSK')
hold on
semilogy(ecno,efsk)
title('FSK')
hold on
xlabel('eb/no in db')
ylabel('RC')
title('Perf analysis of bandpass Mod Scheme')
legend('ASK','PSK','FSK');
hold off
PN SEQUENCE GENERATION

PN SEQUENCE:-

Code:-

len=input('Enter the length of the sequence');


disp('enter the generation polynomial');
poly=input('enter the generation poly:');
ini=input('enter the initial state');
ff=log2(len+1);
a=zeros(len,ff);
a(1,1:ff)=ini;
for i=1:(len-1)
x=0;
for j=2:(ff+1)
if(poly(1,j)==1)
x=xor(x,a(i,j-1));
end
end
a(i+1,1:ff)=circshift(a(i,1:ff),[0 1]);
a(i+1,1)=x;
end
for i=1:len
h(1,i)=a(i,ff);
end
disp(h);

output:-
Enter the length of the sequence15

enter the generation polynomial

enter the generation poly:[1 0 0 1 1]

enter the initial state[1 0 0 0]

0 0 0 1 0 0 1 1 0 1 0 1 1 1 1

%balance property
noo=(sum(h==1))
noz=(sum(h==0))
if noo==noz+1
disp('balance prp is satisfied');
end

output:

noo =

noz =

balance prp is satisfied

%auto correlation prp


for i=1:len
y(i,:)=xor(h,circshift(h,[0 i]));
end

for i=1:len
one=0;
zero=0;
for j=1:len
if ((y(i,j))==0)
zero=zero+1;
else
one=one+1;
end
end
z(i,1)=(zero-one);
end
for i=1:(len-1)
g(i,1)=-1;
end
g(len,1)=len;
disp(z);
if(z==g)
sprintf('\n');
fprintf('autocorrelation prp is satisfied');
flag3=3;
else
fprintf('auto correlation prp is not satisfied ');
flag3=0;
end

output:-

-1

-1

-1

-1

-1

-1

-1

-1

-1

-1

-1

-1

-1

-1

15

autocorrelation prp is satisfied


%run prp
s=h(1);
run=1;
oness=0;
for i=2:(len)
if s~=h(i)
run=run+1;
if ((h(i-2))~=(h(i)))
oness=oness+1;
end
end
s=h(i);
end
if ((oness/run)==0.5)
disp('run prp satisfied');
else
disp('not satisfied');
end

output:-

run prp satisfied

output snaps:-

You might also like