Professional Documents
Culture Documents
Báo cáo thí nghiệm thông tin số
Báo cáo thí nghiệm thông tin số
Bài 1.1:
Source code:
x=-5:0.1:5;
Px=(1/sqrt(2*pi)*exp(-x.^2/2));
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
Source code:
Bài 2.1:
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 =
1 3 1 7 0
xq =
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 2 do thi tren cung 1 he truc
grid on ;
% Bat luoi do 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 do thi
Source code:
N =1000;
x_uni = 2*rand(1, N)-1;
% x_uni phan bo tu -1 den 1
x_sin = sin(linspace(1,5,N));
% Tin hieu sin
nbit = 1 :10;
% so bit luong tu tu 1 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; % Tinh
sai so
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 3 do 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
IV. Bài 4: Mật độ phổ năng lượng và hàm tự tương quan của tín hiệu:
Bài 4.1:
Source code:
L=500;
x=randn(1,L);
x1=linspace(-1,1,L) %Bien do tang dan
x2=sin(linspace(-10,10,L)) % Tin hieu hinh sin
[n y]=xcorr(x);
figure(1);
subplot(2,2,1) % 2 hang, 2 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) % 2 hang, 2 cot, o thu 2
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) % 2 hang, 2 cot, o thu 3
stem(y2,n);
title('Do thi ham tu tuong quan cua x2=sin(linspace(-
10,10,L))');
xlabel('n');
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 do 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');
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 2 do 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 do thi
Bài 6.1:
Source code:
len=500000;
x=(randsrc(1,len)+1)/2;
for i=1:2:length(x)
switch x(i)
case 0
if x(i+1)==0
qpsk_signal((i+1)/2)=exp(j*pi/4);
else
qpsk_signal((i+1)/2)=exp(j*3*pi/4);
end
case 1
if x(i+1)==0
qpsk_signal((i+1)/2)=exp(j*7*pi/4);
else
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 =
0 dB
noise=sqrt(N0/2).*(randn(1,length(qpsk_signal))+j.*randn(1
,length(qpsk_signal)));
qpsk_awgn=qpsk_signal + noise; % Tin hieu khi 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 do chom sao cua tin hieu dieu che QPSK va tin
hieu sau khi di qua kenh AWGN');
a. SNR=0dB:
b. SNR=3dB:
c. SNR=6dB:
VII. Bài 7: Xác xuất lỗi bit trong điều chế QPSK:
Source code:
Source code: