All DC Expriment

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

1.

BPSK
clc;
close all;
clear all;
t = 0:.001:1;
fc= input('Enter frequency of Carrier Sine wave :');
fm= input('Enter message frequnecy:' );
amp=input('Enter carrier and message amplitude(assuming both equal):');
c=amp.*sin(2*pi*fm*t);
subplot(3,1,1)
plot(t,c)
xlabel('time')
ylabel('amplitude')
title('carrier')
m=square(2*pi*fm*t)
subplot(3,1,2)
plot(t,m)
xlabel('time')
ylabel('amplitude')
title('message signal')
x=c.*m;
subplot(3,1,3)
plot(t,x)
xlabel('t')
ylabel('y')
title('psk')

2.QAM, MPSK

clc;
close all;
N=input('Enter number of bits to be grouped:');
M=2^N;
x= [0:M-1];
k=1;
OFF=0;
z=pskmod(x,M);
scatterplot(z,k,OFF,'r+');
title('M-ary PSk')
y=qammod (x,M);
scatterplot(y,k,OFF,'b*');
title('MPSK')
3,Entropy
clc;
clear all;
close all;
i=input('Enter no. of elements=');
q=input('Enter joint probabilities matrix=');
sum=0;
%probability P(x)
for n=1:i
w=0;
for m=1:i
p(n)=w+q(n,m)
w=p(n);
end
end
disp('P(x):');
disp(p);
% entropy H(x)
for n=1:i
H=sum+(p(n)*log2(1/p(n)));
sum=H;
end
disp('H(x): ');
disp(H);
%conditional probability matrix
for n=1:i
for m=1:i
a(n,m)=q(n,m)/p(n);
end
end
disp('P(Y/X):');
disp(a);
% entropy H(Y/X)
d=0;
for n=1:i
for m=1:i
if(a(n,m)>0)
H1=d+(q(n,m)*log2(1/a(n,m)));
d=H1
end
end
end
disp('H(Y/X):');
disp(H1);
% MI
m=H-H1;
disp('MI=');-
disp(m);
% probability P(Y)
for n=1:i
w=0;
for m=1:i
s(n)=w+q(m,n);
w=s(n);
end
end
disp('P(Y):');
disp(s);
% entropy H(Y)
k=0;
for n=1:i
H2=k+(s(n)*log2(1/s(n)));
k=H2;
end
disp('H(Y): ');
disp(H2);

Output
Enter no. of elements=3

Enter joint probabilities matrix=[1 0 1;0 1 0;1 1 0]

p= 1
p= 1
p= 2
p= 2 0
p= 2 1
p= 2 1
p= 2 1 1
p= 2 1 2
p= 2 1 2
P(x): 2 1 2

H(x):
-4

P(Y/X):
0.5000 0 0.5000
0 1.0000 0
0.5000 0.5000 0

d= 1
d= 2
d= 2
d= 3
d= 4
H(Y/X):
4
MI=
-8

P(Y):
2 2 1

H(Y):
-4

4.% LBC CODING:1


clc;
close all;
clear all;
n=input('Enter the number of code bits=');
k=input('Enter the number of message bits=');
p=input('Enter the parity matrix=');
i=eye(k);
g=cat(2,i,p);
m=0:2^k-1;
d=dec2bin(m,k);
c=d*g;
codeword=rem(c,2);0
display(codeword);

Output
Enter the number of code bits=6

Enter the number of message bits=3


Enter the parity matrix=[1 0 1;1 1 1;0 1 1]

ans = 0

codeword =

0 0 0 0 0 0

0 0 1 0 1 1

0 1 0 1 1 1

0 1 1 1 0 0

1 0 0 1 0 1

1 0 1 1 1 0

1 1 0 0 1 0

1 1 1 0 0 1

5. % LBC DECODING:2
clc;
clear all;
close all;
n=input('Enter the number of code bits=');
k=input('Enter the number of message bits=');
p=input('Enter parity matrix=');
r=input('Received bit=');
b= eye(n-k);
ht = cat(1,p,b);
s= r*ht;
sy=rem(s,2);
if sy==0
display('no error');
else
display('error');
end
if sy==0
display('no need of correction');
else
e=eye(n);
for i=1:n
if sy==ht(i,:);
break
end
end
display (i);
display('Bit is in Error');
corrected=xor(r,e(i,:))
end

Output:
Enter the number of code bits=6

Enter the number of message bits=3

Enter parity matrix=[1 1 1;0 1 0;1 0 0]

Received bit=6

no error

no need of correction

6.**HUFFMAN CODING
|clear all;
close all;
symbol =[1:5];
P = (0.4 0.2 0.2 0.10.1];
|[dict, avglen] =huffmandict (symbol, p)
samplecode= dict {5, 2}
samplecode= dict{5, 2}
dict{1, :}
dict{2,:}
dict(3, :}
dict {4, :}
dict {5, :}
hcode = huffmanenco (symbol, dict) ;
dhsig = huffmandeco (hcode, dict) ;
disp("encoded msg: );
disp (hcode) ;
disp ('decoded msg:'):
disp (dhsig) ;
code_length=length (hcode)
sum=0
for m=1:5
H=sum+ (p (m) *log2 (1/p (m) ));
end
disp ('H=’);
disp (H) ;
Efficiency= (H/avglen) *100

7,Simulation of BFSK

clc %for clearing the command window


close all %for closing all the window except command window
clear all %for deleting all the variables from the memory
fc1=input('Enter the freq of 1st Sine Wave carrier:');
fc2=input('Enter the freq of 2nd Sine Wave carrier:');
fp=input('Enter the freq of Periodic Binary pulse (Message):');
amp=input('Enter the amplitude (For Both Carrier & Binary Pulse
Message):');
amp=amp/2;
t=0:0.001:1; % For setting the sampling interval
c1=amp.*sin(2*pi*fc1*t);% For Generating 1st Carrier Sine wave
c2=amp.*sin(2*pi*fc2*t);% For Generating 2nd Carrier Sine wave
subplot(4,1,1); %For Plotting The Carrier wave
plot(t,c1)
xlabel('Time')
ylabel('Amplitude')
title('Carrier 1 Wave')
subplot(4,1,2) %For Plotting The Carrier wave
plot(t,c2)
xlabel('Time')
ylabel('Amplitude')
title('Carrier 2 Wave')
m=amp.*square(2*pi*fp*t)+amp;%For Generating Square wave message
subplot(4,1,3) %For Plotting The Square Binary Pulse (Message)
plot(t,m)
xlabel('Time')
ylabel('Amplitude')
title('Binary Message Pulses')
for i=0:1000 %here we are generating the modulated wave
if m(i+1)==0
mm(i+1)=c2(i+1);
else
mm(i+1)=c1(i+1);
end
end
subplot(4,1,4) %For Plotting The Modulated wave
plot(t,mm)
xlabel('Time')
ylabel('Amplitude')
title('Modulated Wave')

OUTPUT

Enter the freq of 1st Sine Wave carrier:10

Enter the freq of 2nd Sine Wave carrier:30

Enter the freq of Periodic Binary pulse (Message):5

Enter the amplitude (For Both Carrier & Binary Pulse Message):4

You might also like