www.pudn.com > SpacetimeMatlabCode.rar > detect.m, change:2004-03-24,size:2802b


function [data_est,state_est] = detect(sig_down,dlt,slt,ch_coefs) 
 
%************************************************************************** 
%DETECT Multidimensional data detector. 
%   D_E = DETECT(S,DLT,SLT,ALPHA) performs the maximum likelihood 
%   sequence estimation (MLSE) i.e. Viterbi algorithm on the received 
%   signal and returns the data estimations. The look-up tables DLT and 
%   SLT are used together with the external function BRANCH_METRIC which is 
%   called during the computation to evaluate branch metric,  
%   includes a channel complex path fadings. 
% 
%   [DATA_EST,STATE_EST] = DETECT(...) also returns a matrix including 
%   the track with most probable path in the code trellis. This matrix is 
%   required when the decoding process suppose to be displayed with 
%   DISPTRELL function.  
%************************************************************************** 
 
 
[step_final,space_dim,frames] = size(sig_down); 
[s,md,foo] = size(dlt); 
load qam16.txt; 
 
 
for k = 1:frames 
	% running multi-dimensional Viterbi algorithm 
	% make all starting paths unprobable except for the correct one 
	metric(1,2:s) = realmax; 
 
	for l = 1:step_final 
		for j = 1:s % current j 
		% finding all previous states s_pre leads to current sate j 
		[s_pre,foo] = find(slt == j); 
 
		% determining a pair position relevant to the state j 
		% {1,2,3,4,5,6,7,8} -> {1,2,3,4,1,2,3,4} 
		pos = mod(j - 1,md) + 1; 
 
		% picking-up the pairs corresponding to each of s_pre states 
		data_test = dlt(s_pre,pos,:); 
		data_test = reshape(data_test,[md 2]); 
 
		% mapping pairs to appropriate constellation 
		if md == 16 % 16QAM 
			for r = 1:2 
				k1(:,r) = qam16(data_test(:,r) + 1,1); 
				k2(:,r) = qam16(data_test(:,r) + 1,2); 
			end 
 
			q_test = (2 * k1 - md - 1) - i * (2 * k2 - md - 1); 
 
		else % 4,8PSK 
			expr = i * 2 * pi / md; 
			q_test = exp(expr * data_test); 
		end 
 
		% evaluating branch metric 
		metric_d = branch_metric(sig_down(l,:,k),q_test,ch_coefs(:,:,k)); 
 
		% adds the data_test metrices to the previous states 
		metric_md = metric(l,s_pre)' + metric_d; 
 
		% choosing a metric with lowest accumulated value 
		[metric_min,metric_pos] = min(metric_md); 
 
		% and storing it's value to the matrix of metrices 
		metric(l + 1,j) = metric_min; 
 
		% creates a states matrix of s_pre (with lowest metric) 
		vit_state(l + 1,j) = s_pre(metric_pos); 
 
		% creates a matrix of appropriate data_test 
		vit_data(l + 1,j) = pos - 1; 
		end 
	end 
 
	% finding the best path at the trellis end 
	[foo,state_best] = min(metric(end,:)); 
	state_est(step_final + 1) = state_best; 
 
	% back tracking 
	for l = step_final:-1:1 
		state_est(l) = vit_state(l + 1,state_est(l + 1)); 
		data_est(l,:,k) = vit_data(l + 1,state_est(l + 1)); 
	end 
end