Professional Documents
Culture Documents
Lớp:KM17
MSSV:1751150033
GVHD:Nguyễn Thị Bé Tám
ỨNG DỤNG MATLAB TRONG KĨ THUẬT TRUYỀN SỐ LIỆU
I) CƠ SỞ LÝ THUYẾT:
1. Line coding:
Là quá trình chuyển đổi dữ liệu số sang các tín hiệu số. Bằng kỹ thuật này chúng ta chuyển đổi
một chuỗi các bit sang một tín hiệu số. Ở phía người người gửi dữ liệu số được mã hóa thành tín
hiệu số và ở phía người nhận những dử liệu số được tái tạo lại bằng cách giải mã các tín hiệu số.
Figure 1.2:
PSK
clc;
clear all;
close all;
n=8;
x=randi([0,1],1,n); %random bit
generator
bp=.000001; % bit
period
disp(' Binary information at Trans mitter :');
disp(x);
% representation of transmitting binary information as digital signal
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(4,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volts)');
xlabel(' time(sec)');
title('Binary data in the form of a digital signal');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-PSK modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXX
A=5; % Amplitude of carrier
signal
br=1/bp; % bit
rate
f=br*2; % carrier
frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
kl=[];
for i=1:1:length(x)
wave=A*sin(2*pi*f*t2);
kl=[kl wave];
end
for i=1:1:length(x)
if (x(i)==1)
y=A*sin(2*pi*f*t2);
else
y=A*sin(2*pi*f*t2+pi); %-A*sin(2*pi*f*t)
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(4,1,2);
plot(t3,kl);grid on;
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('Carrier Signal');
subplot(4,1,3);
plot(t3,m);grid on;
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('PSK modulated wave coresponding to binary information at the
transmitter');
%XXXXXXXXXXXXXXXXXXXX Binary PSK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=sin(2*pi*f*t); % carrier
siignal
mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm); %
intregation
zz=round((2*z/bp));
if(zz>0) % logic level =
(A+A)/2=0
%becouse A*sin(2*pi*f*t+pi) means -
A*sin(2*pi*f*t)
a=1;
else
a=0;
end
mn=[mn a];
end
disp(' Binary data at Reciver :');
disp(mn);
%Representation of binary information as digital signal which is
acheived
%after PSK demodulation
bit=[];
for n=1:length(mn)
if mn(n)==1;
se=ones(1,100);
else
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(4,1,4);
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('PSK demodulated wave corresponding to binary information at the
receiver ');
QAM
% n_bits: Input, number of bits
% M: Input, constellation size
% EbNodB: Input, energy per bit to noise power spectral density
% ber: Output, bit error rate
% Copyright RAYmaps (www.raymaps.com)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[ber]= QAM_fading(n_bits, M, EbNodB)
% Transmitter
k=log2(M);
EbNo=10^(EbNodB/10);
x=transpose(round(rand(1,n_bits)));
h1=modem.qammod(M);
h1.inputtype='bit';
h1.symbolorder='gray';
y=modulate(h1,x);
% Channel
Eb=mean((abs(y)).^2)/k;
sigma=sqrt(Eb/(2*EbNo));
w=sigma*(randn(n_bits/k,1)+1i*randn(n_bits/k,1));
h=(1/sqrt(2))*(randn(n_bits/k,1)+1i*randn(n_bits/k,1));
r=h.*y+w;
% Receiver
r=r./h;
h2=modem.qamdemod(M);
h2.outputtype='bit';
h2.symbolorder='gray';
h2.decisiontype='hard decision';
z=demodulate(h2,r);
ber=(n_bits-sum(x==z))/n_bits
return
AM
clc;
close all;
clear all;
%XXXXXXXXXXXXXXXXXXXXXXXXXXX Define AM modulation Index
XXXXXXXXXXXXXXXXXXX
disp(' example: m=1 means 100% modulation');
%m=input(' Enter the value of modulation index (m) = ');
m=1; % for 100% modulation
if (0>m||m>1)
error('m may be less than or equal to one and geter than to zero');
end
%XXXXXXXXXXXXXXXXX modulating signal generation
XXXXXXXXXXXXXXXXXXXXXXXXXX
Am=5; % Amplitude of modulating signal
fa=2000; % Frequency of modulating signal
Ta=1/fa; % Time period of modulating signal
t=0:Ta/999:6*Ta; % Total time for simulation
ym=Am*sin(2*pi*fa*t); % Eqation of modulating signal
figure(1)
subplot(3,1,1);
plot(t,ym), grid on;% Graphical representation of Modulating signal
title ( ' Modulating Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
%XXXXXXXXXXXXXXXXXXXXX carrier signal generation
XXXXXXXXXXXXXXXXXXXXXXXXXX
Ac=Am/m;% Amplitude of carrier signal [ where, modulation Index
(m)=Am/Ac ]
fc=fa*10;% Frequency of carrier signal
Tc=1/fc;% Time period of carrier signal
yc=Ac*sin(2*pi*fc*t);% Eqation of carrier signal
subplot(3,1,2);
plot(t,yc), grid on;% Graphical representation of carrier signal
title ( ' Carrier Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX AM Modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
y=Ac*(1+m*sin(2*pi*fa*t)).*sin(2*pi*fc*t); % Equation of Amplitude
%modulated signal
subplot(3,1,3);
plot(t,y);% Graphical representation of AM signal
title ( ' Amplitude Modulated signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
grid on
FM
clc
clear all
close all
t = 0:255;
t = t/256;
f = 2;
fc = 20;
beta = 5;
m = sin(2*pi*f*t);
xc = cos(2*pi*fc*t + beta*m);
figure(6)
plot (t,xc)
figure(4)
.
t = 0:255;
t = t/256;
f = 2;
fc = 20;
beta = 2;
m = sin(2*pi*f*t);
xc = cos(2*pi*fc*t + beta*m);
fo = zeros(1,256);
ff = zeros(1,256);
ff = fc + 4*cos(2*pi*f*t);
x = zeros(1,256);
disc = zeros(1,256);
fo(1) = 20;
for i=1:256
disc(i) = 2*pi*fc*t(i) + beta*m(i) - 2*pi*fo(i)*t(i);
if (i ~= 1)
x(i) = (disc(i) - disc(i-1))*256/(2*pi);
else
x(i) = disc(i)*256/(2*pi);
end;
if (i ~= 256)
fo(i+1) = fc + 0.001*x(i);
end;
end;
subplot(2,1,1)
plot(t,disc);
ylabel('Discriminator');
title('Output of Discrminator');
subplot(2,1,2)
plot(t,x);
ylabel('x');
title('Adjustment to VCO');
PM