www.gusucode.com > 均衡算法误码率对比源码程序 > 均衡算法误码率对比源码程序/Code/SphereDecoder.m

    function [Data_sphere] =  SphereDecoder(X_ZF_dB)
global ModulationScheme H Amp Y MM;
global x_probable UB_sym z m;
x_sol = [real(X_ZF_dB);
imag(X_ZF_dB)];
Y_real = [real(Y);imag(Y)]; %ZF input
H_real=[real(H) -1*imag(H);
imag(H) real(H)];
[n,m] = size(H_real);%Channel H
radius = norm(Y_real - H_real*x_sol);%Initial Radius
[Q,R]= qr(H_real);%QR Decomposition of Channel Matrix H

%After QR Decomposition some changes have to be made into the system like calculation of y-bar
y = Q'*Y_real; y_bar = zeros(size(y)); y_bar(end)=y(end);
x_probable = zeros(m,1);%Initializing vector for calculating of Radius 
k = m;
d_bar(k) = radius;% Setting of Level and radius of mth level
[UB_sym(k),x_probable(k)] = SphereBounds(R(k,k),d_bar(k),y_bar(k),k);%Setting Initial Bounds
z=1;%If z=1 search is still within bounds
while i ~= 0%Outer Loop  of  Search
    if  z~=0%If  upper Bound not exceeded 
        z=1;
        if  (k == 1)%If level-1 is reached find the radius for new symbol sequence 
            d_next = norm(y - R(1:m,:)*x_probable);
            %if new radius is less update radius and solution  
            if abs(d_bar(end)) >=  abs(d_next)  
                d_bar(end) = d_next;    x_sol = x_probable;
                [UB_sym,x_probable,d_bar]=SphereBoundsUpdate(UB_sym,x_probable,d_bar,y,R);
            end
            SphereSymChangeTest(k);%change the symbol for kth level if Upper Bound not reached
        else% Upper Bound not reached and Level higher than level-1 
            k=k-1;% Changing to go to lower level (level=level - 1);
            d_bar(k)=sqrt(abs(d_bar(k+1)^2-(y_bar(k+1)-R(k+1,k+1)*x_probable(k+1))^2 ));% Updating radius
            y_bar(k) =  y(k) - R(k,k+1:m)*x_probable(k+1:m);%update composite signal
            [UB_sym(k),x_probable(k)] = SphereBounds(R(k,k),d_bar(k),y_bar(k),k);% New level Bounds
        end
    else%If upper bound exceeded
        k = k+1;%Changing to higher level (level = level+1) ;
        if (k == m+1)%If highest level is reached store and break
            break
        else%If highest level not reached change symbols
            SphereSymChangeTest(k);%change the symbol for kth level if Upper Bound not reached
        end
    end
end
x_sol = x_sol(1:end/2)+i*(x_sol((end/2)+1:end)) ;
Data_sphere =ddemodce(x_sol/Amp,1,1,'qask',ModulationScheme(MM));