diff --git a/Virtual Sensing/Remote Microphone Technique/MATLAB/Functions/obsFilt.m b/Virtual Sensing/Remote Microphone Technique/MATLAB/Functions/obsFilt.m index c1c2b32693f7fc0a5445e46d5c1ea3821fcf7c7c..f2ef0193f43a021a9a8c22a91807187926d3859b 100644 --- a/Virtual Sensing/Remote Microphone Technique/MATLAB/Functions/obsFilt.m +++ b/Virtual Sensing/Remote Microphone Technique/MATLAB/Functions/obsFilt.m @@ -3,7 +3,7 @@ % Author: Achilles Kappis % e-mail: axilleaz@protonmail.com % -% Date: 13/02/2025 (DD/MM/YYYY) +% Date: 14/02/2025 (DD/MM/YYYY) % % Copyright: MIT % -------------------------------------------------- @@ -31,9 +31,10 @@ % inversion of the cross-spectra of the % monitoring microphones. Can be a vector % with number of elements equal to K (number -% of monitoring microphones) or a scalar +% of monitoring microphones), a scalar % which will result in the same -% regularisation factor for all microphones. +% regularisation factor for all microphones, +% or a square matrix with dimensions KxK. % [Default: 0] % % snrVal [numeric] (Optional): This is the Root-Mean-Square (RMS) @@ -105,11 +106,15 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) end if nargin > 3 && ~isempty(regFacs) - validateattributes(regFacs, "numeric", {'vector', 'nonnegative', 'nonnan', 'nonempty', 'finite'}, mfilename, "Regularisation factors", 4); + validateattributes(regFacs, "numeric", {'2d', 'nonnan', 'nonempty', 'finite'}, mfilename, "Regularisation factors", 4); % Make sure regFacs has correct dimensions - if ~isscalar(regFacs) && numel(regFacs) ~= size(Pm, 1) - error("Regularisation factors must be either a scalar or its length must match the number of monitoring microphones."); + if ~isscalar(regFacs) + if isvector(regFacs) && numel(regFacs) ~= size(Pm, 1) + error("If the regularisation factors are given as a vector the number of elements must match the number of monitoring microphones."); + elseif ismatrix(regFacs) && ~isequal(size(regFacs), ones(1, 2) .* size(Pm, 1)) + error("If the regularisation factors are given as a matrix, it must be a square matrix with each dimension equal to the number of monitoring microphones."); + end end else regFacs = 0; @@ -143,8 +148,10 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) % Regularisation matrix if isscalar(regFacs) regMat = eye(size(Smm)) .* regFacs; - else + elseif isvector(regFacs) regMat = diag(regFacs); + else + regMat = regFacs; end % Signal-to-Noise Ratio at the monitoring microphones