Professional Documents
Culture Documents
All DC Expriment
All DC Expriment
All DC Expriment
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
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
Output
Enter the number of code bits=6
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
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
OUTPUT
Enter the amplitude (For Both Carrier & Binary Pulse Message):4