📄 st_trellis_dec.m
字号:
function outputs = ... st_trellis_dec(Data_received,ST_NextState,ST_Output,Lut_InfBits,ModMap,... alpha_channel,fading_gains,TerminateF,SF,NRx);%------------------------------------------------------------------------------% Decode received space-time trellis coded data matrix.%% Format:% -------%% outputs = ...% st_trellis_dec(Data_received,ST_NextState,ST_Output,Lut_InfBits,ModMap,...% alpha_channel,fading_gains,TerminateF,SF,NRx)% % Author: MVe% Date: 27.08.2002%------------------------------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -- Initialisations -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Length of the received symbol/data vectorLData = length(Data_received);% Extract most used variables from struct 'Trellis'n = size(ST_Output{1,1},2); % # of outputs/antennak_bits = log2(size(ST_NextState,2)); % # input bits to encoderm_bits = log2(size(ST_NextState,1)); % encoder memory (in bits)m = ceil(m_bits/k_bits); % encoder memory (in "symbols")number_of_states = size(ST_NextState,1);NTx = size(ST_Output{1,1},1); % number of transmit antennas%% -- fading_gains = ('tx_antenna','time','rx_antenna') -- %%%% De-interleave data and fading (same interleaving assumed for all channels)if SF>1 temp_SF = zeros(SF,LData/SF); temp_SF_i = zeros(SF,LData/SF); %% -- Fading gains -- %% for i1=1:NRx for i2 = 1:NTx temp_SF_i=reshape(fading_gains(i2,:,i1),SF,LData/SF); for i3=1:SF temp_SF(i3,alpha_channel)=temp_SF_i(i3,:); end % for i3=1:SF fading_gains(i2,:,i1)=reshape(temp_SF,1,LData); end % for i2 = 1:NTx end % for i1=1:NRx %% -- Data -- %% for i1=1:NRx temp_SF_i=reshape(Data_received(i1,:),SF,LData/SF); for i2=1:SF temp_SF(i2,alpha_channel)=temp_SF_i(i2,:); end % for i2=1:SF Data_received(i1,:)=reshape(temp_SF,1,LData); end % for i1=1:2*NRx else Data_received(:,alpha_channel) = Data_received; fading_gains(:,alpha_channel,:) = fading_gains; end % if SF>1%%%%%%%%%%%%%%%%%%%%%%%%%% -- Init trellis -- %%%%%%%%%%%%%%%%%%%%%%%%%%% State presentation of the paths% Format: % Row = state%trellis_state_path = cell(number_of_states,1);[trellis_state_path{:}] = deal(1);% Aux variables.% Format: % Rows = current states% Column = previous states%Metrics_dist_tmp = ones(number_of_states)*(Inf);trellis_state_path_tmp = cell(number_of_states);%% ----------------------Trellis search-----------------------------% 1. State transitions caused by input sequences% 2. Outputs of these transitions.% 3. Distance-metrics between received sequence and transitions.% 4. Discard transitions to each state with higher distance-metrics.% 5. New transitions from surviving paths.%% -----------------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -- Trellis calculations begin (soft decisions) -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Keep track of distance metrics at different states.Metrics_dist = ones(number_of_states,1)*NaN;Metrics_dist(1,1) = 0;% Aux variableeuclid_metric = zeros(NRx,1);% Loop over received symbolsfor t = 1:LData/SF % Loop over allowed states for state = 1:number_of_states % Calculate metrics if transition is allowed, otherwise skip to % next state if ~isnan(Metrics_dist(state,1)) for input = 1:2^k_bits % Next state of the trellis next_state = ST_NextState(state,input); % Modulated branch output output = ModMap(ST_Output{state,input}); euclid_metric = zeros(NRx,1); for rx_ant = 1:NRx for c = 1:SF % Modify branch output with channel gains faded_output = sum(fading_gains(:,(t-1)*SF+c,rx_ant).*output); % Euclidian metric for one receive antenna euclid_metric(rx_ant) = euclid_metric(rx_ant) + ... abs(faded_output-Data_received(rx_ant,SF*(t-1)+c)).^2; end % for c = 1:SF end % for rx_ant = 1:NRx % Branch euclidian metric (NRx receive antennas) Metrics_dist_tmp(next_state,state) = Metrics_dist(state) + ... sum(euclid_metric); % Keep track of the paths that have lead to current states. trellis_state_path_tmp{next_state,state} = ... [trellis_state_path{state,1},next_state]; end % for input = 1:k_bits end % if ~isnan(Metrics_dist(state,1)) end % for state = 1:number_of_states % Find the survivors survivor_ptr = ones(number_of_states,1)*(NaN); [rows,columns] = ... ind2sub([number_of_states,number_of_states],find(Metrics_dist_tmp<Inf)); [tmp_dist, tmp_ptr] = min(Metrics_dist_tmp,[],2); Metrics_dist(rows,1) = tmp_dist(rows,1); survivor_ptr(rows,1) = tmp_ptr(rows,1); % Surviving paths for i2 = 1:number_of_states index_ptr = survivor_ptr(i2); if ~isnan(index_ptr) trellis_state_path(i2,1) = trellis_state_path_tmp(i2,index_ptr); end % if ~isnan(index_ptr) end % for i2 = 1:number_of_states end % for t = 1:LData% Final surviving state path[dummy, decode_ptr] = min(Metrics_dist,[],1);final_state_path = trellis_state_path{decode_ptr,:};% Convert state path to info bit sequenceout_tmp = cell(1,length(final_state_path)-1);for i1 = 1:length(out_tmp) out_tmp(i1) = ... Lut_InfBits(final_state_path(i1),final_state_path(i1+1));end % for i1 = 1:2:length(Data_received)outputs = [out_tmp{:}];% Remove tail bitsif TerminateF outputs = outputs(1:end-k_bits*(ceil(log2(number_of_states)/k_bits)));end % if TerminateF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -