HE/WaveAdp/Generate_CP.m

73 lines
2.4 KiB
Mathematica
Raw Normal View History

2024-03-30 16:35:40 +08:00
function [len_CP] = Generate_CP(channel_response,N_windows,N_level,min_len_CP)
% CP
% OFDMH_bs
% channel_response N_windows N_level
% min_len_CPCPCP>
% CP
%
N_carriers = length(channel_response);
%
Len_windows = N_carriers / N_windows;
%
[channel_gain, sorted_indices] = sort(abs(channel_response), 'descend');%
G_max = max(channel_gain);
G_min = min(channel_gain);
%
D_L = (G_max-G_min)/N_level;
%
level_k = zeros(1,N_carriers);
for i = 1:N_carriers
%
if channel_gain(i) <= G_min
level_k(i) = 1;
elseif channel_gain(i) >= G_max
level_k(i) = N_level;
% (3)
else
level_k(i) = ceil((channel_gain(i) - G_min)/D_L);
end
end
% (2)
weight_k = 2*level_k-1;
% CP
weight_matrix = zeros(N_windows,Len_windows);
choose_matrix = zeros(N_windows,Len_windows);
len_CP = zeros(1,N_windows);
for i = 1:N_windows
weight_matrix(i,:) = weight_k((i-1)*Len_windows+1:i*Len_windows);%
current_CP = weight_matrix(i,1);%
choose_matrix(i,1) = current_CP;%
for j = 2:Len_windows
%
if current_CP <= min_len_CP
current_CP = current_CP + weight_matrix(i,j);
choose_matrix(i,j) = weight_matrix(i,j);
%
if j == Len_windows
if current_CP <= min_len_CP %
len_CP(i) = min_len_CP;
break;
else
len_CP(i) = current_CP;%
break;
end
end
% current_CP > min_len_CP
else
len_CP(i) = current_CP;
break;
end
end
end
end