Professional Documents
Culture Documents
Báo Cáo TTS&TSL
Báo Cáo TTS&TSL
3. i u ch : TX_Uncoded v TX_Coded
function [TX]=modulation(sgn,A) %chuyen day tin hieu roi rac thanh tin hieu lien tuc de truyen di for i = 1:length(sgn) if sgn(i)==1 TX(i) = A; else TX(i) = -A; end end
4. Gi i i u ch
function [DEST]=demodulation(sgn) %khoi phuc lai tin hieu tuong tu thanh tin hieu roi rac for i = 1:length(sgn)
if
5. Gi i m t o ra DEST_Decoded
%Qua trinh giai ma,day tin nhan se duoc nhom thanh cac nhom 7 bit,de khoi %phuc lai 4 bit tin function [DEST_Decoded]=decoder(DEST_Coded) H=[ 1 0 0 1 0 1 1; 0 1 0 1 1 1 0; 0 0 1 0 1 1 1]; %ma tran kiem tra H HT=H'%ma tran nghich dao cua ma tran H 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];%ma tran loi DEST_Decoded =0; j = 1; for k = 1:7:length(DEST_Coded) %nhom tung nhom 7 bit cua DEST_Coded roi tinh syndrome bang %cach nhan tung nhom 7 bit voi ma tran HT,sau do lay module 2 syndrome = mod(DEST_Coded(k:k+6)*HT,2); %chuyen vector syndrom sang chuoi nhi phan,sau do chuyen chuoi %nhi phan sang thap phan synd_int = bin2dec(int2str(syndrome)); e = E(synd_int+1,:);%vector loi %vector 7 bit sau khi duoc sua loi corrected_y = mod(DEST_Coded(k:k+6)+ e,2); %4 bit tin trong dong bit duoc giai ma DEST_Decoded DEST_Decoded(1,j:j+3) = corrected_y(4:7); j = j + 4; end fprintf('\n DEST_Decoded: \n') for i=1:4:20 fprintf('%d ',DEST_Decoded(i:i+3)); fprintf('\n'); end
6.Ch
ng trnh chnh
function main clc clear all bits=input('nhap so bit:'); %data send SRC_Uncoded=create(bits); %encoder SRC_Coded=encoder(SRC_Uncoded) Avect=[0.5 1/sqrt(2) 1 sqrt(2) 2 2*sqrt(2) 4]; uncoded_errors=zeros(1,length(Avect));
coded_errors=zeros(1,length(Avect)); SNR=zeros(1,length(Avect)); pr_error_un=zeros(1,length(Avect)); pr_error_en=zeros(1,length(Avect)); for A_index = 1:length(Avect) A = Avect(A_index); %modulation sign unencoder TX_Uncoded=modulation(SRC_Uncoded,A); % Display the first 20 bits of TX_Uncoded fprintf('TX_Uncoded:'); fprintf('\n'); for i=1:4:20 fprintf('%d ',TX_Uncoded(i:i+3)); fprintf('\n'); end %modulation sign unencoder TX_Coded=modulation(SRC_Coded,A); % Display TX_Coded fprintf('TX_Coded: \n') for i=1:7:35 fprintf('%d ',TX_Coded(i:i+6)); fprintf('\n'); end %creating noise for channel uncoder noise = randn(1,length(TX_Uncoded)); hist(noise,20); fprintf('noise: \n') for i=1:4:20 fprintf('%f ',noise(i:i+3)); fprintf('\n'); end %signal receiver RX_Uncoded = TX_Uncoded + noise; fprintf('\n \n RX_Uncoded: \n') for i=1:4:20 fprintf('%f ',RX_Uncoded(i:i+3)); fprintf('\n'); end %creating noise for channel coder noise = randn(1,length(TX_Coded)); fprintf('New_noise: \n') for i=1:7:35 fprintf('%f ',noise(i:i+6)); fprintf('\n'); end %sing receiver for channel coder RX_Coded = TX_Coded + noise; fprintf('\n\n RX_Coded: \n') for i=1:7:35 ',RX_Coded(i:i+6)); fprintf('%f fprintf('\n'); end %demodulation sign receiver with channel unencoder DEST_Uncoded=demodulation(RX_Uncoded); fprintf('\n DEST_Uncoded: \n') for i=1:4:20 fprintf('%d ',DEST_Uncoded(i:i+3));
fprintf('\n'); end %demodulation sign receiver with channel encoder DEST_Coded=demodulation(RX_Coded) fprintf('\n DEST_Coded: \n') for i=1:7:35 fprintf('%d ',DEST_Coded(i:i+6)); fprintf('\n'); end %decoder DEST_Decoded=decoder(DEST_Coded) uncoded_errors(A_index) = sum(mod(SRC_Uncoded+DEST_Uncoded,2)); coded_errors(A_index) = sum(mod(SRC_Uncoded+DEST_Decoded,2)); fprintf('uncoded_errors:'); fprintf('coded_errors:'); fprintf('%d',uncoded_errors(A_index)); fprintf('\n'); fprintf('coded_errors:'); fprintf('%d',coded_errors(A_index)); fprintf('\n'); %xac suat loi khi khong ma hoa va ma hoa pr_error_un(1,A_index) = uncoded_errors(A_index)/length(SRC_Uncoded); pr_error_en(1,A_index) = coded_errors(A_index)/length(SRC_Uncoded); fprintf('pr_error_un:'); fprintf('%d',pr_error_un(1,A_index)); fprintf('\n'); fprintf('pr_error_en:'); fprintf('%d',pr_error_en(1,A_index)); fprintf('\n'); SNR(1,A_index) = 10*log10(A^2/2); fprintf('SNR:'); fprintf('%f',SNR(1,A_index)); fprintf('\n'); end figure semilogy(SNR,pr_error_un,'k^--','LineWidth',2); hold on; semilogy(SNR,pr_error_en,'ro-','LineWidth',2); xlabel('SNR (dB)'); ylabel('Bit error rate (BER)');
7.Tr ng h p c th v i bits=20, Avect=2 *The generated sequence: SRC_Uncoded: 1010 1000 1000 1010 1010 *The coded sequence: SRC_Coded: 0 0 1 1 0 1 0 1 1 0 1 0 0 0
1 1 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 1 0 1 0 TX_Coded: -2 -2 2 2 -2 2 2 2 -2 2 -2 -2 2 2 -2 2 -2 -2 -2 -2 2 2 -2 2 -2 -2 2 2 -2 2 -2 -2 -2 -2 -2
*The noise received signal: New_noise: 0.690052 0.555757 -1.120255 -1.532693 -1.097868 -1.415773 0.059571 -0.411251 -0.368011 -1.360963 0.779567 0.439411 -0.089622 1.021180 -0.873979 0.414700 0.348441 0.349254 -0.729247 0.326840 -0.514882 -0.896446 -1.203268 1.037816 -0.845944 -0.172914 -1.208652 -0.297127 -3.232038 -1.086959 -1.426436 -1.014451 -0.213267 -0.325348 1.944398 *The demodulated sequence: DEST_Coded: 0 0 1 1 0 1 0 1 1 0 1 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 1 0 1 0 *The decoded sequence: DEST_Decoded: 1 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0 *Final received message: 1 0 1 0 1 0 0 0 1 0 0 0 1 0 8.L p l i th nghi m nh ng v i cc gi tr A khc nhau: Avect=[0.5 1/sqrt(2) 1 sqrt(2) 2 2*sqrt(2) 4]; *Tr ng h p bits=10000: 1 0 1 0 1 0
Bi u
gi tr nhi u:
th quan h gi a SNR v xc su t l i:
Tr Bi u
*Tr Bi u
th quan h gi a SNR v xc su t l i:
Tr l i cu h i: 1.T i sao v n cn bit l i khi dung m kh i Hamming(7,4) Xt ton b dng bit trong tr ng h p m ha v gi i m th k t qu n i nh n c t l i h n so v i khi khng m ha.Tuy nhin,sau khi m ha v gi i m v i m kh i Hamming (7,4) th v n t n t i 1 s l i nh t nh.Nguyn nhn l do y l m Hamming (7,4) nn n u nhm 7 bit c l i th ch s a c l i trong tr ng h p x y ra 1 bit l i.Tr ng h p c 2 bit l i tr ln th b trng tri u ch ng v i tr ng h p x y ra 1 bit l i no ho c trng tri u ch ng khng c l i nn s khng th s a l i c.
2.Gi tr c a N c nh h
Ga tr c a k t qu khng nh ng ph thu c vo gi tr c a A m ta ch n m cn ph thu c vo chi u di c a dng d li u *V i cng chi u di dng d li u th xc su t l i s gi m khi A t ng ln.B i v khi t ng gi tr c a A t c l t ng bin xung truy n i,lc qua qu trnh truy n nhi u c ng vo s khng nh h ng nhi u n gi tr bin so v i khi gi tr A b,ngh a l v i gi tr A b th nhi u c ng vo c th gy o d u bin ,v khi gi i i u ch ,t i s cho ra bit c gi tr ng c l i so v i gi tr g c,cn v i A l n th nhi u kh lm o d u bin h n. *V i cng bin A,nh ng di bit khc nhau,xc su t l i trong tr ng h p c di bit l n h n th ng nh h n tr ng h p c di bit b h n.V nhi u trn ng truy n gy ra 1 s l i i v i dng d li u c truy n i,m nhi u th ng khng ko di v nh ng nh h ng l n ch tc ng vi th i i m.Chnh v v y,v i dng bit cng di th tuy t ng s l i s nhi u ln,nh ng t l l i so v i di dng d li u cng b nn xc su t gy l i b.
5. N u mu n gi m BER th S/N t ng m S/N t ng ngh a l pht i nhi u bit h n .V SNR = Eb /N0 , m Eb l n ng l ng c a 1 bit nn SNR cng l n th NL cng l n =>pht nhi u bit h n th cng su t l n h n h th ng s c ng k nh, t ti n v chi m d ng b ng thng nhi u do ph i cn i gi a cc t s .Cch t t nh t l ta dng m ho khc .VD: M ho ngu n, m ho knh Nh n xt: S d ng m ha knh truy n t t h n khi khng m ha.V khi s d ng m ha knh truy n t c l thm bit d vo chu i d li u truy n i,gip bn thu c th pht hi n v s a c1 s l i.V y m ha knh truy n lm t ng ch t l ng knh truy n,t ng kh n ng pht hi n l i. Khi s d ng m ha knh truy n cn gip ta t ng t l S/N.N u khng s d ng m ha knh truy n c th t ng cng su t pht,nh ng nh ni trn,khng ph i lc no ta c ng c th t ng cng su t pht.V y,ph ng php t t nh t v n m s d ng m ha.