?? lsb_error_new.m
字號:
function [err_value] = lsb_error_new(theta_input_vector, snr)% This function calculates the BER for the LSB.theta_input_vector;n=length(theta_input_vector);%if(n>2)bound_vector=zeros(n-1, 1);for i=1:n-1 bound_vector(i,1)=theta_input_vector(i,1);end% Creating Boundaries%bound=zeros(2^(n-1),1);a=zeros(2^(n),1);%b=zeros(2^(n),1);x=1; y=1;for i=2^(n-2):2^(n-1)-1 index=i; mult=zeros(1, n-1); for j=n-1:-1:1 mult(1,j)=2*mod(index,2)-1; index=floor(index/2); end; a(i+1-2^(n-2),1)=mult*bound_vector; % if(mult(n-1,1)==1) % b(x,1)=bound_vector*mult; % x=x+1; % else % a(y,1)=bound_vector*mult; % y=y+1; % end;end;%x%%yfor i=1:2^(n-2) a(i+2^(n-2),1)=pi-(a(2^(n-2)+1-i,1)); % b(i+2^(n-2),1)=pi-(b(2^(n-2)+1-i,1));end;for i=2^(n-1)+1:3*2^(n-2) a(i,1)=a(i-2^(n-1),1)-pi; % b(i,1)=b(i-2^(n-1),1)-pi;end;for i=1:2^(n-2) a(i+3*2^(n-2),1)=-a(2^(n-2)+1-i, 1);% b(i+3*2^(n-2),1)=-b(2^(n-2)+1-i, 1);end;%%%%% Vectors a and b are ready. Now calculate the actual phi vectors.phi=zeros(2^(n+1), 1);phi_0=zeros(2^(n), 1);phi_1=zeros(2^(n), 1);%x=1;y=1;for i=2^(n-1):2^(n)-1 index=i; mult=zeros(1,n); for j=n:-1:1 mult(1,j)=2*mod(index,2)-1; index=floor(index/2); end;% if(mult(n,1)==1)% phi_1(x,1)=theta_input_vector*mult;% x=x+1;% else% phi_0(y,1)=theta_vector*mult;% y=y+1;% end; theta_input_vector;mult; phi(i+1-2^(n-1),1)=mult*theta_input_vector;end;for i=1:2^(n-1) phi(i+2^(n-1),1)=pi-phi(2^(n-1)+1-i,1);% phi_1(i+2^(n-2),1)=pi-phi_1(i,1);end;for i=1:2^(n) phi(i+2^(n), 1)=-phi(2^(n)+1-i, 1);end;phi_0(1,1)=phi(1,1);x=2;y=1;while(x < 2^(n+1)-2) phi_1(y,1)=phi(x,1); phi_1(y+1,1)=phi(x+1,1); phi_0(y+1,1)=phi(x+2,1); phi_0(y+2,1)=phi(x+3,1); x=x+4; y=y+2;end;phi_1(y,1)=phi(x,1);phi_1(y+1,1)=phi(x+1,1);phi_0(y+1,1)=phi(x+2,1);a;phi;phi_0;phi_1;%%%%% Now the phi vectors are ready. Calculate the Errorerr=0;for j=1:1:2^(n) for i=1:2:2^(n)-1 err=err+F_func(snr, a(i+1,1)-phi_0(j,1))-F_func(snr, a(i,1)-phi_0(j,1)); end; err;end;for j=1:1:2^n for i=2:2:2^(n)-1 err=err+(F_func(snr,a(i+1,1)-phi_1(j,1))-F_func(snr,a(i,1)-phi_1(j,1))); end; err=err+F_func(snr,a(1,1)-phi_1(j,1))-F_func(snr,a(2^n,1)-phi_1(j,1)); err;end; %else %err=F_func(snr, -theta_input_vector(2))+F_func(snr, pi-theta_input_vector(2)) + 0.5*(F_func(snr, 2*theta_input_vector(1)+theta_input_vector(2))-F_func(snr, pi-2*theta_input_vector(1)-theta_input_vector(2)))-0.5*(F_func(snr, 2*theta_input_vector(1)-theta_input_vector(2))-F_func(snr, pi-2*theta_input_vector(1)+theta_input_vector(2))); %end; err_value=err/(2^(n+1));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -