15
Bài thí nghim Thông Tin STrịnh Văn Hiệp – DTVT08-K54 – [email protected] 1 Bài s1 : Quá trình ngu nhiên ca tín hiu 1.1 Vhàm phân bxác sut Gauss a. Matlab code %ham phan bo xac suat Gauss m=0; sigma=1; x=-5:0.05:5; p=1/(sqrt(2*pi)*sigma)*exp(-(x-m).^2/(2*sigma^2)); plot(x,p); title('Ham phan bo xac suat Gauss'); b. Figure P X

Báo cáo thông tin số

Embed Size (px)

Citation preview

Page 1: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 1

Bài số 1: Quá trình ngẫu nhiên của tín hiệu 1.1 Vẽ hàm phân bố xác suất Gauss

a. Matlab code

%ham phan bo xac suat Gauss m=0; sigma=1; x=-5:0.05:5; p=1/(sqrt(2*pi)*sigma)*exp(-(x-m).^2/(2*sigma^2)); plot(x,p); title('Ham phan bo xac suat Gauss');

b. Figure

P P

X

Page 2: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 2

1.2 Mô phỏng quá trình ngẫu nhiên và tính hàm mật độ xác suất a. Matlab code

m=0; sigma=1; n=100000; x=-5:0.05:5; p=1/(sqrt(2*pi)*sigma)*exp(-(x-m).^2/(2*sigma^2)); y=randn(1,n); x2=-5:0.05:5; p1=hist(y,x2); stem(x2,p1/n/0.05); hold on; plot(x,p,'r'); title('Ham mat do phan bo xac suat n=100000'); xlabel('X'); ylabel('P'); hold off;

b. Figure

Hình 1. Hàm phân bố xác suất quá trình ngẫu nhiên với n=100000

P

Page 3: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 3

Hình 2 Hàm phân bố xác suất quá trình ngẫu nhiên với n=1000000

P

Page 4: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 4

Bài số 2 Mật độ phổ năng lượng và hàm tự tương quan của tín hiệu

Matlab code

Hàm tự tương quan

function [Rxx]=autom(x) % [Rxx]=autom(x) %Hàm tự tương quan của tín hiệu rời rạc x % Number of samples in x. N=length(x); Rxx=zeros(1,N); for m=1: N+1 for n=1: N-m+1 Rxx(m)=Rxx(m)+x(n)*x(n+m-1); end; end; Vẽ hàm tự tương quan và hàm mật độ phổ năng lượng

N=100000; n=[1:N]; x=randn(1,N); subplot(3,1,1); plot(n,x); title('Tin hieu ngau nhien'); xlabel('N'); ylabel('Amplitude'); grid; Rxx=autom(x); subplot(3,1,2); plot(Rxx); axis([0 10^5 -1000 1000]); grid; ttitle('Ham Tu tuong quan tin hieu ngau nhien'); xlabel('lags'); ylabel('Autocorrelation'); p=abs(fft(Rxx)); fx=(0:N/2-1)/N; subplot(3,1,3); plot(fx,20*log(p(1:N/2))); ttitle('Ham mat do pho nang luong'); xlabel('f'); ylabel('dB');

Page 5: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 5

Figure

Page 6: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 6

Bài số 3. Mã đường dây NRZ 3.1 Truyền dẫn số dùng mã hóa BPSK

a) Matlab code Hàm tính BER của BPSK

function BER=BPSK_map(n,bit,snr) %n- number of bit %bit-bit input %snr- Signal Noise Ratio %Mapping s=2*bit-1; %AWGN channel es=var(s); eb=es/2; n_0=eb/10^(snr/10); noise=sqrt(n_0/2)*(randn(size(s))+j*randn(size(s))); BPSK_receiver=s+noise; %De-mapping BPSK_de_mapping=[]; for i=1:n d1=(real(BPSK_receiver(i))-1)^2+imag(BPSK_receiver(i))^2;

d2=(real(BPSK_receiver(i))+1)^2+imag(BPSK_receiver(i))^2; BPSK_de_mapping=[BPSK_de_mapping (d1<=d2)]; end BER=sum(xor(bit,BPSK_de_mapping))/n; end Vẽ BER/SNR

n=50000; snr=[0:1:10]; bit=randn(1,n)>0.5; ber=[];p=[]; for i=1:length(snr) ber(i)=BPSK_map(n,bit,snr(i)); gamma_b(i)=10^(snr(i)/10); p(i)=0.5*(1-erf(sqrt(gamma_b(i))/sqrt(2))); end semilogy(snr,ber,'-',snr,p,'--'); legend('Mo phong','Ly thuyet'); title('BER/SNR'); xlabel('SNR'); ylabel('BER');

