function [Demod_out,LLR] = Demodulation(Demod_in,noise_var_out,PAR)
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COPYRIGHT (c) CBC/XWV Chengdu, 2010
% The copyright to the document(s) herein is the property of CBC/XWV
% Chengdu.The document(s) may be used and/or copied only with the written
% permission from CBC/XWV Chengdu, or in accordance with the terms and
% conditions stipulated in the agreement/contract under which the
% document(s) have been supplied.
% All rights reserved.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Author: ELLIWWN
% Created: <2010-7-2>
% [Revision date: <date>]
% [Revised by: <signum>]
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function Description:
% perform QPSK, 16QAM or 64 QAM soft demodulation, output LLR which is the
% soft output defined as log(P(==1)/P(==0)), as well as the hard output
% after performing hard decision.
%
% type: 1 --- traditional LLR based on Eucilid distance
% 2 --- simplified LLR
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mod_syms = PAR.TX.MOD.constellation;
ones_idx = PAR.RX.MOD.onesIdx;
zeros_idx = PAR.RX.MOD.zerosIdx;
norm = PAR.TX.MOD.norm;
demod_type = PAR.RX.MOD.demod_type;
if demod_type == 1
LLR = calc_LLR(Demod_in.',noise_var_out,ones_idx,zeros_idx,mod_syms);
elseif demod_type == 2
LLR = calc_LLR2(Demod_in.',noise_var_out,mod_syms,norm);
else
error('unknown soft demodulation type');
end
LLR = LLR(:).';
% hard decision
Demod_out = zeros(size(LLR));
Demod_out(find(LLR>0))=1;
function [bitmatrix] = calc_LLR(rx_symbols,noise_var,ones_idx,zeros_idx,mod_syms)
bits_per_sym = log2(length(mod_syms));
bitmatrix = zeros(bits_per_sym,length(rx_symbols));
num_comp = size(ones_idx,2); % number of comparison constellation pionts for each bit
noise_var = 2*noise_var;
distances = repmat(rx_symbols, 1, length(mod_syms)) - repmat(mod_syms, length(rx_symbols), 1);
distances = real(distances).^2+imag(distances).^2;
for bcnt=1:1:bits_per_sym
numer_val = distances(:, ones_idx(bcnt,:));
denom_val = distances(:, zeros_idx(bcnt,:));
numer_val = min(numer_val.'); % (1 x N)
denom_val = min(denom_val.'); % (1 x N)
bitmatrix(bcnt,:) = (denom_val-numer_val)./noise_var; %+exp(-numer_val-denom_val); % (bits_per_sym x N)
clear numer_val denom_val;
end
function bitmatrix = calc_LLR2(rx_symbols,noise_var,mod_syms,norm)
bits_per_sym = log2(length(mod_syms));
noise_var = 2*noise_var;
% rx_symbols = rx_symbols/norm;
I = real(rx_symbols);
Q = imag(rx_symbols);
bitmatrix(1,:) = -I;Noise_var(1,:)=noise_var;
bitmatrix(2,:) = -Q;Noise_var(2,:)=noise_var;
if bits_per_sym == 4
bitmatrix(3,:) = abs(bitmatrix(1,:))-2*norm;Noise_var(3,:)=noise_var;
bitmatrix(4,:) = abs(bitmatrix(2,:))-2*norm; Noise_var(4,:)=noise_var;
elseif bits_per_sym == 6
bitmatrix(3,:) = abs(bitmatrix(1,:))-4*norm;Noise_var(3,:)=noise_var;
bitmatrix(4,:) = abs(bitmatrix(2,:))-4*norm;Noise_var(4,:)=noise_var;
bitmatrix(5,:) = abs(bitmatrix(3,:))-2*norm;Noise_var(5,:)=noise_var;
bitmatrix(6,:) = abs(bitmatrix(4,:))-2*norm;Noise_var(6,:)=noise_var;
end
% Modified by Chris Zhang. Used to conform to algorithm adapted in DSP.
%bitmatrix = bitmatrix./Noise_var;
评论0