Báo cáo thí nghiệm thông tin số đại học Bách Khoa Hà Nội

18 848 3
Báo cáo thí nghiệm thông tin số đại học Bách Khoa Hà Nội

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Bài 1.1: Source code: x=5:0.1:5; Px=(1sqrt(2pi)exp(x.22)); plot(x,Px); % Ve do thi xlabel(x); % Label cho truc hoanh ylabel(Px); % Label cho truc tung title( Do thi ham phan bo xac suat Gauss); % Ten do thi Kết quả mô phỏng: Bài 1.2: Source code: length=100000; % Do dai cua qua trinh ngau nhien x=randn(1,length); % Tao qua trinh ngau nhien theo phan phoi chuan step=.1; % buoc nhay bang 0.1 k=5:step:5; % Khoang xet tu 5 den 5, b?oc nhay 0.1 px=hist(x,k)lengthstep % Tinh so vecto trong cac khoang cho boi vecto k stem(k,px) % ve do thi roi rac Px_lythuyet=exp(k.22)sqrt(2pi); % Ham phan bo xac suat theo ly thuyet hold on; plot(k,Px_lythuyet); title( Phan bo sac xuat Gauss); % Tieu de cua do thi xlabel(x); % Ten truc hoanh ylabel(P(x)); % Ten truc tung legend(Ly thuyet,Mo phong); % Tao ghi chu

