From 029a30426b2f6497c8237e7d49b10f79f9e5bee5 Mon Sep 17 00:00:00 2001 From: ZaellixA <axilleaz@protonmail.com> Date: Wed, 5 Mar 2025 00:36:41 +0000 Subject: [PATCH] Update obsFilt.m to accept matrix SNR values and change input check for regularisation factors to check for real values --- .../MATLAB/Functions/obsFilt.m | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Virtual Sensing/Remote Microphone Technique/MATLAB/Functions/obsFilt.m b/Virtual Sensing/Remote Microphone Technique/MATLAB/Functions/obsFilt.m index f2ef019..b71fcce 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: 14/02/2025 (DD/MM/YYYY) +% Date: 05/03/2025 (DD/MM/YYYY) % % Copyright: MIT % -------------------------------------------------- @@ -41,12 +41,13 @@ % Signal-to-Noise Ratio (SNR) in the % monitoring microphone signals. This must % be either a scalar indicating the common -% SNR value of the microphone signals, or a +% SNR value of the microphone signals, a % vector of dimensions Kx1, containing the SNR -% values of each microphone. The values must -% be real or Inf for the noiseless case. See -% the Notes below for references on how this -% value is calculated. [Default: Inf]. +% values of each microphone or a square matrix +% with dimensions KxK. The values must be real +% or Inf for the noiseless case. See the Notes +% below for references on how this value is +% calculated. [Default: Inf]. % % -------------------------------------------------- % Output @@ -106,7 +107,7 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) end if nargin > 3 && ~isempty(regFacs) - validateattributes(regFacs, "numeric", {'2d', 'nonnan', 'nonempty', 'finite'}, mfilename, "Regularisation factors", 4); + validateattributes(regFacs, "numeric", {'2d', 'real', 'nonnan', 'nonempty', 'finite'}, mfilename, "Regularisation factors", 4); % Make sure regFacs has correct dimensions if ~isscalar(regFacs) @@ -121,15 +122,23 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) end if nargin > 4 && ~isempty(snrVal) - validateattributes(snrVal, "numeric", {'vector', 'real', 'nonnan', 'nonempty'}, mfilename, "Normalised Root-Mean-Square Singal-to-Noise Ratio of the monitoring microphones", 5); - - % Make sure snrVal has correct dimensions + validateattributes(snrVal, "numeric", {'2d', 'real', 'nonnan', 'nonempty'}, mfilename, "Normalised Root-Mean-Square Singal-to-Noise Ratio of the monitoring microphones", 5); + if ~isscalar(snrVal) && numel(snrVal) ~= size(Pm, 1) error("SNR must be either a scalar or its length must match the number of monitoring microphones."); end - if sum(snrVal == -Inf) > 0 - error("SNR value cannot be equal to -Inf"); + % Make sure snrVal has correct dimensions + if ~isscalar(snrVal) + if isvector(snrVal) && numel(snrVal) ~= size(Pm, 1) + error("If the SNR values are given as a vector the number of elements must match the number of monitoring microphones."); + elseif ismatrix(snrVal) && ~isequal(size(snrVal), ones(1, 2) .* size(Pm, 1)) + error("If the SNR values are given as a matrix, it must be a square matrix with each dimension equal to the number of monitoring microphones."); + end + end + + if nnz(snrVal == -Inf) + error("SNR value cannot be equal -Inf"); end else snrVal = Inf; @@ -156,12 +165,18 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) % Signal-to-Noise Ratio at the monitoring microphones if ~isinf(snrVal) - snrVal = 10^(-snrVal/10); % Convert deciBel to linear + snrVal = 10.^(-snrVal/10); % Convert deciBel to linear snrMtx = (snrVal.^2) .* norm(Smm, 'fro')/(size(Pm, 1)^2); % Calculate the appropriate SNR amplitude values else snrMtx = 0; end - snrMtx = snrMtx .* eye(size(Pm, 1)); + + if isscalar(snrMtx) + snrMtx = snrMtx .* eye(size(Pm, 1)); + elseif isvector(snrMtx) + snrMtx = diag(snrMtx); + end + Smm = Smm + snrMtx + regMat; oOpt = Sme/Smm; -- GitLab