1## Copyright (C) 1999 Paul Kienzle <pkienzle@users.sf.net> 2## 3## This program is free software: you can redistribute it and/or modify 4## it under the terms of the GNU General Public License as published by 5## the Free Software Foundation, either version 3 of the License, or 6## (at your option) any later version. 7## 8## This program is distributed in the hope that it will be useful, 9## but WITHOUT ANY WARRANTY; without even the implied warranty of 10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11## GNU General Public License for more details. 12## 13## You should have received a copy of the GNU General Public License 14## along with this program; see the file COPYING. If not, see 15## <https://www.gnu.org/licenses/>. 16 17## -*- texinfo -*- 18## @deftypefn {Function File} {} gaussian (@var{m}) 19## @deftypefnx {Function File} {} gaussian (@var{m}, @var{a}) 20## 21## Return a Gaussian convolution window of length @var{m}. The width of the 22## window is inversely proportional to the parameter @var{a}. Use larger 23## @var{a} for a narrower window. Use larger @var{m} for longer tails. 24## 25## w = exp ( -(a*x)^2/2 ) 26## 27## for x = linspace ( -(m-1)/2, (m-1)/2, m ). 28## 29## Width a is measured in frequency units (sample rate/num samples). 30## It should be f when multiplying in the time domain, but 1/f when 31## multiplying in the frequency domain (for use in convolutions). 32## @end deftypefn 33 34function w = gaussian (m, a) 35 36 if (nargin < 1 || nargin > 2) 37 print_usage (); 38 elseif (! (isscalar (m) && (m == fix (m)) && (m > 0))) 39 error ("gaussian: M must be a positive integer"); 40 elseif (nargin == 1) 41 a = 1; 42 endif 43 44 w = exp(-0.5*(([0:m-1]'-(m-1)/2)*a).^2); 45 46endfunction 47 48%!assert (gaussian (1), 1) 49 50%% Test input validation 51%!error gaussian () 52%!error gaussian (0.5) 53%!error gaussian (-1) 54%!error gaussian (ones (1, 4)) 55%!error gaussian (1, 2, 3) 56