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.
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');
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');
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');
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;
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)');
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');
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;
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;
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:
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: