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

📄 chk_ofdm_parameters.m

📁 国外大学的同志作出来的好程序
💻 M
字号:
function [ofdm_sim, sim, errors]=chk_ofdm_parameters(ofdm_sim, sim);
%check ofdm parameters.
%
errors=0;
if log2(ofdm_sim.Nfft)~=floor(log2(ofdm_sim.Nfft)),
    disp('[chk_ofdm_parameters]Error: Nfft should be the power of 2.')
    errors=-1; return;
end

if ofdm_sim.Ncp<0 | ofdm_sim.Ncp>=ofdm_sim.Nfft,
    disp('[chk_ofdm_parameters]Error: Ncp is out of the range.')
    errors=-1; return;
end

if ofdm_sim.Ncp==0,
    disp('[chk_ofdm_parameters]Warning: Ncp is zero.')
    errors=errors+1;
end

if ofdm_sim.Nd==0 & ~isempty(ofdm_sim.DataSubcIndex),
    ofdm_sim.Nd=length(ofdm_sim.DataSubcIndex);
elseif ofdm_sim.Nd~=length(ofdm_sim.DataSubcIndex) & ~isempty(ofdm_sim.DataSubcIndex),
    disp('[chk_ofdm_parameters]Error: ofdm_sim.Nd is wrong.');
    errors=-1; return;
end

if ofdm_sim.Np==0 & ~isempty(ofdm_sim.PilotSubcIndex),
    ofdm_sim.Np=length(ofdm_sim.PilotSubcIndex);
elseif ofdm_sim.Np~=length(ofdm_sim.PilotSubcIndex) & ~isempty(ofdm_sim.PilotSubcIndex),
    disp('[chk_ofdm_parameters]Error: ofdm_sim.Np is wrong.');
    errors=-1; return;
end

if ofdm_sim.Nu==0 & ofdm_sim.Nd~=0 & ofdm_sim.Np~=0,
    ofdm_sim.Nu=ofdm_sim.Nd+ofdm_sim.Np;
elseif ofdm_sim.Nu~=ofdm_sim.Nd+ofdm_sim.Np,
    disp('[chk_ofdm_parameters]Error: ofdm_sim.Nu/Nd/Np is wrong.')
    errors=-1; return;
end

%assign sub-carrier for data and pilot
if isempty(ofdm_sim.DataSubcIndex) & isempty(ofdm_sim.PilotSubcIndex),
    disp('[chk_ofdm_parameters]Info: Automatic assignment of pilot and data tones.');
    if mod(ofdm_sim.Nfft, ofdm_sim.Np+2)~=0 | ofdm_sim.Nu~=ofdm_sim.Nfft-2;
        disp('[chk_ofdm_parameters]Error:Automatic assignment of pilot and data tones are not possible for Np and Nu.');
        ofdm_sim
        errors=-1; return;
    else
        grp_num=ofdm_sim.Nfft/(ofdm_sim.Np+2);
        ofdm_sim.PilotSubcIndex=[grp_num: grp_num: ofdm_sim.Nfft/2-grp_num, ofdm_sim.Nfft/2+grp_num: grp_num: ofdm_sim.Nfft-grp_num];
        UsedSubcIndex=[2:ofdm_sim.Nfft/2, ofdm_sim.Nfft/2+2: ofdm_sim.Nfft];
        ofdm_sim.UsedSubcIndex=UsedSubcIndex;
        DataSubcIndex=UsedSubcIndex;
        for ic=1: length(ofdm_sim.PilotSubcIndex),
            index=find(DataSubcIndex==ofdm_sim.PilotSubcIndex(ic));
            DataSubcIndex(index)=[];
        end
        ofdm_sim.DataSubcIndex=DataSubcIndex;
        if length(DataSubcIndex)~=ofdm_sim.Nd,
            disp('[chk_ofdm_parameters]Error: length of DataSubIndex is not right.');
            errors=-1; return;
        end

    end
end

%Cross update for sim and ofdm_sim.
sim.packet_type='ofdm';
sim.frame_time=(ofdm_sim.Nfft+ofdm_sim.Ncp)/sim.symbol_rate;
sim.frame_data_len = ofdm_sim.Nd;
sim.frame_data_time=ofdm_sim.Nfft/sim.symbol_rate;
sim.prefix_type='cyclic';
sim.prefix_time=ofdm_sim.Ncp/sim.symbol_rate;
sim.appendix_type='';
sim.appendix_time=0;
sim.preamble_type=['ofdm_' ofdm_sim.preamble_type];
sim.preamble_time=3*sim.frame_time;


ofdm_sim.tx_num = sim.tx_num;

if sim.frame_num==0 && sim.packet_time~=0 && strcmp(lower(sim.packet_type), 'ofdm'),
    sim.frame_num=round((sim.packet_time-sim.blank_time-sim.lfm_time-sim.preamble_time)/sim.frame_time);
    sim.packet_time=sim.blank_time+sim.lfm_time+sim.preamble_time+sim.frame_time*sim.frame_num;
    disp('[chk_ofdm_parameters]Info: frame_num and packet_time have been adjusted.')
elseif sim.frame_num~=0 && sim.packet_time==0 && strcmp(lower(sim.packet_type), 'ofdm'),
    sim.packet_time=sim.blank_time+sim.lfm_time+sim.preamble_time+sim.frame_time*sim.frame_num
    disp('[chk_ofdm_parameters]Info: frame_num and packet_time have been adjusted.')
end


⌨️ 快捷键说明

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