From 5b4ce8a54ca88b54908c904e52f5a17281e452b5 Mon Sep 17 00:00:00 2001 From: ZaellixA <axilleaz@protonmail.com> Date: Fri, 6 Dec 2024 10:43:47 +0000 Subject: [PATCH] Update parameter list and checks in firstOrderDma.m --- .../MATLAB/Functions/firstOrderDma.m | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m b/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m index 82e4168..6377e7b 100644 --- a/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m +++ b/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m @@ -3,7 +3,7 @@ % Author: Achilles Kappis % e-mail: axilleaz@protonmail.com % -% Date: 17/11/2024 (DD/MM/YYYY) +% Date: 04/12/2024 (DD/MM/YYYY) % % Copyright: MIT % -------------------------------------------------- @@ -64,39 +64,44 @@ % Notes % % -------------------------------------------------- -function [h, output] = firstOrderDma(input, freq, d, pPattern, beta) +function [h, output] = firstOrderDma(freq, d, pPattern, beta, input) % ==================================================== % Check for number of arguments % ==================================================== - narginchk(3, 5); + narginchk(2, 5); nargoutchk(0, 2); % ==================================================== % Validate input arguments % ==================================================== - validateattributes(input, {'numeric'}, {'3d', 'nonnan', 'finite', 'nonempty'}, mfilename, 'Input', 1); + validateattributes(freq, {'numeric'}, {'real', 'nonnan', 'finite', 'nonempty', 'vector'}, mfilename, 'Frequencies', 1); + validateattributes(d, {'numeric'}, {'scalar', 'real', 'nonnan', 'finite', 'nonempty'}, mfilename, 'Inter-element distance', 2); - if mod(size(input, 1), 2) ~= 0 - error("First dimension of 'input' parameter must have even length.") - end + % Check input + if nargin > 4 && ~isempty(input) + validateattributes(input, {'numeric'}, {'3d', 'nonnan', 'finite', 'nonempty', 'size', [NaN, NaN, length(freq)]}, mfilename, 'Input', 5); - validateattributes(freq, {'numeric'}, {'real', 'nonnan', 'finite', 'nonempty', 'vector', 'numel', size(input, 3)}, mfilename, 'Frequencies', 2); - validateattributes(d, {'numeric'}, {'scalar', 'real', 'nonnan', 'finite', 'nonempty'}, mfilename, 'Inter-element distance', 3); + if mod(size(input, 1), 2) ~= 0 + error("First dimension of 'input' parameter must have even length.") + end + else + input = []; + end % Check beta - if nargin > 4 - validateattributes(beta, {'numeric'}, {'scalar', 'real', 'finite', 'nonempty', 'nonnan', '<=', 1, '>=', 0}, mfilename, "Beta", 5) + if nargin > 3 && ~isempty(beta) + validateattributes(beta, {'numeric'}, {'scalar', 'real', 'finite', 'nonempty', 'nonnan', '<=', 1, '>=', 0}, mfilename, "Beta", 4) else beta = 0; end % Check alpha (angle of null) - if nargin > 3 + if nargin > 2 && ~isempty(pPattern); if isstring(pPattern) || ischar(pPattern) - validateattributes(pPattern, {'char', 'string'}, {'scalartext', 'nonempty'}, mfilename, 'Polar pattern', 4); + validateattributes(pPattern, {'char', 'string'}, {'scalartext', 'nonempty'}, mfilename, 'Polar pattern', 3); elseif isnumeric(pPattern) - validateattributes(pPattern, {'numeric'}, {'scalar', 'real', 'nonnan', 'finite', 'nonempty'}, mfilename, 'Angle of null', 4); + validateattributes(pPattern, {'numeric'}, {'scalar', 'real', 'nonnan', 'finite', 'nonempty'}, mfilename, 'Angle of null', 3); end else pPattern = "dipole"; @@ -151,7 +156,7 @@ function [h, output] = firstOrderDma(input, freq, d, pPattern, beta) % ==================================================== % Calculate array output % ==================================================== - if nargout > 1 + if nargout > 1 && ~isempty(input) % Go through the frequencies for freqIdx = length(freq):-1:1 for pairIdx = size(input, 1)/2:-1:1 @@ -159,6 +164,8 @@ function [h, output] = firstOrderDma(input, freq, d, pPattern, beta) output(pairIdx, :, freqIdx) = h(:, freqIdx)' * input(pairIdx * 2 - 1:pairIdx * 2, :, freqIdx); end end + else + output = []; end end -- GitLab