Code covered by the BSD License  

Highlights from
Multiple Vector Convolutions

Multiple Vector Convolutions

by

 

returns full convolution of multiple vectors and appropriate locations

multiconv(X, Y, varargin)
function [C,x] = multiconv(X, Y, varargin)
%convolutes multiple vectors
%MULTICONV returns full convolution of multiple vectors and appropriate locations
%Valid path options are:
%  * 'lin', 'log' returns linearly of logarithmically spaced location vector
%  * true, false : normalizes distribution to 1 
%  * true, false : redistributes data values to old location
%
%Example:
%    multiconv(locations, [distribution1, distribution2, distribution3] ...
%           [, lin, log] [, norm] [, redist] )
%
%Depends on: islin, islog
%See also: conv

p	=	inputParser;
validOptions = {'lin', 'log'};
p.addRequired('X',			@isnumeric );
p.addRequired('Y',			@isnumeric );
p.addOptional('OPTIONS',	'',		@(x) any(strcmp(x,validOptions)) );
p.addOptional('NORM',		false,	@islogical );
p.addOptional('REDIST',		false,	@(x) any([islogical(x), isnumeric(x)]) );
p.parse(X, Y, varargin{:});

if any(strcmp(p.Results.OPTIONS, 'lin'))
	lin		=	true;
	log		=	false;
elseif any(strcmp(p.Results.OPTIONS, 'log'))
	lin		=	false;
	log		=	true;
else
	lin		=	false;
	log		=	false;
end

if isempty(Y)
	C	=	Y(:);
	x	=	X(:);
	return
end

% Check size of data vector
X	=	X(:);
if size(Y,2) == length(X)
	Y	=	Y';
elseif ~any(size(Y) == length(X))
	error('multiconv:yvector', 'Wrong size of Y')
end

% Do convolutions
if size(Y,2) > 1
	C	=	conv(Y(:,1), Y(:,2));
	for i = 3:size(Y,2)
		C	=	conv(C, Y(:,i));
	end
else
	C	=	Y;
end
C	=	C(:);

% Redistribute on original vector
if size(Y,2) ~= (length(C)-1)/(length(X)-1)
	error('multiconv:length', 'Something strange happened')
end
if p.Results.REDIST
	C	=	C(1:size(Y,2):length(C));
	x	=	X;
% elseif isnumeric(p.Results.REDIST) && ~isempty(p.Results.REDIST)
% 	C	=	p.Results.REDIST;
% 	x	=	p.Results.REDIST;
else
	if islin(X) || lin
		x	=	linspace(min(X), max(X), length(C))';
	elseif islog(X) || log
		x	=	logspace(log10(min(X)), log10(max(X)), length(C))';
	else
		error('multiconv:output', 'Cannot determine format of input')
	end
end

if p.Results.NORM
	C	=	C/trapz(x,C);
end

end

% Copyright 2009-2013 Alexandra Heidsieck <aheidsieck@tum.de>,
%                     IMETUM, Technische Universitaet Muenchen

Contact us