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

Separate the source strengths and signal length input arguments, updated input...

Separate the source strengths and signal length input arguments, updated input argument checks and source signal calculations
parent 50f33059
Branches
No related tags found
1 merge request!3Update to v0.2.3
......@@ -3,7 +3,7 @@
% Author: Achilles Kappis
% e-mail: axilleaz@protonmail.com
%
% Date: 13/09/2024 (DD/MM/YYYY)
% Date: 14/09/2024 (DD/MM/YYYY)
%
% Copyright: MIT
% --------------------------------------------------
......@@ -25,12 +25,23 @@
% Q [numeric] (Optional): The source signals. This can be either an IxNxJ
% array, where I is the length of the source
% signals in samples and J is the number of
% trials/sound field realisations, or a real
% positive integer denoting the length of the
% source signals. In case the length of the source
% signals is given, the generated signals are
% zero-mean, (approximately) uniformly distributed
% and normalised to unity. [Default: 128].
% trials/sound field realisations, a vector of
% positive real values holding the source strengths
% (this is just an amplitude scaling factor), or a
% real positive integer denoting the common
% strength of all the source signals. [Default: 1].
%
% sigLen [numeric] (Optional): The length of the source signals. This must
% be real positive integer. The generated
% signals are zero-mean, (approximately)
% uniformly distributed and normalised to
% unity. If "Q" is an array, "sigLen" is used
% to set the length of the signals. If
% "sigLen" is smaller than I, the signals are
% truncated and if it is larger the signals
% are padded with zeros. Leave empty to have
% the signals unchanged.
% [Default: 128 or if Q is matrix size(Q, 1)].
%
% nTrials [numeric] (Optional): This is the number of trials/sound field
% realisations that will be generated. If "Q"
......@@ -72,11 +83,11 @@
% long source signals
%
% --------------------------------------------------
function [rSig, rSigMean, rSigMtx, rSigMtxMean, Q] = ptSrcFieldTD(sPos, rPos, fs, Q, nTrials, c)
function [rSig, rSigMean, rSigMtx, rSigMtxMean, Q] = ptSrcFieldTD(sPos, rPos, fs, Q, sigLen, nTrials, c)
% ====================================================
% Check for number of arguments
% ====================================================
narginchk(3, 6);
narginchk(3, 7);
nargoutchk(0, 5);
% ====================================================
......@@ -91,23 +102,36 @@ function [rSig, rSigMean, rSigMtx, rSigMtxMean, Q] = ptSrcFieldTD(sPos, rPos, fs
if nargin > 3 && ~isempty(Q)
if isscalar(Q)
validateattributes(Q, "numeric", {'scalar', 'real', 'nonnan', 'nonempty', 'finite', 'positive', 'integer'}, mfilename, "Length of source signals in samples", 4);
elseif isvector(Q)
validateattributes(Q, "numeric", {'vector', 'real', 'nonnan', 'nonempty', 'finite', 'numel', size(sPos, 1)}, mfilename, "Source signals", 4);
else
validateattributes(Q, "numeric", {'3d', 'real', 'nonnan', 'nonempty', 'finite', 'ncols', size(sPos, 1)}, mfilename, "Source signals", 4);
end
else
Q = 128;
Q = 1;
end
if ~isscalar(Q)
if nargin > 4 && ~isempty(sigLen)
validateattributes(sigLen, "numeric", {'scalar', 'nonempty', 'nonnan', 'finite', 'real', 'positive', 'integer'}, mfilename, "The length of the source signals", 5)
else
if ~isvector(Q)
sigLen = size(Q, 1);
else
sigLen = 128;
end
end
if ~ismatrix(Q)
nTrials = size(Q, 3);
elseif nargin > 4 && ~isempty(nTrials) && isscalar(Q)
validateattributes(nTrials, "numeric", {'scalar', 'positive', 'nonnan', 'nonempty', 'finite'}, mfilename, "Number of trials/sound field realisations", 5);
elseif nargin > 5 && ~isempty(nTrials)
validateattributes(nTrials, "numeric", {'scalar', 'positive', 'nonnan', 'nonempty', 'finite', 'integer'}, mfilename, "Number of trials/sound field realisations", 6);
else
nTrials = 1;
end
if nargin > 5 && ~isempty(c)
validateattributes(c, "numeric", {'scalar', 'nonempty', 'nonnan', 'finite', 'real', 'positive'}, mfilename, "The speed of sound", 6);
if nargin > 6 && ~isempty(c)
validateattributes(c, "numeric", {'scalar', 'nonempty', 'nonnan', 'finite', 'real', 'positive'}, mfilename, "The speed of sound", 7);
else
c = 343;
end
......@@ -117,10 +141,17 @@ function [rSig, rSigMean, rSigMtx, rSigMtxMean, Q] = ptSrcFieldTD(sPos, rPos, fs
% Pre-process data
% ====================================================
% Generate source signals
if isscalar(Q)
Q = rand(Q, size(sPos, 1), nTrials);
Q = Q - mean(Q);
Q = Q./max(abs(Q));
if isvector(Q)
tmp = rand(sigLen, size(sPos, 1), nTrials);
tmp = tmp - mean(tmp);
tmp = tmp./max(abs(tmp));
Q = Q(:).' .* tmp;
elseif sigLen ~= size(Q, 1)
if sigLen > size(Q, 1)
Q = cat(1, Q, zeros(sigLen - size(Q, 1), size(Q, 2), size(Q, 3)));
else
Q = Q(1:sigLen, :, :);
end
end
% Calculate source-receiver distances
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment