Top Banner
Bài 1.1 x=-5:.1:5; Px=exp(-x.^2/2)/sqrt(2*pi); plot(x,Px); title('Phan bo xac suat Gauss'); xlabel('x'); ylabel('P(x)'); FIGURE: Bài 1.2 len=100000;%Do dai qua trinh ngau nhien x=randn(1,len);%Tao qua trinh ngau nhien theo pp chuan step=.1;%step=0.1 k=-5:step:5;%Khoang xet tu -5 den 5, cach deu 0.1 px=hist(x,k)/len/step;%Ham phan bo xac suat stem(k,px); Px_lythuyet=exp(-k.^2/2)/sqrt(2*pi);%Ham phan bo xac suat ly thuyet hold on; plot(k,Px_lythuyet); title('Phan bo xac suat Gauss'); xlabel('x');
13

thi nghiem thong tin so

Jan 16, 2016

Download

Documents

truonghau199

huong dan thi nghiem thong tin so
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: thi nghiem thong tin so

Bài 1.1 x=-5:.1:5; Px=exp(-x.^2/2)/sqrt(2*pi); plot(x,Px); title('Phan bo xac suat Gauss'); xlabel('x'); ylabel('P(x)'); FIGURE:

Bài 1.2 len=100000;%Do dai qua trinh ngau nhien x=randn(1,len);%Tao qua trinh ngau nhien theo pp chuan step=.1;%step=0.1 k=-5:step:5;%Khoang xet tu -5 den 5, cach deu 0.1 px=hist(x,k)/len/step;%Ham phan bo xac suat stem(k,px); Px_lythuyet=exp(-k.^2/2)/sqrt(2*pi);%Ham phan bo xac suat ly thuyet hold on; plot(k,Px_lythuyet); title('Phan bo xac suat Gauss'); xlabel('x');

PhuongOt
Typewriter
PhuongOt
Typewriter
PhuongOt
Typewriter
PhuongOt
Typewriter
PhuongOt
Typewriter
PhuongOt
Typewriter
PhuongOt
Typewriter
CODE VÀ MÔ PHỎONG
PhuongOt
Typewriter
Page 2: thi nghiem thong tin so

ylabel('P(x)');legend('Mo phong','Ly thuyet');hold off;FIGURE:

Hàm lquan.m function [indx, qy]= lquan(x,xmin,xmax,nbit) nlevel=2.^nbit; q=(xmax-xmin)./nlevel; [indx, qy]=quantiz(x,xmin+q:q:xmax-q,xmin+q/2:q:xmax-q/2); Bài 2.1 xs=rand(1,5)*2-1; [xi, xq]=lquan(xs,-1,1,3)

