diff --git a/Virtual Sensing/Generic/MATLAB/Functions/mulCoh.m b/Virtual Sensing/Generic/MATLAB/Functions/mulCoh.m index 758eef5d42eba1685f44a6a03abd7663b911085b..c7b14980c102fea4cf82901f1e7cc1fc7dd90de1 100644 --- a/Virtual Sensing/Generic/MATLAB/Functions/mulCoh.m +++ b/Virtual Sensing/Generic/MATLAB/Functions/mulCoh.m @@ -3,7 +3,7 @@ % Author: Achilles Kappis % e-mail: axilleaz@protonmail.com % -% Date: 12/07/2024 (DD/MM/YYYY) +% Date: 16/07/2024 (DD/MM/YYYY) % % Copyright: MIT % -------------------------------------------------- @@ -27,6 +27,8 @@ % -------------------------------------------------- % Output % +% cohSq [numeric]: The multiple coherence squared. +% % coh [numeric]: The multiple coherence. % % -------------------------------------------------- @@ -36,12 +38,12 @@ % virtual signal and physical signals in remote acoustic sensing" by % P. Zhang, S. Wang, H. Duan, J. Tao, H. Zou and X. Qiu. % -------------------------------------------------- -function coh = mulCoh(Px, Py, Sqq, xRegFac) +function [cohSq, coh] = mulCoh(Px, Py, Sqq, xRegFac) % ==================================================== % Check for number of arguments % ==================================================== narginchk(2, 4); - nargoutchk(0, 1); + nargoutchk(0, 2); % ==================================================== % Validate input arguments @@ -78,7 +80,11 @@ function coh = mulCoh(Px, Py, Sqq, xRegFac) Syy = Py * Sqq * Py'; Sxy = Px * Sqq * Py'; - % Calculate multiple coherence - coh = diag((Sxy'/(Sxx + xRegFac * eye(size(Sxx, 1))) * Sxy)./Syy); - coh = real(coh); % Make sure to get rid of residual imaginary parts + % Calculate multiple coherence squared + cohSq = diag((Sxy'/(Sxx + xRegFac * eye(size(Sxx, 1))) * Sxy)./Syy); + cohSq = real(cohSq); % Make sure to get rid of residual imaginary parts + + if nargout > 1 + coh = sqrt(cohSq); + end end \ No newline at end of file