function encodeMatrix = ambiencodemtrx(order, elements)
%ambiencodemtrx computes encode matrix for Higher Order Ambisonics (HOA)
%
% inputs 
% order      : Ambisonic order, integer value 0 through 7
% elements   : array of azimuth, elevation and optional devicetype
%                [azimuth; elevation; deviceType]
%                [azimuth; elevation]
%                where 
%                    azimuth may range from 0 degrees to 360 degrees
%                    elevation may range from -90 degrees to 90 degrees
%                    deviceTypes are 0 or 1, 
%                deviceType turns the element encoding on or off for the
%                particular element. If deviceType vector is omitted,
%                then the deviceTypes are set to 1.
%
% outputs
% encodeMatrix : encode matrix of size [numDevices x numAmbisonicChannels]
% 
% This function ambiencodemtrx is for demonstration purposes. It may
% change in a future release.

% Copyright 2018-2019 The MathWorks, Inc.
%#codegen
% -------------------------------------------------------------------------
% Validate required inputs
% -------------------------------------------------------------------------
validateattributes(order, {'numeric'}, ...
                        {'nonempty','real','integer','scalar','>=',0,'<=',7},...
                        'ambiencodemtrx','order',1); 
validateattributes(elements, {'single', 'double'}, ...
                        {'nonempty','real','nonnan'}, ...
                        'ambiencodemtrx','elements',2); 
coder.internal.errorIf((size(elements,1) ~= 2) && (size(elements,1) ~= 3), ...
    'audio:ambisonics:BadElementSize');
% -------------------------------------------------------------------------   
encodeMatrix = audioexample.ambisonics.ambicodecmtrx(order, elements, 'enc');
end