Bài 2.2 t=0:.1:20; xt=sin(rand()+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('Do thi cua tin hieu'); xlabel('t'); legend('xt','xqt');

Page 3: thi nghiem thong tin so

FIGURE:

Bài 3.1 N=1000;x=2*rand(1,N)-1;%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 kqua

SNqR_lt=6.02*nbit;%Mang SNqR theo ly thuyetPs=sum(x.^2)/N;%Cong suat tin hieufor i=1:size(nbit,2)%Tra ve so cot cua nbit [xi, xq]=lquan(x,-1,1,nbit(i)); eq=x-xq; Pq=sum(eq.^2)/N; SNqR(i)=10*log10(Ps/Pq);endplot(nbit,SNqR,'b',nbit,SNqR_lt,'r');xlabel('nbit');ylabel('SNqR');legend('Thuc te','Ly thuyet');

Page 4: thi nghiem thong tin so

FIGURE:

Bài 3.2 N=1000;x=sin(linspace(1,5,N));%Tin hieu dieu hoanbit=1:10;%So bit luong tu tu 1 den 10SNqR=zeros(size(nbit));%Khoi tao mang SNqR chua kqua

SNqR_lt=6.02*nbit;%Mang SNqR theo ly thuyetPs=sum(x.^2)/N;%Cong suat tin hieufor i=1:size(nbit,2)%Tra ve so cot cua nbit [xi, xq]=lquan(x,-1,1,nbit(i));% eq=x-xq; Pq=sum(eq.^2)/N; SNqR(i)=10*log10(Ps/Pq);endplot(nbit,SNqR,'b',nbit,SNqR_lt,'r');xlabel('nbit');ylabel('SNqR');legend('Thuc te','Ly thuyet');

Page 5: thi nghiem thong tin so

FIGURE: SNqR ly thuyet va thuc te

Bài 4.1 L=500;x=randn(1,L);n=-(L-1):1:(L-1);acorr_x=xcorr(x);%Tinh tu tuong quanplot(n,acorr_x,'m');hold on;x=linspace(-1,1,L);%Bien do tang dann=-(L-1):1:(L-1);acorr_x=xcorr(x);plot(n,acorr_x,'r');x=sin(linspace(-10,10,L));%Tin hieu sinn=-(L-1):1:(L-1);acorr_x=xcorr(x);plot(n,acorr_x,'.');legend('randn','linspace','sin(linspace)');xlabel('n');ylabel('acorr(x)');title('Ham tu tuong quan');

hold off;

Page 6: thi nghiem thong tin so

FIGURE:

Bài 4.2 N=200; L=50; x=rand(1,L); acorr_x=xcorr(x); k=0:N-1; fx=fft(x,N);%DFT tin hieu x esd_x=abs(fx).^2;%Mat do pho nang luong ft_acorr_x=fft(acorr_x,N).*exp(1i*2*pi/N*k*(L-1));%Pho ham tu tuong quan subplot(2,1,1); semilogy(k*2/N,esd_x); title('Mat do pho nang luong'); xlabel('k*2/N'); ylabel('S(k)'); subplot(2,1,2); semilogy(k*2/N,real(ft_acorr_x),'r'); title('Mat do pho nang luong theo tu tuong quan'); xlabel('k*2/N'); ylabel('Rxx(k)');

Page 7: thi nghiem thong tin so

FIGURE:

Bài 5.1 len=100000;%Do dai dong bit mo phongSNR_db=0:2:8;%Tao vecto SNR_db = 0 2 4 6 8SNR=10.^(SNR_db/10);%Doi SNR tu Decibel sang lanbsignal=randint(1,len);%Dong bit ngau nhien do dai lenNRZ_signal=bsignal*2-1;%Bien doi dong bit 0 1 sang -1 1N0=1./SNR;for i=1:length(SNR_db) noise=sqrt(N0(i))*randn(1,len);%Tao tap am r_signal=NRZ_signal + noise;%Tin hieu NRZ phia thu NRZ_decoded=sign(r_signal);%Giai ma tin hieu NRZ [num,rat]=symerr(NRZ_decoded,NRZ_signal); BER(i)=rat;endplot(SNR_db,BER,'bo--');title('Ti le loi bit BER voi ti le tin hieu tren tap am SNR');xlabel('SNR__db');ylabel('BER');

Page 8: thi nghiem thong tin so

FIGURE:

Bài 5.2 len=100000;%Do dai dong bit mo phong SNR_db=0:2:8;%Tao vecto SNR_db = 0 2 4 6 8 SNR=10.^(SNR_db/10);%Doi SNR tu Decibel sang lan bsignal=randint(1,len);%Dong bit ngau nhien do dai len NRZ_signal=bsignal*2-1;%Bien doi dong bit 0 1 sang -1 1 N0=1./SNR; for i=1:length(SNR_db) noise=sqrt(N0(i))*randn(1,len);%Tao tap am r_signal=NRZ_signal + noise;%Tin hieu NRZ phia thu NRZ_decoded=sign(r_signal);%Giai ma tin hieu NRZ [num,rat]=symerr(NRZ_decoded,NRZ_signal); BER(i)=rat; end plot(SNR_db,BER,'bo--'); title('So sanh BER voi ly thuyet Pe') xlabel('SNR__db'); ylabel('BER'); hold on; SNR=0:2:8; Pe=1./2.*(1-erf(sqrt(10.^(SNR/10)./2)));%Tinh Pe plot(SNR,Pe,'r'); hold off;

Page 9: thi nghiem thong tin so

FIGURE:

Bài 6.1 len=500000;x=randint(1,len);for i=1:2:len;

switch x(i) case 0 if x(i+1)==1

qpsk_signal((i+1)/2)=exp(j*5*pi/4)*sqrt(2); else qpsk_signal((i+1)/2)=exp(j*3*pi/4)*sqrt(2); end case 1 if x(i+1)==1

qpsk_signal((i+1)/2)=exp(j*7*pi/4)*sqrt(2); else qpsk_signal((i+1)/2)=exp(j*pi/4)*sqrt(2); end end

endplot(qpsk_signal,'+');title('Bieu do chom sao QPSK');xlabel('\phi(t)');hold on;t=0:0.01:2*pi;plot(sqrt(2)*exp(j*t),'r--');hold off;

Page 10: thi nghiem thong tin so

FIGURE:

Bài 6.2 len=50000;x=randint(1,len);for i=1:2:len;

switch x(i) case 0 if x(i+1)==1

qpsk_signal((i+1)/2)=exp(j*5*pi/4)*sqrt(2); else qpsk_signal((i+1)/2)=exp(j*3*pi/4)*sqrt(2); end case 1 if x(i+1)==1

qpsk_signal((i+1)/2)=exp(j*7*pi/4)*sqrt(2); else qpsk_signal((i+1)/2)=exp(j*pi/4)*sqrt(2); end end

end

SNR=6;Es=std(qpsk_signal).^2;N0=Es/(10^(SNR/10));noise=sqrt(N0/2).*(randn(1,length(qpsk_signal))+j.*randn(1,length(qpsk_signal)));qpsk=qpsk_signal+noise;plot(qpsk,'.');

Page 11: thi nghiem thong tin so

hold on;plot(qpsk_signal,'y+');hold on;t=0:0.01:2*pi;plot(sqrt(2)*exp(j*t),'y--');legend('Co nhieu','K nhieu');hold off;FIGURE: QPSK co nhieu

Bài 7 len=50000;x=randint(1,len);for i=1:2:len;

switch x(i) case 0 if x(i+1)==1

qpsk_signal((i+1)/2)=exp(j*5*pi/4)*sqrt(2); else qpsk_signal((i+1)/2)=exp(j*3*pi/4)*sqrt(2); end case 1 if x(i+1)==1

qpsk_signal((i+1)/2)=exp(j*7*pi/4)*sqrt(2); else qpsk_signal((i+1)/2)=exp(j*pi/4)*sqrt(2); end end

endSNR=0:2:8;Es=std(qpsk_signal).^2;

Page 12: thi nghiem thong tin so

N0=Es./(10.^(SNR/10)); qpsk_de=zeros(1,2*length(qpsk_signal)); for i=1:length(SNR) noise=sqrt(N0(i)/2).*(randn(1,length(qpsk_signal))+j.*randn(1,length(qpsk_signal))); qpsk=qpsk_signal+noise; for k=1:length(qpsk) if(real(qpsk(k))>0) qpsk_de(2*k-1)=1; else qpsk_de(2*k-1)=0; end if(imag(qpsk(k))>0) qpsk_de(2*k)=0; else qpsk_de(2*k)=1; end end BER(i)=symerr(qpsk_de,x)/length(x); end Pb=1/2*erfc(sqrt((10.^(SNR/10))./2)); xlabel('SNR_db'); plot(SNR,BER,'o-'); hold on; plot(SNR,Pb,'r'); legend('BER','Pb'); hold off; FIGURE:

Page 13: thi nghiem thong tin so

Bài 8 n_sym=50000;M=[16 32 64];SNR_db=0:25;BER=zeros(length(M),length(SNR_db));for k=1:size(M,2) s_stream=randint(1,n_sym,M(k)); y=qammod(s_stream,M(k),0,'gray'); Es=std(y).^2; SNR=10.^(SNR_db/10); N0=Es./SNR;

for r=1:size(SNR_db,2) noise=sqrt(N0(r)/2)*(randn(1,length(y))+j.*randn(1,length(y))); y_awgn=y+noise; s_demod=qamdemod(y_awgn,M(k),0,'gray'); [num rat]=biterr(s_demod,s_stream); BER(k,r)=rat; end end semilogy(SNR_db,BER(1,:),'bo-',SNR_db,BER(2,:),'rs-',SNR_db,BER(3,:),'m*-'); title('Ti le BER voi cac muc khac nhau'); xlabel('SNR_db'); legend('M=16','M=32','M=64'); grid on; FIGURE: