báo cáo thông tin số.docx

25
BÀI SỐ 1 QUÁ TRÌNH NGẪU NHIÊN CỦA TÍN HIỆU Bài 1.1: Code: %B1.1 ham phan bo xac suat Gauss muy=0; %phan phoi chuan sgm=1; x=-5:0.1:5; %tao 1 mang phan tu chay tu -5 den 5 voi buoc nhay la 0.1 Px=1/(sqrt(2*pi)*sgm)*exp(-(x-muy).^2/(2*sgm^2)); %cong thuc phan bo xac suat Gauss plot(x,Px,'m'); %ve do thi bang ham plot title('1.1 Ham phan bo xac suat Gauss'); % tieu de do thi xlabel('x'); %truc x ylabel('P(x)') % truc y Đồ thị: 1

Transcript of báo cáo thông tin số.docx

BO CO TH NGHIM THNG TIN S

BI S 1 QU TRNH NGU NHIN CA TN HIUBi 1.1: Code:%B1.1 ham phan bo xac suat Gaussmuy=0; %phan phoi chuansgm=1;x=-5:0.1:5; %tao 1 mang phan tu chay tu -5 den 5 voi buoc nhay la 0.1Px=1/(sqrt(2*pi)*sgm)*exp(-(x-muy).^2/(2*sgm^2)); %cong thuc phan bo xac suat Gaussplot(x,Px,'m'); %ve do thi bang ham plottitle('1.1 Ham phan bo xac suat Gauss'); % tieu de do thixlabel('x'); %truc xylabel('P(x)') % truc y th:Bi 1.2: Code:%%B1.2 ham phan bo xac suat Gauss v?i 100000 phan tumuy=0; %Phan phoi chuan N(0,1)sgm=1;step=0.1;n=100000; % do dai cua qua trinh ngau nhienx=-5:step:5; % khoang xet deu tu -5 den 5, cach deu 0.1y=randn(1,n); % tao qua trinh ngau nhien theo phan phoi chuanPx=hist(y,x)/n/step; % tinh so vecto theo ham phan bo xac suatstem(x,Px); % ve do thi roi rachold on; % giu lai do thi vua ve de ve chong cac do thi khac lenPx_lt=1/(sqrt(2*pi)*sgm)*exp(-(x-muy).^2/(2*sgm^2)); % cong thuc Gaussplot(x,Px_lt,'m'); % ve do thi ly thuyettitle('1.2a Ham mat do phan bo xac suat voi n = 100000'); % ten do thixlabel('x'); % truc xylabel('P(x)'); % truc ylegend('Ly thuyet','Mo phong'); % chu thich cho do thihold off; % tat "hold on" th:

BI S 2 LNG T HA TUYN TNHBi 2.1: function [ indx qy] =lquan( x,xmin,xmax,n )nlevel=2^n; % So muc dien tu hoaq=(xmax-xmin)/nlevel;% Buoc luong tu[indx qy]=quantiz(x,xmin+q:q:xmax-q,xmin+q/2:q:xmax-q/2);End

xs = 0.8268 0.2647 -0.8049 -0.4430 0.0938>> [xi xq]=lquan(xs,-1,1,3)xi = 7 5 0 2 4xq = 0.8750 0.3750 -0.8750 -0.3750 0.1250Bi 2.2: Code:t=0:0.01:20;xt=sin(randn()+t).*cos(rand()*t);[inx xqt]= lquan(xt,-1,1,randint(1,1,3)+2);plot(t,xt,'b',t,xqt,'r');grid on;title('Luong tu hoa tuyen tinh');xlabel('xt');ylabel('xqt');legend('tin hieu x(t)','tin hieu luong tu xq(t)');hold off; th:

BI S 3 TP M LNG T TRONG K THUT LNG T HA TUYN TNHBi 3.1: Code:N=1000; x=2*rand(1,N)-1; % x phan bo deu tu -1 den 1nbit= 1:10; % so bit luong tu tu 1 den 10SNqR= zeros(size(nbit)); % khoi tao mang SNqR chua ket quaSNqR_lt= 6.02 * nbit; % Mang chua SNqR tinh theo ly thuyetPs=sum(x.^2)/N; % cong suat tin hieu x for i=1:size(nbit,2) % size(n,2) tra ve so cot n [inx xq]=lquan(x,-1,1,nbit(i)); % luong tu hoa x, voi so bit nbit(i)luu ket qua vao xq eq= x-xq; % Sai so eq Pq=sum(eq.^2)/N; % Cong suat tap am luong tu Pq SNqR(i)=10*log(Ps/Pq); % SNqR theo dBendplot(nbit,SNqR,'b',nbit,SNqR_lt,'r'); % Do thi ket qua SNqR_db theo nbittitle('Bai 3.1 Tap am luong tu');xlabel('SNqR');ylabel('SNqR_lt');legend( 'SNqR Mo phong','SNqR ly thuyet');grid on;

th:

