You are on page 1of 15

Bi th nghim Thng Tin S

Bi s 1: Qu trnh ngu nhin ca tn hiu


1.1 V hm phn b xc 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

PP

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S


1.2 M phng qu trnh ngu nhin v tnh hm mt xc sut
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

Hnh 1. Hm phn b xc sut qu trnh ngu nhin vi n=100000

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Hnh 2 Hm phn b xc sut qu trnh ngu nhin vi n=1000000

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Bi s 2 Mt ph nng lng v
hm t tng quan ca tn hiu
Matlab code
Hm t tng quan
function [Rxx]=autom(x)
% [Rxx]=autom(x)
%Hm t tng quan ca tn hiu ri rc 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 hm t tng quan v hm mt ph nng lng


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

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Figure

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Bi s 3. M ng dy NRZ
3.1 Truyn dn s dng m ha BPSK
a) Matlab code
Hm tnh BER ca 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');

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

b) Figure

Hnh 1 BER/SNR truyn dn s dng BPSK

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Hnh 2: So snh t l BER/SNR l thuyt v m phng

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Bi s 4 iu ch QPSK
3.1 Biu chm 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

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

Bi th nghim Thng Tin S

Hnh 1 Biu chm sao QPSK


4.2 Tn hiu QPSK qua nhiu trng
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--');

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

10

Bi th nghim Thng Tin S

Hnh 2 Biu chm sao QPSK qua nhiu trng SNR=6

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

11

Bi th nghim Thng Tin S

Hnh 3 Biu chm sao QPSK qua nhiu trng SNR=3

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

12

Bi th nghim Thng Tin S

Bi s 5. M phng h thng thng tin s


dng QPSK
a.Matlab code:
Hm m ha v gii 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)];
Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

13

Bi th nghim Thng Tin S


end
ber=sum(xor(bit,bit1))/n
end

Kt qu
SNR
BER

0
0.064

2
0.028

4
0.0069

6
0.0012

Figure

Bi s 6. So snh BER/SNR
Matlab code
n=50000;
snr=[0:1:10];
bit=randn(1,n)>0.5;
Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

14

Bi th nghim Thng Tin S


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

Kt qu
SNR
BER (l thuyt)
BER (m phng)

0
0.0786
0.064

2
0.0375
0.028

Trnh Vn Hip DTVT08-K54 trinhhiepth@gmail.com

4
0.0125
0.0069

6
0.0024
0.0012

15

You might also like