Báo cáo thí nghiệm thơng tin số Họ tên: Lớp: I MSSV: Bài 1:Q trình ngẫu nhiên tín hiệu Bài 1.1: Source code: x=-5:0.1:5; Px=(1/sqrt(2*pi)*exp(-x.^2/2)); plot(x,Px); % Ve thi xlabel('x'); % Label cho truc hoanh ylabel('Px'); % Label cho truc tung title(' Do thi ham phan bo xac suat Gauss'); % Ten thi Kết mô phỏng: Bài 1.2: Source code: length=100000; % Do dai cua qua trinh ngau nhien x=randn(1,length); % Tao qua trinh ngau nhien theo phan phoi chuan step=.1; % buoc nhay bang 0.1 k=-5:step:5; % Khoang xet tu -5 den 5, b?oc nhay 0.1 px=hist(x,k)/length/step % Tinh so vecto cac khoang cho boi vecto k stem(k,px) % ve thi roi rac Px_lythuyet=exp(-k.^2/2)/sqrt(2*pi); % Ham phan bo xac suat theo ly thuyet hold on; plot(k,Px_lythuyet); title(' Phan bo sac xuat Gauss'); % Tieu de cua thi xlabel('x'); % Ten truc hoanh ylabel('P(x)'); % Ten truc tung legend('Ly thuyet','Mo phong'); % Tao ghi chu hold off; Kết mô phỏng: II Bài II:Lượng tử hóa tuyến tính: Bài 2.1: Chương trình con: function[indx,qy]=lquan(x,xmin,xmax,nbit) nlevel=2^nbit; % So muc luong tu hoa q=(xmax-xmin)/nlevel; % Buoc luong tu [indx qy]=quantiz(x,xmin+q:q:xmax-q,xmin+q/2:q:xmax-q/2); Lệnh Command: >> xs=rand(1,5)*2-1; >> [xi xq]=lquan(xs,-1,1,3) xi = xq = -0.6250 -0.1250 -0.6250 0.8750 -0.8750 Bài 2.2: Source code: t = 0:.01:20; xt = sin( randn() + t).*cos(rand()*t); % Tin hieu vao [inx xqt] = lquan (xt, -1, 1, randi(3)+1); % xqt: tin hieu da duoc luong tu hoa plot(t,xt,'b',t,xqt,'r'); % Ve thi tren cung he truc grid on ; % Bat luoi hoa title ('Luong Tu Hoa Tuyen Tinh'); % tieu de xlabel('t'); % truc x ylabel('xt xqt'); % truc y legend('Tin hieu dau','Tin hieu qua Luong Tu'); % giai thich tung duong tren thi Kết mô phỏng: III Bài 3: Tạp âm lượng tử kỹ thuật lượng tử hóa tuyến tính: Source code: N =1000; x_uni = 2*rand(1, N)-1; % x_uni phan bo tu -1 den x_sin = sin(linspace(1,5,N)); % Tin hieu sin nbit = :10; % so bit luong tu tu den 10 SNqR_uni = zeros (size(nbit)); % khoi tao mang SNqR_uni SNqR_sin = zeros (size(nbit)); % SNqR cua tin hieu sin SNqR_lt = 6.02 *nbit; % mang SNqR tinh theo Ly thuyet Ps_uni = sum (x_uni.^2)/N; % Cong suat tinh hieu mo phong Ps_sin = sum (x_sin.^2)/N; % Cong suat tin hieu sin for i=1:size(nbit,2) [xi xq_uni] = lquan (x_uni,-1,1,nbit(i) ); % Luong tu hoa voi ket qua dua vao xq eq_uni = x_uni - xq_uni; sai so % Tinh Pq_uni= sum (eq_uni.^2)/N; % Cong suat tap am luong tu SNqR_uni(i) = 10 * log10 (Ps_uni /Pq_uni) ; % tinh SNqR end for i=1:size(nbit,2) % tra ve so cot n [xi xq_sin] = lquan (x_sin,-1,1,nbit(i) ); % Luong tu hoa voi ket qua dua vao xq eq_sin = x_sin - xq_sin; % Sai so eq_sin Pq_sin= sum (eq_sin.^2)/N; % Cong suat tap am luong tu Pq_sin SNqR_sin(i) = 10 * log10 (Ps_sin /Pq_sin) ; % tinh SNqR_sin end plot (nbit,SNqR_uni ,'r',nbit,SNqR_sin,'b',nbit,SNqR_lt,'o'); % Ve thi SNqR(nbit) tren cung mot he truc xlabel('nbit'); ylabel('SNqR'); legend('SNqR_uni(nbit)','SNqR_sin(nbit)', 'SNqR_lt(nbit)') % Ghi chu thich Kết mô phỏng: IV Bài 4:Mật độ phổ lượng hàm tự tương quan tín hiệu: Bài 4.1: Source code: L=500; x=randn(1,L); x1=linspace(-1,1,L) %Bien tang dan x2=sin(linspace(-10,10,L)) % Tin hieu hinh sin [n y]=xcorr(x); figure(1); subplot(2,2,1) % hang, cot, o thu nhat stem(y,n); title('Do thi ham tu tuong quan cua x=randn(1,L)'); xlabel('n'); [n y1]=xcorr(x1); subplot(2,2,2) % hang, cot, o thu stem(y1,n); title('Do thi ham tu tuong quan cua x1=linspace(-1,1,L)'); xlabel('n'); [n y2]=xcorr(x2); subplot(2,2,3) % hang, cot, o thu stem(y2,n); title('Do thi ham tu tuong quan cua x2=sin(linspace(10,10,L))'); xlabel('n'); Kết mô phỏng: Bài 4.2: Source code: N=200; x=randn(1,50); w=linspace(0,2*pi,N); fx=freqz(x,1,w); esd_x=fx.*conj(fx); acorr_x=xcorr(x); ft_acorr_x=freqz(acorr_x,1,w).*exp(j*w*49); subplot(2,1,1); semilogy(w/pi,esd_x); title('Ham mat nang luong cua tin hieu'); xlabel('w/pi'); ylabel('esd_x'); subplot(2,1,2); semilogy(w/pi,real(ft_acorr_x),'b'); title('Pho cua ham tu tuong quan'); xlabel('w/pi'); ylabel('ft_acorr_x'); Kết mô phỏng: V Bài 5: Mã đường dây NRZ: Bài 5.1: Source code: len=100000; SNR_db=0:2:8; for i=1:length(SNR_db) SNR=10.^(SNR_db/10); N0=1./SNR; NRZ_signal=randsrc(1,len); noise=sqrt(N0(i)).*randn(size(NRZ_signal)); r_signal=NRZ_signal+noise; NRZ_decoded=sign(r_signal); [Num,BER(i)]=symerr(NRZ_signal,NRZ_decoded); end semilogy(SNR_db,BER,'ro-'); xlabel('SNR(dB)'); ylabel('BER'); title('Ti le loi bit'); Bài 5.2: Source code: len=100000; SNR_db=0:2:8; for i=1:length(SNR_db) SNR=10.^(SNR_db/10); N0=1./SNR; NRZ_signal=randsrc(1,len); noise=sqrt(N0(i)).*randn(size(NRZ_signal)); r_signal=NRZ_signal+noise; NRZ_decoded=sign(r_signal); [Num,BER(i)]=symerr(NRZ_signal,NRZ_decoded); Pe=0.5*(1-erf(sqrt(SNR/2))); end semilogy(SNR_db,BER,'bo ',SNR_db,Pe,'r* ');%Ve thi tren cung he truc xlabel('SNR(dB)'); % Ten truc hoanh legend('ly thuyet','Thuc te'); % Tao chu thich title('Ti le loi bit'); % Ten thi Kết mô phỏng: VI Bài 6:Kỹ thuật điều chế số QPSK: Bài 6.1: Source code: len=500000; x=(randsrc(1,len)+1)/2; for i=1:2:length(x) switch x(i) case if x(i+1)==0 else end case if x(i+1)==0 else qpsk_signal((i+1)/2)=exp(j*pi/4); qpsk_signal((i+1)/2)=exp(j*3*pi/4); qpsk_signal((i+1)/2)=exp(j*7*pi/4); qpsk_signal((i+1)/2)=exp(j*5*pi/4); end end end Es=std(qpsk_signal).^2; %Tinh nang luong N0=Es/(10^(0/10)); % Cong suat tap am cua nhieu voi SNR = dB noise=sqrt(N0/2).*(randn(1,length(qpsk_signal)) +j.*randn(1,length(qpsk_signal))); qpsk_awgn=qpsk_signal + noise; % Tin hieu co nhieu plot(qpsk_awgn,'o'); title('SNR=0dB'); grid on; axis auto; xlabel('I'); ylabel('Q'); hold on; plot(qpsk_signal,'o'); t=0:0.01:2*pi; plot(exp(j*t),'k '); xlabel('I'); ylabel('Q'); title('Bieu chom cua tin hieu dieu che QPSK va tin hieu sau di qua kenh AWGN'); Kết mô phỏng: a SNR=0dB: b SNR=3dB: c SNR=6dB: VII Bài 7:Xác xuất lỗi bit điều chế QPSK: Source code: len = 50000; %Do dai bit SNR_bd = 0:2:8; SNR = 10.^(SNR_bd/10); bsignal = randint(1,len); %Tao dong bit ngau nhien for t=1:2:len switch bsignal(t) case if bsignal(t+1)==0 qpsk_signal((t+1)/2) = exp(j*3*pi/4); else qpsk_signal((t+1)/2) = exp(j*5*pi/4); end case if bsignal(t+1)==0 qpsk_signal((t+1)/2) = exp(j*pi/4); else qpsk_signal((t+1)/2) = exp(j*7*pi/4); end end end for k=1:length(SNR_bd) r_signal = awgn(qpsk_signal,SNR_bd(k)); %QPSK co nhieu for t=1:2:len if real(r_signal((t+1)/2))>=0 if imag(r_signal((t+1)/2))>=0 r_bsignal(t) = 1; r_bsignal(t+1) = 0; else r_bsignal(t) = 1; r_bsignal(t+1) = 1; end else if imag(r_signal((t+1)/2))>=0 r_bsignal(t) = 0; r_bsignal(t+1) = 0; else r_bsignal(t) = 0; r_bsignal(t+1) = 1; end end end [number,ratio] = biterr(bsignal,r_bsignal); BER(k) = ratio end Pb = 1/2.*erfc(sqrt(SNR/2)) plot(SNR_bd,Pb,'o-',SNR_bd,BER,'r'); title('Ty le loi bit ly thuyet va mo phong'); xlabel('SNR_bd'); ylabel('Pb'); legend('Ly thuyet','Mo phong'); Kết mô VIII Bài 8:Mô điều chế M- QAM qua kênh nhiễu Gauss Source code: n_sym = 50000; % So ki tu dieu che M = [16 32 64]; SNR_db = 0:25; BER = zeros(length(M),length(SNR_db)); for k=1:size(M,2) % Size(M,2): so cot cua M s_stream = randi([0 M(k)-1],1,n_sym); s_mod = qammod(s_stream,M(k),0,'GRAY'); % Dieu che tin hieu y for r=1:size(SNR_db,2) s_mod_awgn = awgn(s_mod,SNR_db(r),'measured');% y qua kenh nhieu s_demod = qamdemod(s_mod_awgn,M(k),0,'GRAY'); % Giai dieu che M-QAM [number,ts] = biterr(s_stream,s_demod); % Ty le loi bit BER(k,r) = ts end end semilogy(SNR_db,BER(1,:),'o-',SNR_db,BER(2,:),'b*-',SNR_db ,BER(3,:),'k.-'); grid on; title('Ty le loi bit dieu che M-QAM'); xlabel('SNR_bd'); ylabel('BER'); legend('M=16','M=32','M=64'); Kết mô phỏng:

Ngày đăng: 17/05/2016, 20:44

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan