function decodeMatrix = ambidecodemtrx(order, speakers)
%ambidecodemtrx computes decode matrix for Higher Order Ambisonics (HOA)
%
% inputs
% order     : Ambisonic order, integer value 0 through 7
% speakers  : 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 speaker decoding on or off for the
%               particular speaker. If deviceType vector is omitted,
%               then the deviceTypes are set to 1.
%
% 
% This function ambidecodemtrx 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},...
                        'ambidecodemtrx','order',1); 
validateattributes(speakers, {'single', 'double'}, ...
                        {'nonempty','real','nonnan'}, ...
                        'ambidecodemtrx','speakers',2); 
coder.internal.errorIf((size(speakers,1) ~= 2) && (size(speakers,1) ~= 3), ...
    'audio:ambisonics:BadSpeakerSize');
% -------------------------------------------------------------------------   
decodeMatrix = audioexample.ambisonics.ambicodecmtrx(order, speakers, 'dec');
end

