You are on page 1of 9

I HC NNG

TRNG I HC BCH KHOA


KHOA IN T VIN THNG
---o0o---




BO CO TH NGHIM
THNG TIN S V TRUYN
S LIU




Sinh Vin Thc Hin : Phan Quc Thng
Lp 08DT3
Nhm : 15A




Nng 2011
LAB1:

G = [1 1 0 1 0 0 0
1 1 1 0 1 0 0
1 1 1 0 0 1 0
1 0 1 0 0 0 1];

m = round(rand(1,4));
x = mod(m*G,2);
e =round(rand(1,7));
y = mod(x+e,2);
%matrix checksum
H = [1 0 0 1 0 1 1
0 1 0 1 1 1 0
0 0 1 0 1 1 1];

%matrix inverter
HT=H';

%syndrom
S = mod(y*HT,2);

%vector eror
E = [0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 0 1 0 0 0
0 0 0 0 0 1 0];
a = bin2dec(int2str(S);
for i=1:7
if(dec2bin(int2str(mod(E(i,:)*HT,2)))==dec2bin(int2str(s)))
sign_deco=mod(E(i,:)+sign,2);
end
end
end

Sau khi m ha v gii m th vn cn bt li v s li pht hin c
lun lun ln hn s li sa c.Cho nn d gii m nhng vn cn bt
li



LAB2:

%phat 10000 bit
for i = 1:length(data)
SRC_Uncoded(i)= sign(randn)>=1;
end
% Display the first 20 bits of SRC_Uncoded
fprintf('SRC_Uncoded:'); fprintf('\n');
for i=1:4:20
fprintf('%d ',SRC_Uncoded(i:i+3));
fprintf('\n');
end

%Tao tin hieu ma hoa SRC_Coded tu SRC_Uncoded
SRC_Coded = zeros(1, 7/4*length(SRC_Uncoded));
j = 1;
for k = 1:4:length(SRC_Uncoded)
SRC_Coded(j:j+6)= mod(SRC_Uncoded(k:k+3)*G,2);
j=j+7;
end
% Display SRC_Coded
fprintf('SRC_Coded:'); fprintf('\n');
for i=1:7:35
fprintf('%d ',SRC_Coded(i:i+6));
fprintf('\n');
end
Modulation
%qua trinh chuyen tin hieu tu so sang tuong tu (D/A).
%Tao tin hieu TX_Codec
for i = 1:length(SRC_Coded)
if SRC_Coded(i)==1
TX_Coded(i) = A;
else TX_Coded(i) = -A;
end
end
% Display TX_Coded
fprintf('TX_Coded: \n')
for i=1:7:35
printf('%d ',TX_Coded(i:i+6));
fprintf('\n');
end

Noise
%Tao chuoi nhieu noise ngau nhien co chieu dai bang chieu dai
cua TX_Uncoded
noise = randn(1,length(TX_Uncoded));
%20 gia tri nhieu au tien cua noise
noise = randn(1,length(TX_Coded));
RX_Coded = TX_Coded + noise;
%20 gia tri au tien cua nhieu moi:
fprintf('New_noise: \n')
for i=1:4:20
fprintf('%f ',noise(i:i+3));
fprintf('\n');
End
Demodulation
%Tao tin hieu DEST_Coded tu RX_Coded
for i = 1:length(RX_Coded)
if RX_Coded(i)>0
DEST_Coded(i)=1;
else DEST_Coded(i)=0;
end
end
%20 bits au tien cua DEST_Coded:
fprintf('\n DEST_Coded: \n')
for i=1:4:20
fprintf('%d ',DEST_Coded(i:i+3));
fprintf('\n');
end
Decoding
To DEST_Decoded:
Code: DEST_Decoded = zeros(1,length(SRC_Uncoded));
j = 1;
for k = 1:7:length(DEST_Coded)
syndrome = mod(DEST_Coded(k:k+6)*HT,2);
synd_int = bin2dec(int2str(syndrome));
e = E(synd_int+1,:);
corrected_y = mod(DEST_Coded(k:k+6)+ e,2);
DEST_Decoded(j:j+3) = corrected_y(4:7);
j = j + 4;
end
%20 gia tri au cua DEST_Decoded:
fprintf('\n DEST_Decoded: \n')
for i=1:4:20
fprintf('%d ',DEST_Decoded(i:i+3));
fprintf('\n');
end
Probability of error
%Xac inh so bits loi trong truong hop truyen chua ma hoa
uncoded va a ma hoa encoded bang cach so sanh cac bits cua
DEST_Decoded voi SRC_Uncoded

coded_errors = sum(mod(DEST_Decoded,2));


%Ket qua
fprintf('\n\tA = %3.4f, SNR = %5.2f dB\n', ...
Avect(A_index), SNR(A_index));
fprintf( '\tUncoded Errors = %5d, Coded Errors =
%5d\n',coded_errors);
end
%Tinh xac xuat loi luc chua ma hoa va da ma hoa:
pr_error_en = [pr_error_en, coded_errors/length(data)];
fprintf( '\tpr_error_un = %f, pr_error_en = %f\n', ...
pr_error_un,pr_error_en);
end
Thc hin li th nghim vi cc gi tr khc nhau ca A.
Avect=[0.5,1/sqrt(2),1,sqrt(2),2,2*sqrt(2),4]; bits=10000
Gia tri SNR,uncode_error v coded_error la:
A = 0.5000, SNR = -9.03 dB
Uncoded Errors = 3039, Coded Errors = 3322,
A = 0.7071, SNR = -6.02 dB
Uncoded Errors = 2384, Coded Errors = 2452
A = 1.0000, SNR = -3.01 dB
Uncoded Errors = 1604, Coded Errors = 1386,
A = 1.4142, SNR = 0.00 dB
Uncoded Errors = 754, Coded Errors = 481,
A = 2.0000, SNR = 3.01 dB
Uncoded Errors = 244, Coded Errors = 47
A = 2.8284, SNR = 6.02 dB
Uncoded Errors = 20, Coded Errors = 0,
A = 4.0000, SNR = 9.03 dB
Uncoded Errors = 0, Coded Errors = 0,
Biu gi tr nhiu:

th quan h gia SNR v xc sut li:



LAB3:
%encoder hamming (7,4)
function [sign_ham]=encoder(sign)
%matrix generation
G=[1 1 0 1 0 0 0
0 1 1 0 1 0 0
1 1 1 0 0 1 0
1 0 1 0 0 0 1];
sign_ham=mod(sign*G,2);

%decode hamming (7,4)
function [sign_deco]=decoder(sign)
%matrix checksum
H=[1 0 0 1 0 1 1
0 1 0 1 1 1 0
0 0 1 0 1 1 1];
%matrix inverter
HT=H';
%syndrom
s=mod(sign*HT,2);
%vector error
E=[0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 0 1 0 0 0
0 0 0 0 0 1 0];
for i=1:7
if(dec2bin(int2str(mod(E(i,:)*HT,2)))==dec2bin(int2str(s)))
sign_deco=mod(E(i,:)+sign,2);
end
end
end
%demodulation sign user BPSK
function [sign_demodu]=demodulation(sign)
n=length(sign);
sign_demodu=zeros(1,length(sign));
for i=1:n;
if(sign(i)>0)
sign_demodu(i)=1;
else
sign_demodu(i)=0;
end
end
end
%modulation sign user BPSK
function [sign_modu]=modulation(sign,A)
n=length(sign);
sign_modu=zeros(1,length(sign));
for i=1:n
if(sign(i)==1)
sign_modu(i)=A;
else
sign_modu(i)=-A;
end
end
end

%function main
function []=main()
clear all
close all
clc
%vector input
N=input('how many bits?\n N=');
%sign input
sign=round(rand(1,N));
%power sign transmiter
A=[0.5,1/sqrt(2),1,sqrt(2),2,2*sqrt(2),4,4*sqrt(2)];
%ampli nois
amp_nois=sqrt(2);
%encode
sign_en_rec=0;
sign_unen_rec=0;
BER_en=zeros(1,length(A));
BER_unen=zeros(1,length(A));
SNR=zeros(1,length(A));
for j=1:length(A);
%SNR
SNR(1,j)=20*log(A(1,j)/sqrt(2));
temp1=0;
temp2=0;
for i=1:(N/4)
%encode channal
sgn_enco=encoder(sign(1,((i-1)*4+1):i*4));
%modulation
sgn_en_modu=modulation(sgn_enco,A(j));
sgn_unen_modu=modulation(sign(1,((i-1)*4+1):i*4),A(j));
%channal
AWGN=rand(1,length(sgn_en_modu))*amp_nois;
sgn_en=sgn_en_modu+AWGN;
sgn_unen=sgn_unen_modu+AWGN(1,1:4);
%demodulation
sgn_en_dest=demodulation(sgn_en);
sgn_unen_dest=demodulation(sgn_unen);
%decode channal
sign_deco=decoder(sgn_en_dest);
temp1(1,length(temp1)+(1:4))=sign_deco(1,4:7);
temp2(1,length(temp2)+(1:4))=sgn_unen_dest;
end
sign_en_rec(1,1:(length(temp1)-1))=temp1(1,2:length(temp1));
sign_unen_rec(1,1:(length(temp2)-1))=temp2(1,2:length(temp2));
BER_en(1,j)=sum(mod(sign_en_rec+sign,2));
BER_unen(1,j)=sum(mod(sign_unen_rec+sign,2));
end
per_BER_en=BER_en/N;
per_BER_unen=BER_unen/N;
figure
semilogy(SNR,per_BER_en,'k^--','LineWidth',2);
hold on;
semilogy(SNR,per_BER_unen,'ro-','LineWidth',2);
xlabel('SNR (dB)');
ylabel('Bit error rate (BER)');
end

-22 -20 -18 -16 -14 -12 -10 -8 -6
10
-0.8
10
-0.7
10
-0.6
10
-0.5
SNR (dB)
B
i
t

e
r
r
o
r

r
a
t
e

(
B
E
R
)

You might also like