%CDLChannelAntennaArraysInfo TR 38.901 Antenna arrays information of CDL channel model

%   Copyright 2020-2022 The MathWorks, Inc.

%#codegen

function info = CDLChannelAntennaArraysInfo(model)

    %----------------------------------------------------------------------
    % input validation
    
    validateParameters(model);
    
    %----------------------------------------------------------------------
    % Antenna arrays related info
    
    sizT = size(model.TransmitAntennaArray.ElementPositions);
    info.NumTransmitAntennas = prod(sizT(2:end));
    info.NumInputSignals = model.NumInputSignals;
    sizR = size(model.ReceiveAntennaArray.ElementPositions);
    info.NumReceiveAntennas = prod(sizR(2:end));
    info.NumOutputSignals = model.NumOutputSignals;

    
end

function validateParameters(model)

    validateAntennaArray(model,'TransmitAntennaArray');
    validateAntennaArray(model,'ReceiveAntennaArray');
    
end

function validateAntennaArray(model,arrayfield)

    validateMandatoryParameter(model,arrayfield);
    array = model.(arrayfield);
    validateMandatoryParameter(array,'Position');
    validateMandatoryParameter(array,'Orientation');    
    validateMandatoryParameter(array,'ElementPositions');    
    validateMandatoryParameter(array,'ElementOrientations');
    validateMandatoryParameter(array,'ElementPattern'); 
    
end

% Validates the presence of a mandatory structure field parameter
function validateMandatoryParameter(model,parameter)

    if (~isfield(model,parameter))
        error('wireless:error','Parameter structure field ''%s'' not found',parameter);
    end
    
end





