⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cc.m

📁 A Novel Coded Layered Space-Time- Frequency Architecture: Convolutional Codes
💻 M
📖 第 1 页 / 共 2 页
字号:
global power_ratio alpha_freq pilot_position;
if pilot_position == 0
R_data = R(:,:,1+M_ant:Nd+M_ant);
if ch_est_flag == 0 % ideal channel estimation
H = H_ideal(:,:,:,1+M_ant:Nd+M_ant);
else
H = ch_estimation(R(:,:,1:M_ant));
end
elseif pilot_position == 1
R_data = cat(3,R(:,:,1:Nd/2),R(:,:,Nd/2+1+M_ant:Nd+M_ant));
if ch_est_flag == 0 % ideal channel estimation
H = cat(4,H_ideal(:,:,:,1:Nd/2),H_ideal(:,:,:,Nd/2+1+M_ant:Nd+M_ant));
else
H = ch_estimation(R(:,:,Nd/2+1:Nd/2+M_ant));
end
else
R_data = R(:,:,1:Nd);
if ch_est_flag == 0 % ideal channel estimation
H = H_ideal(:,:,:,1:Nd);
else
H = ch_estimation(R(:,:,Nd+1:Nd+M_ant));
end
end
for k = 1:Nc
[z(:,:,k),mu(:,:,k),eta_2(:,:,k)] =MMSE(squeeze(R_data(:,k,:)),squeeze(H(:,:,k,:)),sigma^2,squeeze(L_A(:,k,:)),squeeze(symbol_data(:,k,:)));
end
L_D =LLR_gen(reshape(permute(z,[2,3,1]),1,Nd*Nc*M_ant),reshape(permute(mu,[2,3,1]),1,Nd*Nc*M_ant),reshape(permute(eta_2,[2,3,1]),1,Nd*Nc*M_ant));
%Program-5 Channel estimation module
function H = ch_estimation(R_pilot)
global Nc ifftsize Tg Tb Ts T_sample guardtime Nd rate ifftsize;
global M_ant N_ant lou llr_appro_flag fd L int_flag rate E_chipsymb ch_est_flag;
global modu_size Modulate_map Modulate_map_real Modulate_map_imag nEN;
global power_ratio alpha_freq;
N_freq = 2;
H_temp1 = permute(R_pilot./sqrt(power_ratio*E_chipsymb),[1,3,2]);
H_temp2 = cat(3,zeros(N_ant,M_ant,2),H_temp1)*alpha_freq(3)+...
cat(3,zeros(N_ant,M_ant,1),H_temp1,zeros(N_ant,M_ant,1))*alpha_freq(2)+...
cat(3,H_temp1,zeros(N_ant,M_ant,2))*alpha_freq(1);
H_temp3(:,:,1) = H_temp2(:,:,2)/(alpha_freq(1)+alpha_freq(2));
H_temp3(:,:,2:Nc-1) = H_temp2(:,:,3:Nc)/(alpha_freq(1)+alpha_freq(2)+alpha_freq(3));
H_temp3(:,:,Nc) = H_temp2(:,:,Nc+1)/(alpha_freq(3)+alpha_freq(2));
H = repmat(H_temp3,[1 1 1 Nd]);
%Program-6 MMSE-SIC detection module
function [z,mu,eta_2] = MMSE(R_data,H,sigma_2,L_A,symbol_data)
global Nc ifftsize Tg Tb Ts T_sample guardtime Nd rate ifftsize;
global M_ant N_ant lou llr_appro_flag fd L int_flag rate E_chipsymb ch_est_flag;
global modu_size Modulate_map Modulate_map_real Modulate_map_imag nEN;
118
global Max_delay Dexp Dexp_point fs Multipath_E Multipath_amp S_1_2 R_1_2 pilot;
global symbol2bit;
global feedback_flag;
C = 2^modu_size;
symbol2bit_t = 2*kron(ones(M_ant,1),symbol2bit)-1;
symbol_temp = kron(ones(M_ant,1),Modulate_map');
I_matrix = eye(M_ant);
for l = 1:size(R_data,2)
H_my = H(:,:,l);
if feedback_flag == 0 % ideal feedback bits
X_mean = symbol_data(:,l);
X_var = zeros(M_ant,M_ant);
elseif feedback_flag == 1 % non-ideal feedback bits
X_temp1 = kron(L_A(:,(l-1)*modu_size+1:l*modu_size),ones(C,1)).*symbol2bit_t;
X_temp2 = 1./(1+exp(X_temp1));
X_mean = (sum(reshape(prod(X_temp2,2).*symbol_temp,C,M_ant),1))';
X_var = diag((sum(reshape(prod(X_temp2,2).*abs(symbol_temp).^2,C,M_ant),1))'-abs(X_mean).^2);
if X_var < 0,error('X_var error!,\n');end
end
for j = 1:M_ant
X_j = X_mean.*(1-I_matrix(:,j));
Y_j = R_data(:,l)-H_my*X_j;
X_var_j = X_var;
X_var_j(j,j) = E_chipsymb;
omega_j_H = E_chipsymb*I_matrix(j,:)*H_my'*inv(H_my*X_var_j*H_my'+sigma_2*eye(N_ant));
z(j,l) = omega_j_H*Y_j;
mu(j,l) = real(omega_j_H*H_my*I_matrix(:,j));
eta_2(j,l) = real((mu(j,l)-(mu(j,l))^2)*E_chipsymb);
end
end
%Program-7 Convolutional encoding & MAP decoding modules
function dump = convolu_initial(g)
global bin_state next_state next_state_code1 next_state_code2 last_state;
[n,k] = size(g);
m = k-1;
nstates = 2^m;
temp_state = [1:nstates]'-1;
for i = m:-1:1
bin_state(1:nstates,i) = fix(temp_state./(2^(i-1)));
temp_state = temp_state-bin_state(1:nstates,i)*2^(i-1);
end
next_state(1:nstates,1:2) = [(mod((0:nstates-1).*2,2^m)+1)',(mod((0:nstates-1).*2,2^m)+2)'];
last_state(1:nstates,1:2) = [(fix((0:nstates-1)./2)+1)',(fix((0:nstates-1)./2)+2^(m-1)+1)'];
for state = 1:nstates
for i = 0:1
output_bits = rem(g*[i,bin_state(state,:)]',2);
next_state_code1(state,output_bits(1)+1) = next_state(state,i+1);
next_state_code2(state,output_bits(2)+1) = next_state(state,i+1);
end
end
dump = 1;
function y = encode_conv(g,x)
[n,k] = size(g);
L_total = length(x);
x = [zeros(1,k-1),x];
for row = 1:n
y_temp(row,:) = rem(filter(g(row,:),[1],x),2);
119
end
y = reshape(y_temp(:,k:L_total+k-1),1,n*L_total);
function [x_hat,L_D] = logmap(L_A,g)
global bin_state next_state next_state_code1 next_state_code2 last_state;
global tail_flag;
% Total number of bits: Inftyo. + tail
L_total = length(L_A)/2;
[n,k] = size(g);
m = k-1;
nstates = 2^m;
Infty = 1e300;
% Initialization of Alpha
Alpha_temp(L_total,1) = 0;
Alpha_temp(L_total,2:nstates) = Infty*ones(1,nstates-1);
% Initialization of Beta
if tail_flag == 0
Beta(L_total+1,1) = 0;
Beta(L_total+1,2:nstates) = Infty*ones(1,nstates-1);
else
Beta(L_total+1,1:nstates) = zeros(1,nstates);
end
exp_L_A = reshape(exp(L_A),2,length(L_A)/2);
% Branch metrics, compute Delta.
for state = 1:nstates
for i=0:1
output_bits = kron(rem(g*[i,bin_state(state,:)]',2),ones(1,L_total));
Delta(1:L_total,i*nstates+state) = -(sum(log((output_bits+(1-output_bits).*exp_L_A)./(1+exp_L_A)),1))';
Delta_coded1(1:L_total,output_bits(1,1)*nstates+state) = Delta(1:L_total,i*nstates+state);
Delta_coded2(1:L_total,output_bits(2,1)*nstates+state) = Delta(1:L_total,i*nstates+state);
end
end
% Trace forward, compute Alpha
Delta_temp = Delta(L_total:-1:1,:);
for k = L_total-1:-1:1
Alpha_temp(k,1:nstates) = E_function(Alpha_temp(k+1,last_state(1:nstates,1))+Delta_temp(k+1,(mod(0:nstates-1,2))'*nstates+last_state(1:nstates,1)),...
Alpha_temp(k+1,last_state(1:nstates,2))+Delta_temp(k+1,(mod(0:nstates-1,2))'*nstates+last_state(1:nstates,2)));
end
Alpha = Alpha_temp(L_total:-1:1,:);
% Trace backward, compute Beta
for k = L_total:-1:2
Beta(k,1:nstates) = E_function(Delta(k,0*nstates+[1:nstates])+Beta(k+1,next_state(1:nstates,1)),...
Delta(k,1*nstates+[1:nstates])+Beta(k+1,next_state(1:nstates,2)));
end
% Compute the log-likelihood ratio of coded bits
temp0 = Alpha(1:L_total,1)+Delta_coded1(1:L_total,0*nstates+1)+Beta(2:L_total+1,next_state_code1(1,0+1));
temp1 = Alpha(1:L_total,1)+Delta_coded1(1:L_total,1*nstates+1)+Beta(2:L_total+1,next_state_code1(1,1+1));
for state4 = 2:nstates
temp0 = E_function(temp0,....
Alpha(1:L_total,state4)+Delta_coded1(1:L_total,0*nstates+state4)+Beta(2:L_total+1,next_state_code1(state4,0+1)));
temp1 = E_function(temp1,....
Alpha(1:L_total,state4)+Delta_coded1(1:L_total,1*nstates+state4)+Beta(2:L_total+1,next_state_code1(state4,1+1)));
end
L_D_coded(1,:) = -temp0'+temp1';
120
temp0 = Alpha(1:L_total,1)+Delta_coded2(1:L_total,0*nstates+1)+Beta(2:L_total+1,next_state_code2(1,0+1));
temp1 = Alpha(1:L_total,1)+Delta_coded2(1:L_total,1*nstates+1)+Beta(2:L_total+1,next_state_code2(1,1+1));
for state4 = 2:nstates
temp0 = E_function(temp0,....
Alpha(1:L_total,state4)+Delta_coded2(1:L_total,0*nstates+state4)+Beta(2:L_total+1,next_state_code2(state4,0+1)));
temp1 = E_function(temp1,....
Alpha(1:L_total,state4)+Delta_coded2(1:L_total,1*nstates+state4)+Beta(2:L_total+1,next_state_code2(state4,1+1)));
end
L_D_coded(2,:) = -temp0'+temp1';
L_D = reshape(L_D_coded,1,2*L_total);
% Compute the log-likelihood ratio of info bits
temp0 = Alpha(1:L_total,1)+Delta(1:L_total,0*nstates+1)+Beta(2:L_total+1,next_state(1,1));
temp1 = Alpha(1:L_total,1)+Delta(1:L_total,1*nstates+1)+Beta(2:L_total+1,next_state(1,2));
for state4 = 2:nstates
temp0 = E_function(temp0,....
Alpha(1:L_total,state4)+Delta(1:L_total,0*nstates+state4)+Beta(2:L_total+1,next_state(state4,1)));
temp1 = E_function(temp1,....
Alpha(1:L_total,state4)+Delta(1:L_total,1*nstates+state4)+Beta(2:L_total+1,next_state(state4,2)));
end
L_D_info = -temp0'+temp1';
x_hat = (1-sign(L_D_info))/2;
%Program-8 LLR generation function
function llr = LLR_gen(z,mu,eta_2)
global Nc ifftsize Tg Tb Ts T_sample guardtime Nd rate ifftsize;
global M_ant N_ant lou llr_appro_flag fd L int_flag rate E_chipsymb ch_est_flag;
global modu_size Modulate_map Modulate_map_real Modulate_map_imag nEN;
global Max_delay Dexp Dexp_point fs Multipath_E Multipath_amp S_1_2 R_1_2 pilot;
global symbol2bit;
X = real(z);
Y = imag(z);
num_bit_encoded = length(z)*2;
llr(1:2:num_bit_encoded-1) = log(exp(-(X+mu).^2./eta_2)+1e-300)-...
log(exp(-(X-mu).^2./eta_2)+1e-300);
llr(2:2:num_bit_encoded) = log(exp(-(Y-mu).^2./eta_2)+1e-300)-...
log(exp(-(Y+mu).^2./eta_2)+1e-300);
%Program-9 Influence of Doppler frequency shift
function dopplertf = doptf(fd,fs)
len = 8192;
% length of doppler filter impulse response = irlen
irlen = len/2;
% create the PSD of the in-phase and quad-phase in the frequency domain
f=0:1/len:(len-1)/len;
span = floor(len*fd/fs)+1;
psd = ones(1,span)./sqrt((fd/fs)^2*ones(1,span)-f(1:span).^2);
psd = [psd, zeros(1,len-span)];
psd = psd + rot90(psd,2);
% the transfer function of the doppler filter is the sqrt(PSD)
sqrtpsd = sqrt(psd);
% allow a time delay of irlen/2 samples by multiplying with a linear
% phase shift
sqrtpsd = sqrtpsd.* exp(-j*f*2*pi*irlen/2);
% obtain the impulse response using inverse FFT
im_res = real(ifft(sqrtpsd,len));
121
% truncate the impulse response to length irlen
im_res(irlen+1:len) = zeros(1,len-irlen);
% convert the truncated impulse response to the frequency
% domain to get the transfer function
filtertf = fft(im_res,len);
% Normalize the transfer function such that the power
% of the filter output is 0.5 (that way, power of
% the channel, equal to the sum of the powers of the I
% and the Q components, is 1)
dopplertf = filtertf/sqrt(2*filtertf*filtertf'/len);
%Program-10 Generator of one realization of flat fading channel
function my_alpha = flatfade(fd,fs,duration,dopplertf,state)
len = 8192;
irlen = len/2;
N=round(fs*duration);
if length(state)==1
input = [randn(1,irlen), zeros(1,len-irlen)];
out(1,:) = real(ifft(dopplertf.*fft(input)));
input = [randn(1,irlen), zeros(1,len-irlen)];
out(2,:) = real(ifft(dopplertf.*fft(input)));
state = out(:, irlen+1:2*irlen);
end;
batch = len-irlen;
numofloop = ceil((N)/batch);
lastlooplen = N-(numofloop-1)*batch;
a = [state zeros(2, (numofloop+1)*batch)];
for i=1:numofloop
ptstart = (i-1)*batch+1;
ptend = (i-1)*batch + len;
if i==numofloop
input = [randn(2,lastlooplen), zeros(2,len-lastlooplen)];
else
input = [randn(2,batch), zeros(2,irlen)];
end;
out(1,:) = real(ifft(dopplertf.*fft(input(1,:))));
out(2,:) = real(ifft(dopplertf.*fft(input(2,:))));
a(:,ptstart:ptend)=a(:,ptstart:ptend)+out;
end;
my_alpha = a(1, 1:N) + j * a(2,1:N);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -