Skip to content
Snippets Groups Projects
Commit 029a3042 authored by Achilles Kappis's avatar Achilles Kappis
Browse files

Update obsFilt.m to accept matrix SNR values and change input check for...

Update obsFilt.m to accept matrix SNR values and change input check for regularisation factors to check for real values
parent 3c9b08f2
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
% Author: Achilles Kappis % Author: Achilles Kappis
% e-mail: axilleaz@protonmail.com % e-mail: axilleaz@protonmail.com
% %
% Date: 14/02/2025 (DD/MM/YYYY) % Date: 05/03/2025 (DD/MM/YYYY)
% %
% Copyright: MIT % Copyright: MIT
% -------------------------------------------------- % --------------------------------------------------
...@@ -41,12 +41,13 @@ ...@@ -41,12 +41,13 @@
% Signal-to-Noise Ratio (SNR) in the % Signal-to-Noise Ratio (SNR) in the
% monitoring microphone signals. This must % monitoring microphone signals. This must
% be either a scalar indicating the common % 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 % vector of dimensions Kx1, containing the SNR
% values of each microphone. The values must % values of each microphone or a square matrix
% be real or Inf for the noiseless case. See % with dimensions KxK. The values must be real
% the Notes below for references on how this % or Inf for the noiseless case. See the Notes
% value is calculated. [Default: Inf]. % below for references on how this value is
% calculated. [Default: Inf].
% %
% -------------------------------------------------- % --------------------------------------------------
% Output % Output
...@@ -106,7 +107,7 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) ...@@ -106,7 +107,7 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal)
end end
if nargin > 3 && ~isempty(regFacs) 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 % Make sure regFacs has correct dimensions
if ~isscalar(regFacs) if ~isscalar(regFacs)
...@@ -121,15 +122,23 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) ...@@ -121,15 +122,23 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal)
end end
if nargin > 4 && ~isempty(snrVal) 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); validateattributes(snrVal, "numeric", {'2d', 'real', 'nonnan', 'nonempty'}, mfilename, "Normalised Root-Mean-Square Singal-to-Noise Ratio of the monitoring microphones", 5);
% Make sure snrVal has correct dimensions
if ~isscalar(snrVal) && numel(snrVal) ~= size(Pm, 1) 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."); error("SNR must be either a scalar or its length must match the number of monitoring microphones.");
end end
if sum(snrVal == -Inf) > 0 % Make sure snrVal has correct dimensions
error("SNR value cannot be equal to -Inf"); 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 end
else else
snrVal = Inf; snrVal = Inf;
...@@ -156,12 +165,18 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal) ...@@ -156,12 +165,18 @@ function [oOpt, Sme, Smm, condNum] = obsFilt(Pe, Pm, Svv, regFacs, snrVal)
% Signal-to-Noise Ratio at the monitoring microphones % Signal-to-Noise Ratio at the monitoring microphones
if ~isinf(snrVal) 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 snrMtx = (snrVal.^2) .* norm(Smm, 'fro')/(size(Pm, 1)^2); % Calculate the appropriate SNR amplitude values
else else
snrMtx = 0; snrMtx = 0;
end 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; Smm = Smm + snrMtx + regMat;
oOpt = Sme/Smm; oOpt = Sme/Smm;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment