# MATLAB代做|FPGA代做|Python代做--球形译码

### 时间：2019-1-5 15:19:16 点击：

核心提示：MATLAB代做|FPGA代做|Python代做--球形译码...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tittle: Sphere decoding
% Date: Nov 12, 2007
% Author: ........
% .......
% ........
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [sHat,dist] = sphere(m,sMax,x,H,d,cplx)
% Sphere decoding estimate arg min ||x - Hs||^2
% m is input y 's dimension, that is, the decoded symbol number
% sMax is the maximum value of possible transmitter symbol
% x is pertubed signal
% H is Channel transfer matric
% cplx shows the complex system or real system 0 for real, 1 for complex
% d is the radius of sphere centered at x
% some global definition

%global sHat;    % the estimation value of s (transfered signals)
%global dist;    % the distance from s to x
%global counter; % counter the No. of solution

counter = 1;
sHat = [];
dist = [];

% A small number
EPS = 0.001;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Basic error checking
% make sure the input is correct
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% make sure H's column no. equals m
[n,mChk] = size(H);
if n ~= length(x) || mChk ~= m   % input pertubed data dim is not the same as the column of H
fprintf('Error: Decoding failed, invalid dimensions for H. (n < m)\n');
return;
end

% n should be no less than m
if n < m
fprintf('Error: Cannot solve under-determined problem, n (%i) < m (%i).\n', n, m);
return;
end

% define the lattice (spanned by the modulation pattern)
if length(sMax) == 1
sMax = [-sMax:-1, 1:sMax];
elseif size(sMax,2) == m  % this is for complexed expression.
sMax = sMax.';          % such as{1+j, 1-j, -1-j, 1-j}
elseif size(sMax,1) ~= m
fprintf('Error: Decoding failed, invalid dimensions for xMax.\n');
return;
end

% Complex -> real conversion if necessary
if cplx == 1
m = 2*m;
n = 2*n;
x = [real(x);imag(x)];
H = [[real(H),imag(H)];[-imag(H),real(H)]]; % refer to the paper "MIMO Receive Algorithms"
if isreal(sMax)
sMax = [sMax;sMax]';
else
sMax = [real(sMax);imag(sMax)]';
end
end

% Special handling to allow xMax == 0
noBCind = find(sMax==0);
sMax(noBCind) = Inf; % when xMax ==0, set it as infinite

% Q R factorization
[Q,R] = qr(H);
r = R; % compatible with Babak Hassibi and Haris Vikalo's paper
Q2X = 0;    % R is an uper triangular matrix without eigenvalue of zero
QX = Q'*x;  % QX = Q'* X = [Q1 Q2]'*X = [Q1*X Q2*X] = [y Q2*X]
y = QX(1:m); % y = Q1*X
if m < n
r = R(1:m, 1:m); % compatible with Babak Hassibi and Haris Vikalo's paper
Q2X = QX(m+1:n);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% preprocessing ends here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% search the tree and find the estimation of s
% sphere decoding begin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% defining some variables
dp   = zeros(m,1); % d primary (d')
yres = zeros(m+1,m+1);  % the residue of the equaltion yk|k+1
s = zeros(m,1); % s is the estimate symbols
% defining some variables

% initialization (step 1)
k = m;    %  denoting the k level tree m is the column of H
dp(m) = d^2 - norm(Q2X,2)^2;
yres(k,k+1) = y(m);
% step 1 ends

% initial the root bound
if r(k,k) > 0
UB(k) = floor( (dp(k) + yres(k,k+1)) / r(k,k) );
s(k)  = ceil( (-dp(k)+yres(k,k+1)) / r(k,k) ) - 1;
elseif r(k,k) < 0
UB(k) = floor( (-dp(k)+yres(k,k+1)) / r(k,k) );
s(k)  = ceil( (dp(k) + yres(k,k+1)) / r(k,k) ) - 1;
else
fprintf('Error: Oh, man, the diagonal element of R should bu nonzero.\n');
end
% initialization ends

%searching the sphere begins
while k<=m
% step 3 begins
s(k) = s(k) + 1;  % sk + 1 begin to search the tree
if s(k) <= UB(k)  % step 3 condition holds
% step 5 begins
if (~(size(find(sMax==s(k)),2)==0))
if(k ~= 1)
% step 5 condition holds
% ------> should go to step 2
k = k - 1;
yres(k,k+1) = y(k) - sum( r(k,k+1:m)*s(k+1:m) );  % the residue
dp(k) = dp(k+1) - ( yres(k+1,k+2) - r(k+1,k+1)*s(k+1) )^2;
% ------> should go to step 2

% step 2 ends ------> should go to step 3
%           UB(k) = floor( (dp(k) + yres(k,k+1)) / r(k,k) );
%           s(k)  = ceil( (-dp(k)+yres(k,k+1)) / r(k,k) ) - 1;
if r(k,k) > 0
UB(k) = floor( (dp(k) + yres(k,k+1)) / r(k,k) );
s(k)  = ceil( (-dp(k)+yres(k,k+1)) / r(k,k) ) - 1;
elseif r(k,k) < 0
UB(k) = floor( (-dp(k)+yres(k,k+1)) / r(k,k) );
s(k)  = ceil( (dp(k) + yres(k,k+1)) / r(k,k) ) - 1;
else
fprintf('Error: Oh, man, the diagonal element of R should be nonzero.\n');
end
% step 2 ends ------> should go to step 3
else % step 5 condition doesn't holds
% step 6 begins ------> should go to step 3
sHat(counter,:) = s'; % output one group of solution;
dist(counter) = dp(m)-dp(1) + (y(1) - sum(r(1,1:m)*s(1:m)))^2; % output the distance s from x
counter = counter + 1;
% step 6 ends ------> should go to step 3
end
% step 5 end
end
else
% step 4 begins
k = k + 1;
if(k == m + 1)
break;
end
end
%setp 3 ends
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sphere decoding ends
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

return

QQ ：1224848052

• 百度搜索