function [zc,varargout] = mygaussian(x,z,varargin)
%MYGAUSSIAN makes use of the 1D convolution myconvper to filter the signal
% z sampled on the domain x with a 1D Gaussian filter.
%
% ZC = MYGAUSSIAN2(X,Z) returns the filtered signal ZC corresponding to
% the original signal Z defined on X.
% [ZC,HX] = MYGAUSSIAN2(X,Z) returns also the 1D Gaussian weighting
% function
% ZC = MYGAUSSIAN2(X,Z,LCXR) lets the user specify the cut-off length as
% a fraction of the sample size LX=X(END,1)-Y(1,1), i.e., LCX=LCXR*LX.
% According to ISO 11562, the cut-off length LC for a Gaussian Profile
% Filter is L/5.
%
% x must be produced by;
% x = linspace(ax,bx,Nx)
% size(z) == [1,Nx]
% Author(s): A. Almqvist
% Copyright 2009- Andreas Almqvist
% $Revision: 1$ $Date: 2009/11$
% Homemade function
% Cut-off length lcx = lcxr*Lx
lcxr = 1/5; % ISO 11562 Gaussian Profile Filter
if length(varargin) == 1;
lcxr = varargin{1};
end
% Create the domain of def. for the Gaussian weighting function
N = length(x);
Lx = x(end)-x(1);
dx = x(2)-x(1);
xf = linspace(-Lx/2,Lx/2,N);
lcx = lcxr*Lx; % Cut-off acc to ISO 11562 Gaussian Profile Filter Lx/5
alpha = sqrt(log(2)/pi); % Auxiliary constant
% The Gaussian weighting function
variancex = 1/(pi*sqrt(2/log(2)))*lcx;
hx = dx/(sqrt(2*pi)*variancex)*...
exp(-((xf/variancex).^2)/2);
% zc = myfullrepx(myconvx(myperrepx(z),hx));
zc = myconvper(z(:,1:end-1),hx);
zc = [zc,zc(:,1)];
if nargout == 1
varargout{1} = hx;
end