Bi 3.2:N=1000; x=sin(linspace(1,5,N)); % x phan bo tu 1 den 5 N gia tri deu nhaunbit= 1:10; % so bit luong tu tu 1 den 10SNqR= zeros(size(nbit)); % khoi tao mang SNqR chua ket quaSNqR_lt= 6.02 * nbit; % Mang chua SNqR tinh theo ly thuyetPs=sum(x.^2)/N; % cong suat tin hieu x for i=1:size(nbit,2) % size(n,2) tra ve so cot n [inx xq]=lquan(x,-1,1,nbit(i)); % luong tu hoa x, voi so bit nbit(i)luu ket qua vao xq eq= x-xq; % Sai so eq Pq=sum(eq.^2)/N; % Cong suat tap am luong tu Pq SNqR(i)=10*log(Ps/Pq); % SNqR theo dBendplot(nbit,SNqR,'b',nbit,SNqR_lt,'r'); % Do thi ket qua SNqR_db theo nbittitle('3.2 Tap am luong tu');xlabel('SNqR');ylabel('SNqR_lt');legend( 'SNqR Mo phong','SNqR ly thuyet');grid on; th:

BI S 4 MT PH NNG LNG V HM T TNG QUAN CA TN HIUBi 4.1: Code:L=500;x= randn(1,L); %4.1a - dung ham phan phoi chuan%x= linspace(-1,1,L); %4.1b - dung ham bien do tang dan%x= sin(linspace(-10,10,L)); %4.1c - dung ham sinacorr_x = xcorr(x); % ham tu tuong quan cua vec to xn= -(L-1):(L-1);plot(n,acorr_x,'b'); % do thi tu tuong quantitle ('4.1a Ham tu tuong quan tin hieu x voi ham phan phoi chuan'); %dat ten tieu de%title ('4.1b Ham tu tuong quan tin hieu x voi ham bien do tang dan'); %dat ten tieu de%title ('4.1c Ham tu tuong quan tin hieu x voi ham sin'); %dat ten tieu dexlabel ('n'); %truc xylabel ('xcorr_x'); %truc y th:

Bi 4.2: Code:N=200; % so luong tan so roi rac du lonL=50; % do dai cua qua trinh ngau nhienx=randn(1,L); % x la qua trinh ngau nhien theo phan phoi chuanw=linspace(0,2*pi,N); %w l khoang tan so (0,2*pi) voi N tan so roi rac fx=freqz(x,1,w); % bien doi fourier cua x tai cac tan so roi rac trong wesd_x=fx.*conj(fx); % mat do pho nang luong cua xplot(w/(2*pi),esd_x); % do thi mat do pho nang luongtitle('4.2 do thi mat do pho nang luong'); % tieu de do thixlabel('w/2\pi'); % truc xylabel('ESD(x)'); % truc y

th:

Tm hm t tng quan v v th so snh: Code:N=1000; % so luong tan so roi rac du lonL=500; % do dai cua qua trinh ngau nhienx=randn(1,L); % x la qua trinh ngau nhien theo phan phoi chuanw=linspace(0,2*pi,N); % w l khoang tan so (0,2*pi) voi N tan so roi rac fx=freqz(x,1,w); % bien doi fourier cua x tai cac tan so roi rac trong wesd_x=fx.*conj(fx); % mat do pho nang luong cua xplot(w/(2*pi),esd_x); % do thi mat do pho nang luonghold on;title('4.2 mat do pho nang luong va ham tu tuong quan');xlabel('w/2\pi');[acorr_x,n]=xcorr(x); % ham tu tuong quanft_acorr_x=freqz(acorr_x,1,w).*exp(j*w*(L-1)); plot(w/(2*pi),real(ft_acorr_x),'b:'); % do thi ham tuong quanlegend('ESD(w)','R(w)');hold off; th:

BI S 5 M NG DY NRZBi 5.1: Code:len=100000; % do dai dong bit mo phongSNR_db=0:2:8 % tao vecto SNR_dbSNR=10.^(SNR_db/10); % doi SNR tu decibel sang lann bsignal=(rand(1,len)>=0.5);NRZ_signal=bsignal*2-1; % bien doi dong bit 0 1 sang -1 1N0=1./SNR; % phuon sai cua tap am= cong suat tap am % cho tin hieu di qua kenh nhieu trang va giai dieu che for i=1:length(SNR_db) noise=sqrt(N0(i))*randn(1,len); % tap am noise r_signal=NRZ_signal+ noise; % tin hieu thu duoc = tin hieu NRZ ben %phat+ tap am noise NRZ_decoded=sign(r_signal); % giai ma tin hieu NRZ thu duoc Pe(i)=symerr(NRZ_signal, NRZ_decoded)/len;end plot(SNR_db,Pe,'bo--'); % ve do thititle('5.1 Ma duong day NRZ'); % tieu de do thixlabel('SNR_dB'); % truc xylabel('Pe'); % truc y th:

