You are on page 1of 12

PH LC

###################################################
Antenday.m (Tn hm chnh ca giao din m phng phn iu khin bp sng anten)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(Hm chy chng trnh trong phn 1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function chay_Callback(hObject, eventdata, handles)
global goc1 goc2 goc3 goc4 goc5 goc6 gocden N check1 check noise
global w gain a w1 w2 SNR
N=str2num(get(handles.soanten,'string'));
noise=str2num(get(handles.nhieu,'string'));
gocden=str2num(get(handles.gocden,'string'));
SNR=str2num(get(handles.editawgn,'string'));
SNR=10^(SNR/10);
if get(handles.but1,'value')==1
check=0;
elseif ((get(handles.but1,'value')==0)&(get(handles.but3,'value')==1))
check=1;
elseif ((get(handles.but1,'value')==0)&(get(handles.but3,'value')==0))
check=2;
end;
if (get(handles.but5,'value')==1)
check1=0;
elseif ((get(handles.but5,'value')==0)&(get(handles.but7,'value')==1))
check1=1;
elseif ((get(handles.but5,'value')==0)&(get(handles.but7,'value')==0))
check1=2;
end;
if (check1==0)
if (N==7)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
goc4=str2num(get(handles.goc4,'string'));
goc5=str2num(get(handles.goc5,'string'));
goc6=str2num(get(handles.goc6,'string'));
elseif (N==6)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
goc4=str2num(get(handles.goc4,'string'));
goc5=str2num(get(handles.goc5,'string'));
elseif (N==5)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
goc4=str2num(get(handles.goc4,'string'));
elseif(N==4)
goc1=str2num(get(handles.goc1,'string'));

goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
elseif (N==3)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
elseif (N==2)
goc1=str2num(get(handles.goc1,'string'));
end;
gocden=gocden*pi/180; %chuyen doi do sang radian
goc1=goc1*pi/180;
goc2=goc2*pi/180;
goc3=goc3*pi/180;
goc4=goc4*pi/180;
goc5=goc5*pi/180;
goc6=goc6*pi/180;
% Tao ma tran tin hieu va nhieu
for i=1:N
a0(i)=exp(-j*(i-1)*pi*sin(gocden));
a1(i)=exp(-j*(i-1)*pi*sin(goc1));
a2(i)=exp(-j*(i-1)*pi*sin(goc2));
a3(i)=exp(-j*(i-1)*pi*sin(goc3));
a4(i)=exp(-j*(i-1)*pi*sin(goc4));
a5(i)=exp(-j*(i-1)*pi*sin(goc5));
a6(i)=exp(-j*(i-1)*pi*sin(goc6));
end;
matran=[a0;a1;a2;a3;a4;a5;a6];
matran1=[];
for i=2:N
matran0(i-1,:)=matran(i,:);
end;
Rss0=a0'*a0;
Ruu0=zeros(N);
for i=1:N-1
Ruu0=Ruu0+matran0(i,:)'*matran0(i,:);
end;
% Giai he phuong trinh tuyen tinh, tinh ma tran phuong sai
for i=1:N
matran1(i,:)=matran(i,:);
end;
det0=det(matran1);
t=[];
t(1)=1;
for i=2:N
t(i)=0;
end;
t=transpose(t);
tg1=matran1;
for i=1:N
tg1(:,i)=t;
det1(i)=det(tg1);

tg1=matran1;
end;
% Tinh vector trong luong cua anten mang
w0=0;
for i=1:N
w0(i)=det1(i)/det0;
end;
end;
%%%%%%%%%%%%%%%%%%%
if (check1==1)|(check1==2)%%Tinh toan cho truong hop dung ky thuat MSINR
snrin1=SNR_in(N,noise,SNR);
set(handles.sinrin,'string',snrin1);
if (noise==6)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
goc4=str2num(get(handles.goc4,'string'));
goc5=str2num(get(handles.goc5,'string'));
goc6=str2num(get(handles.goc6,'string'));
elseif (noise==5)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
goc4=str2num(get(handles.goc4,'string'));
goc5=str2num(get(handles.goc5,'string'));
elseif (noise==4)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
goc4=str2num(get(handles.goc4,'string'));
elseif(noise==3)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
goc3=str2num(get(handles.goc3,'string'));
elseif (noise==2)
goc1=str2num(get(handles.goc1,'string'));
goc2=str2num(get(handles.goc2,'string'));
elseif (noise==1)
goc1=str2num(get(handles.goc1,'string'));
end;
gocden=gocden*pi/180; %chuyen do sang radian
goc1=goc1*pi/180;
goc2=goc2*pi/180;
goc3=goc3*pi/180;
goc4=goc4*pi/180;
goc5=goc5*pi/180;
goc6=goc6*pi/180;
% Tao ma tran tin hieu va nhieu
for i=1:N
a0(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(gocden));

a1(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(goc1));
a2(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(goc2));
a3(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(goc3));
a4(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(goc4));
a5(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(goc5));
a6(i,:)=exp(-sqrt(-1)*(i-1)*pi*sin(goc6));
end;
a00=transpose(a0);a11=transpose(a1);a22=transpose(a2);a33=transpose(a3);
a44=transpose(a4);a55=transpose(a5);a66=transpose(a6);
Rss=a0*a00;
if (noise==1)
Ruu=a1*a11;ax=a0+a1;
Rxx=a0*a00+a1*a11;
% r_xd=(a0+a1)*a00;
elseif (noise==2)
Ruu=a1*a11+a2*a22;ax=a0+a1+a2;
Rxx=a0*a00+a1*a11+a2*a22;
%r_xd=(a0+a1+a2)*a00;
elseif (noise==3)
Ruu=a1*a11+a2*a22+a3*a33;ax=a0+a1+a2+a3;
Rxx=a0*a00+a1*a11+a2*a22+a3*a33;
%r_xd=(a0+a1+a2+a3)*a00;
elseif (noise==4)
Ruu=a1*a11+a2*a22+a3*a33+a4*a44;ax=a0+a1+a2+a3+a4;
Rxx=a0*a00+a1*a11+a2*a22+a3*a33+a4*a44;
%r_xd=(a0+a1+a2+a3+a4)*a00;
elseif (noise==5)
Ruu=a1*a11+a2*a22+a3*a33+a4*a44+a5*a55;ax=a0+a1+a2+a3+a4+a5;
Rxx=a0*a00+a1*a11+a2*a22+a3*a33+a4*a44+a5*a55;
%r_xd=(a0+a1+a2+a3+a4+a5)*a00;
elseif(noise==6)
Ruu=a1*a11+a2*a22+a3*a33+a4*a44+a5*a55+a6*a66;ax=a0+a1+a2+a3+a4+a5+a6;
Rxx=a0*a00+a1*a11+a2*a22+a3*a33+a4*a44+a5*a55+a6*a66;
%r_xd=(a0+a1+a2+a3+a4+a5+a6)*a00;
end;
w2=inv(Rxx)*ax;
R=Rss*inv(Ruu);
[w1,d]=eigs(R);
max=d(1,1);t=1;
for aa=1:N %Tim gia tri rieng lon nhat
if (d(aa,aa)>max)
max=d(aa,aa);
t=aa;
end;
end;
w1=w1(:,t);%Vector rieng tuong ung voi gia tri rieng lon nhat
SINR1=(w1'*Rss*w1)/(w1'*Ruu*w1);
%set(handles.sinrout,'string',SINR1);
w1=transpose(w1);
end;

%%%%%%%%%%%%%%%%%%%%%
if check1==2 % Truong hop chon giai phap phan tap MMSE
w=transpose(w2);
elseif check1==1
w=w1;
set(handles.sinrout,'string',SINR1);
elseif check1==0
w=w0;
sinr_in0=sinr_in0(N,SNR);
set(handles.sinrin,'string',sinr_in0);
sinr_out0=w*Rss0*w'/(w*Ruu0*w');
set(handles.sinrout,'string',sinr_out0);
end;
%%%%%%%%%%%%%%%%%%%%%
% Tinh do loi gain cho tung goc den khac nhau
bieudo(w,check,N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
################################################
Bieudo.m (Hm v biu beam ca anten dy)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out=bieudo(w,check,N)
%global w check N
degree=linspace(0,360,240);
anpha=degree*pi/180;
a=[];
for n=1:length(anpha)
for m=1:N
a(n,m)=exp(-(sqrt(-1))*(m-1)*pi*sin(anpha(n)));
end;
end;
z=0;
gain=0;
for i=1:length(anpha)
z(i)=w*ctranspose(a(i,:));
x(i)=real(z(i));
y(i)=imag(z(i));
gain(i)=sqrt(x(i)*x(i)+y(i)*y(i));
end;
max=0;
for i=1:length(anpha)
if (gain(i)>max)
max=gain(i);
end;
end;
max=max+0.2;
% Ve bieu do gain
figure(1);
if (check==0)
plot(degree,gain,'r-');
grid on;

h=title('o thi bc xa cua anten day :');


set(h,'Fontname','VNi-Times');set(h,'Fontsize',14);
h1=xlabel('Goc en AOA (o)');set(h1,'Fontname','VNi-Times');set(h1,'Fontsize',14);
h2=ylabel('o li Gain (anten)');set(h2,'Fontname','VNi-Times');set(h2,'Fontsize',14);
axis([0 400 0 max]);
scala=0:50:360;
set(gca,'xtick',scala);
set(gca,'xticklabel',scala);
elseif (check==1)
polar(anpha,gain);
h=title('o th bc xa cua anten day dang bup song');
set(h,'Fontname','VNi-Times');set(h,'Fontsize',14);
end;
################################################

Khaosatber.m (Tn hm phn m phng ber h thng tri ph c s dng phn


tp)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Run1_callback() : Hm chy trong khaosatber .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function run1_Callback(hObject, eventdata, handles)
N=str2num(get(handles.edit4,'string'));
theta_s=str2num(get(handles.edit1,'string'));
theta_I1=str2num(get(handles.edit2,'string'));
theta_I2=str2num(get(handles.edit3,'string'));
INR1=str2num(get(handles.edit5,'string'));
INR2=str2num(get(handles.edit6,'string'));
SNR=[0:2:30];
D=[0:1:(N-1)].';
ns=length(SNR);
us=sin(theta_s*pi/180);
uI1=sin(theta_I1*pi/180);
uI2=sin(theta_I2*pi/180);
sigma_I1=10^(INR1/10);
sigma_I2=10^(INR2/10);
sigma_n=1;
vs=exp(-j*pi*D*us);
vI1=exp(-j*pi*D*uI1);
vI2=exp(-j*pi*D*uI2);
Rn=sigma_I1*vI1*vI1'+sigma_I2*vI2*vI2'+sigma_n*eye(N);
A=sqrt(sigma_I1*sigma_I1+sigma_I2*sigma_I2);
for n = 1:ns
sigma_s = 10^(SNR(n)/10);
Rs = sigma_s*vs*vs';
%vx=sqrt(sigma_s)*vs+sqrt(sigma_I1)*vI1+sqrt(sigma_I2)*vI2;
%Rx = Rs+Rn;
W_sinr=W_eigen(Rs,Rn);
W_mmse=W_MMSE(Rn,sigma_s,vs);
SINRopt(n)=sigma_s/(1+sigma_I1+sigma_I2);
SINRopt_sinr(n) = real(W_sinr'*Rs*W_sinr)/real(W_sinr'*Rn*W_sinr);
SINRopt_mmse(n) = real(W_mmse'*Rs*W_mmse)/real(W_sinr'*Rn*W_mmse);

end;
figure
h0=semilogy(SNR,SINRopt,'+-',SNR,SINRopt_sinr,'d-',SNR,SINRopt_mmse,'d-');
set(h0,'LineWidth',1.5)
hold on;
h=ylabel('SINR au ra')
set(h,'Fontname','VNi-Times','Fontsize',14);
h=xlabel('SNR au vao')
set(h,'Fontname','VNi-Times','Fontsize',14);
h=title('Khao sat SINR au ra theo SNR au vao');
set(h,'Fontname','VNi-Times','Fontsize',14);
h=legend('Khong phan tap','Ky thuat phan tap MSINR','Ky thuat phan tap
MMSE')
set(h,'Fontname','VNi-Times');
grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Khaosatber.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Run2_callback : chy chng trnh v biu ber
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function run2_Callback(hObject, eventdata, handles)
N=str2num(get(handles.edit4,'string'));
theta_s=str2num(get(handles.edit1,'string'));
theta_I1=str2num(get(handles.edit2,'string'));
theta_I2=str2num(get(handles.edit3,'string'));
INR1=str2num(get(handles.edit5,'string'));
INR2=str2num(get(handles.edit6,'string'));
SNR=[0:2:30];
D=[0:1:(N-1)].';
ns=length(SNR);
us=sin(theta_s*pi/180);
uI1=sin(theta_I1*pi/180);
uI2=sin(theta_I2*pi/180);
sigma_I1=10^(INR1/10);
sigma_I2=10^(INR2/10);
sigma_n=1;
vs=exp(-j*pi*D*us);
vI1=exp(-j*pi*D*uI1);
vI2=exp(-j*pi*D*uI2);
Rn=sigma_I1*vI1*vI1'+sigma_I2*vI2*vI2'+sigma_n*eye(N);
A=sqrt(sigma_I1*sigma_I1+sigma_I2*sigma_I2);
w0=1;Lc=32;
%%%%%%%%%%%%%%%%%%%%%%
for n = 1:ns
sigma_s = 10^(SNR(n)/10);
Rs = sigma_s*vs*vs';
%vx=sqrt(sigma_s)*vs+sqrt(sigma_I1)*vI1+sqrt(sigma_I2)*vI2;
%Rx = Rs+Rn;
W_sinr=W_eigen(Rs,Rn);
W_mmse=W_MMSE(Rn,sigma_s,vs);

SINRopt(n)=sigma_s/(1+sigma_I1+sigma_I2);
SINRopt_sinr(n) = real(W_sinr'*Rs*W_sinr)/real(W_sinr'*Rn*W_sinr);
SINRopt_mmse(n) = real(W_mmse'*Rs*W_mmse)/real(W_sinr'*Rn*W_mmse);
Aout1=(1+A)*SINRopt(n)/SINRopt_sinr(n)-1;
Aout2=(1+A)*SINRopt(n)/SINRopt_mmse(n)-1;
SINRopt_mmse(n)=real(W_mmse'*Rs*W_mmse)/real(W_mmse'*Rn*W_mmse);
a0(n)=ber_traipho(SNR(n),Lc,A,w0);
a1(n)=ber_traipho(SNR(n),Lc,Aout1,w0);
a2(n)=ber_traipho(SNR(n),Lc,Aout2,w0);
end;
figure;
semilogy(SNR,a0,'+-',SNR,a1,'d-',SNR,a2,'+-');
hold on;
grid on;
h=title('Gian o ber tn hieu trai pho');
set(h,'Fontsize',14,'Fontname','VNi-Times');
h=legend('Ber trai pho','Ber trai pho + phan tap MSINR','Ber trai pho + phan
tap MMSE');
set(h,'Fontname','VNi-Times');
h=ylabel(' Ty le loi bit BER');
set(h,'Fontname','VNi-Times','Fontsize',14);
xlabel ('SNR');
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton4_Callback(hObject, eventdata, handles)
bertraipho
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Khaosatber.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ber]=ber(snr_db,Lc,A,w0)
snr=10^(snr_db/10);
sgma=1;Eb=2*sgma^2*snr;
E_chip=Eb/Lc;
N=10000;
err=0;
for i=1:N
temp=rand;
if (temp<0.5)
data=-1;
else
data=1;
end;
for j=1:Lc
repeat_data(j)=data;
end;
for j=1:Lc
temp=rand;
if (temp<0.5)
pn_sq(j)=-1;

else
pn_sq(j)=1;
end;
end;
trans_sig=sqrt(E_chip)*repeat_data.*pn_sq;
noise=sgma*randn(1,Lc);
n=(i-1)*Lc+1:i*Lc;
interference=A*sin(w0*n);
rece_sig=trans_sig+noise+interference;
temp=rece_sig.*pn_sq;
decision=sum(temp);
if (decision<0)
decision=-1;
else
decision=1;
end;
if (decision~=data)
err=err+1;
end;
end;
ber=err/N;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SISO.m Hm thc hin kho st cht lng cc b t hp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%
SignalEnergyMin = 4;
SignalEnergyMax = 52;
SignalEnergy_d = 1;
BlocksPerEnergy = 200;
BlockSize = 2^8;
SamplingRate = 1;
WGNPower = 1;
RayleighParam = .24;
Antennas = 2;
M=16;
for aa=1:Antennas
Gvec1 = randn(1,BlocksPerEnergy);
Gvec2 = randn(1,BlocksPerEnergy);
RayleighVec(aa,:) = sqrt((RayleighParam^2.*Gvec1.^2)+(RayleighParam^2.*Gvec2.^2));
end
EnergiesdB = SignalEnergyMin:SignalEnergy_d:SignalEnergyMax;
Energies = 10.^(EnergiesdB./10);
for ee = 1:size(Energies,2)
for bb = 1:BlocksPerEnergy
A = randint(1,BlockSize,16); % Generate Data Stream
B = mod16qam (A,1,SamplingRate,Energies(ee))'; % 16-QAM Modulation
for aa=1:Antennas
disp(['Eb = ',int2str(Energies(ee)),'; Block ',int2str(bb),'; Antenna ',int2str(aa)]);
C(aa,:) = RayleighVec(aa,bb).*B; % Nhan nhieu Rayleigh fading

D(aa,:) = AWGN(C(aa,:),WGNPower); % Cong nhieu AWGN


[E(aa,:),Es(aa,bb)] = demod16qam (D(aa,:),1,SamplingRate); % Dieu che 16-QAM
[TT,SER(aa,bb)] = symerr(A,E(aa,:)); % Do SER tren moi antenna
end
% Bo to hop chon loc (Selective Combining)
stronger = (find (Es(:,bb) == max (Es(:,bb))));
[SC,E_sc(1,bb)] = demod16qam (D(stronger,:),1,SamplingRate);
[TT,SER_sc(bb)] = symerr(A,SC); % Do SER tren moi antenna
% Bo to hop cung do loi (Equal Gain Combining)
[EGC,E_egc(1,bb)] = demod16qam (mean(D,1),1,SamplingRate);
[TT,SER_egc(bb)] = symerr(A,EGC); % Do SER trn moi antenna
% Bo to hop ty so toi da (Maximal Ratio Combining)
for aa=1:Antennas
r(aa) = sqrt(Es(aa,bb)/Energies(ee));
end
for aa=1:Antennas
a(aa) = r(aa)/sum(sqrt(r));
end
[MRC,E_mrc(1,bb)] = demod16qam (r(1)*D(1,:)+r(2)*D(2,:),1,SamplingRate);
[TT,SER_mrc(bb)] = symerr(A,MRC); % Do SER tren moi antenna
end
for aa=1:Antennas
ESER(aa,ee) = mean(SER(aa,:),2);
end
ESER_sc(ee) = mean(SER_sc,2);
ESER_egc(ee) = mean(SER_egc,2);
ESER_mrc(ee) = mean(SER_mrc,2);
end
figure;
semilogy(EnergiesdB,mean(ESER,1),'+',EnergiesdB,ESER_sc(1,:),'d',EnergiesdB,ESER_e
gc(1,:),'d',EnergiesdB,ESER_mrc(1,:),'d');
h=title ('\fontsize{10}\bfAnten thch nghi (16-QAM): \rm2 Tn hieu thu vi cong suat
xac nh(Kenh Rayleigh AWGN cham)');
set(h,'Fontname','VNi-Times');
h=legend('\fontsize{10}\bfAntenna 1+2','Bo to hp SC','Bo to hp EGC','Bo to
hp MRC');
set(h,'Fontname','VNi-Times');
xlabel ('Eb/N_0'); ylabel ('SER');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Tongquan.m ( Hm chy giao din chnh phn 4 : ng dng phn tp trong h thng
WCDMA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function chay_Callback(hObject, eventdata, handles) (Hm chy trong Tongquan.m)
global in_code out_code sobit n k g datatomod fd fs fc PN spread check_awgn snr sir noise
fs fd fc bitsai
n=2;k=1;g=[5 2];
fd=str2num(get(handles.Fd,'string'));
fs=str2num(get(handles.Fs,'string'));
fc=str2num(get(handles.Fc,'string'));
mary=get(handles.kieudieuche,'value');

mary=2^mary;
sir=str2num(get(handles.sir,'string'));
kieumahoa=get(handles.mahoa1,'value');
kieuvao=get(handles.kieutinhieuvao,'value');
noise=str2num(get(handles.nhieu,'string'));
check_awgn=get(handles.check_awgn,'value');
if check_awgn==1
snr=str2num(get(handles.edit4,'string'));
end;
%thong so trai pho
factor=get(handles.factor,'value');
if (factor==1)
spread=32;
elseif (factor==2)
spread=256;
end;
PN=randint(1,spread);%chuoi ma trai pho
switch (kieuvao)
case 1
in_code=get(handles.dulieuvao,'string');
sobit=length(in_code);
set(handles.sobitvao,'string',sobit);
for i=1:length(in_code)
in(i)=str2num(in_code(i));
end;
in_code=in;
case 2
sobit=str2num(get(handles.sobitvao,'string'));
in_code=randbits(sobit(1,1));
set(handles.dulieuvao,'string',bittostr(transpose(in_code)));
end;
temp_in=in_code;
switch kieumahoa
case 1
out_code=makhoi(temp_in,n,k,g);
case 2
out_code=macuon(temp_in);
end;
temp=transpose(out_code);
set(handles.chuoiphat,'string',bittostr(temp));
datarow=mattorow(out_code);
out_traipho=traipho(datarow,PN);
Am=10^(-sir/20);
inter=randint(1,length(out_traipho));
a=dieuche(inter,mary);
out_mod=dieuche(out_traipho,mary);
Eb=var(out_mod)/2;
N_0=Eb/10^(snr/10);
N0=sqrt(N_0/2)*(randn(size(out_mod))+j*randn(size(out_mod)));
inter1=(Eb/spread)*(randn(size(out_mod))+j*randn(size(out_mod)));len=length(out_mod);

out_mod=out_mod+N0+inter1;
out_demod=giaidieuche(out_mod,mary);
out_giaitraipho=giaitraipho(out_demod,PN);
switch kieumahoa
case 1
out_decode=decode(out_giaitraipho,n,k,'convol',g);
case 2
out_decode=giaimacuon(out_giaitraipho);
end;
set(handles.Tinhieura,'string',bittostr(transpose(out_decode)));
bitsai=0;
for i=1:length(out_decode)
if (out_decode(i,:)~=in_code(i))
bitsai=bitsai+1;
end;
end;
set(handles.sobitloi,'string',bitsai);
ber=bitsai/length(in_code);
set(handles.ber,'string',ber);
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%

You might also like