Page 7: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 7

b) Figure

Hình 1 BER/SNR truyền dẫn số dùng BPSK

Page 8: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 8

Hình 2: So sánh tỷ lệ BER/SNR lý thuyết và mô phỏng

Page 9: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 9

Bài số 4 Điều chế QPSK

3.1 Biểu đồ chòm sao QPSK

a. Matlab code

n=50000;

it=randint(1,n);

s=[]; for i=1:2:length(bit) if bit(i)==0&bit(i+1)==0 s((i+1)/2)=exp(j*pi/4); elseif bit(i)==0&bit(i+1)==1 s((i+1)/2)=exp(j*3*pi/4); elseif bit(i)==1&bit(i+1)==1 s((i+1)/2)=exp(j*5*pi/4); elseif bit(i)==1&bit(i+1)==0 s((i+1)/2)=exp(j*7*pi/4); end end plot(s,'*') hold on; t=0:0.01:2*pi; plot(exp(j*t),'r--'); xlabel('\phi(t)'); ylabel('S'); title('Bieu do chom sao QPSK');

b.Figure

Page 10: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 10

Hình 1 Biểu đồ chòm sao QPSK

4.2 Tín hiệu QPSK qua nhiễu trắng

snr_db=6; es=var(s); eb=es/2; n_0=eb/10^(snr_db/10); n=sqrt(n_0/2)*(randn(size(s))+j*randn(size(s))); r=s+n; t=0:0.01:2*pi; xlabel('\phi(t)'); ylabel('S'); title('Bieu do chom sao QPSK'); plot(r,'.') hold on plot(s,'r*'); hold on t=0:0.01:2*pi; plot(exp(j*t),'r--');

Page 11: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 11

Hình 2 Biểu đồ chòm sao QPSK qua nhiễu trắng SNR=6

Page 12: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 12

Hình 3 Biểu đồ chòm sao QPSK qua nhiễu trắng SNR=3

Page 13: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 13

Bài số 5. Mô phỏng hệ thống thông tin số

dùng QPSK a.Matlab code:

Hàm mã hóa và giải mã

function ber=QPSK_map(n,bit,snr) %n- number of bit %bit %snr-Signal Noise Ratio s=[]; for i=1:2:n if bit(i)==0&bit(i+1)==0 s((i+1)/2)=exp(j*pi/4); elseif bit(i)==0&bit(i+1)==1 s((i+1)/2)=exp(j*3*pi/4); elseif bit(i)==1&bit(i+1)==1 s((i+1)/2)=exp(j*5*pi/4); elseif bit(i)==1&bit(i+1)==0 s((i+1)/2)=exp(j*7*pi/4); end end es=var(s); eb=es/2; n_0=eb/10^(snr/10); noise=sqrt(n_0/2)*(randn(size(s))+j*randn(size(s))); r=s+noise; t=0:0.01:2*pi; d=[]; bit1=[]; a=[0 0 0 1 1 1 1 0]; for i=1:n/2 d(1)=(real(r(i))-real(exp(j*pi*1/4)))^2+(imag(r(i))-imag(exp(j*pi/4)))^2; m=1; for k=2:4 d(k)=(real(r(i))-real(exp(j*pi*(2*k-1)/4)))^2+(imag(r(i))-imag(exp(j*(2*k-1)*pi/4)))^2; if d(k)<=d(m) m=k; end end bit1=[bit1 a(2*m-1) a(2*m)];

Page 14: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 14

end ber=sum(xor(bit,bit1))/n end Kết quả

SNR 0 2 4 6 BER 0.064 0.028 0.0069 0.0012

Figure

Bài số 6. So sánh BER/SNR Matlab code

n=50000; snr=[0:1:10]; bit=randn(1,n)>0.5;

Page 15: Báo cáo thông tin số

Bài thí nghiệm Thông Tin Số

Trịnh Văn Hiệp – DTVT08-K54 – [email protected] 15

ber=[];p=[]; for i=1:length(snr) ber(i)=QPSK_map(n,bit,snr(i)); gamma_b(i)=10^(snr(i)/10); p(i)=erfc(sqrt(2*gamma_b(i))/sqrt(2))/2; end symilog(snr,ber,'-',snr,p,'--'); legend('Mo phong','Ly thuyet'); title('BER/SNR'); xlabel('SNR'); ylabel('BER'); Kết quả

SNR 0 2 4 6 BER (lý thuyết) 0.0786 0.0375 0.0125 0.0024 BER (mô phỏng) 0.064 0.028 0.0069 0.0012