Bi 5.2: Code:len=100000; % Do dai dong bit mo phongSNR_db=0:2:8; % Tao vector SNR_db= 0 2 4 6 8SNR=10.^(SNR_db/10); % Doi tu decibel sang lanbsignal=randint(1,len); % Tao dong bit ngau nhienNRZ_signal=bsignal*2-1; % Bien doi dong bit 0 1 thang dang -1 1N0=1./SNR;for i=1:length(SNR_db) noise=sqrt(N0(i))*randn(1,len); % Tao tap am noise voi ty so SNR la SNR(i) r_signal=NRZ_signal+noise; % Tin hieu thu duoc = tin hieu NRZ ben phat + tap am NRZ_decoded=sign(r_signal); % Giai ma tin hieu NRZ thu duoc bit_error=sum(NRZ_signal ~= NRZ_decoded); % Tong cac bit loi Pe(i)=bit_error/len; % Xac suat loiendplot(SNR_db,Pe,'k*-'); % Do thi the hien xac suat loi bit ung voi cac gia tri SNR= 0 2 4 6 8title('5.2 Do thi the hien xac suat loi bit');xlabel('SNR dB');ylabel('Pe'); hold on;Pe_lt=(1-erf(sqrt(SNR)/sqrt(2)))/2; % Xac suat loi bit theo ly thuyetplot(SNR_db,Pe_lt,'bo-');legend('Mo phong','Ly thuyet'); th:

BI S 6 IU CH QPSKBi 6.1: Code:len=50000;x = (rand(1,len) >=0.5); % tao dong bit ngau nhien do dai lenqpsk_signal=[];for i = 1:2:length(x) if x(i)== 0 & x(i+1) == 0 qpsk_signal((i+1)/2) = exp(j*pi/4); elseif x(i) == 0 & x(i+1) == 1 qpsk_signal((i+1)/2) = exp(j*3*pi/4); elseif x(i) == 1 & x(i+1) == 1 qpsk_signal((i+1)/2) = exp(j*5*pi/4); elseif x(i) == 1 & x(i+1) == 0 qpsk_signal((i+1)/2) = exp(j*7*pi/4); endendplot(qpsk_signal,'o'); % ve tin hieu dieu che len do thihold on;t=0:0.01:2*pi;plot(exp(j*t),'b--');title('6.1 bieu do chom sao QPSK');xlabel('I');ylabel('Q'); th:

Bi 6.2:Code:len=50000;x = (rand(1,len) >=0.5); % tao dong bit ngau nhien do dai lenqpsk_signal=[];for i = 1:2:length(x) if x(i)== 0 & x(i+1) == 0 qpsk_signal((i+1)/2) = exp(j*pi/4); elseif x(i) == 0 & x(i+1) == 1 qpsk_signal((i+1)/2) = exp(j*3*pi/4); elseif x(i) == 1 & x(i+1) == 1 qpsk_signal((i+1)/2) = exp(j*5*pi/4); elseif x(i) == 1 & x(i+1) == 0 qpsk_signal((i+1)/2) = exp(j*7*pi/4); endendes = var(s); eb = es/2;snr_db = 6; % gia thietn_0 = eb/10^(snr_db/10);n = sqrt(n_0/2)*(randn(size(s)) + j*randn(size(s))); % mien nhieu gaussr = s + n; % tin hieu cong nhieuplot(r,'.');hold on;plot(s,'ro'); % ve do thi chom sao QPSKhold on;t = 0:0.01:2*pi;plot(exp(j*t),'r--'); % ve duong trong don vi net mau dolegend('S_m','qpsk signal');title('6.2 Cho qua tin hieu nhieu trang');xlabel('I');ylabel('Q'); th:

BI S 7 M PHNG IU CH QPSK QUA KNH NHIU GAUSS Code:len=100000;x = randint(1,len);qpsk=qammod(x,4);SNR_db=0:2:8; %Khoi tao vecto SNR_dbSNR=10.^(SNR_db/10);N0=1./SNR; %tao vecto N0for i=1:length(SNR_db) noise=sqrt(N0(i)/2)*(randn(size(qpsk))+j*randn(size(qpsk))); %Tao nhieu qpskx_nhieu=qpsk+noise; r_x=qamdemod(qpskx_nhieu,M); n=0; for k=1:length(x) if x(k)~=r_x(k) n=n+1; end endBER(i)=n/len;endplot(SNR_db,BER,'m-');title('7.0 Mo phong dieu che QPSK qua kenh nhieu Gauss');xlabel('SNR dB');ylabel('BER'); th:

BI S 8 XC SUT LI BIT TRONG IU CH QPSK Code:len=100000;x = randint(1,len);qpsk=qammod(x,4);SNR_db=0:2:8; %khoi tao vecto SNR_db 0 2 4 6 8SNR=10.^(SNR_db/10);N0=1./SNR; %tao vecto N0for i=1:length(SNR_db) BERBPSK(i)=(1./2)*erfc(sqrt(SNR(i)/2)); BERQPSK(i)=(1./2)*erfc(SNR(i)/sqrt(2));endplot(SNR_db,BERBPSK,'bO-',SNR_db,BERQPSK,'m*-');title('So Sanh Ti Le Bit Loi Trong Dieu Che Tin Hieu');xlabel('SNR_db');ylabel('BER');legend('Mo phong','Ly thuyet');hold off; th

22