HE/WaveAdp/Generate_CP.m
2024-03-30 16:35:40 +08:00

73 lines
2.4 KiB
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function [len_CP] = Generate_CP(channel_response,N_windows,N_level,min_len_CP)
% 产生CP长度的函数
% 在该方法中假设将要发送的OFDM符号的数量等于H_bs中窗的数目。
% 输入channel_response 信道响应N_windows 需要划窗的个数N_level 量化等级;
% min_len_CP最小CP取决于最大延迟拓展有最小CP值>最大延迟拓展
% 输出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