function [ dataf ] = Gfilt(z,a,fs)
% Gfilt
% 
% usage:
%      [ filtereddata ] = Gfilt(data,a,fs)
%
%  Gaussian Filter; input data is filtered by multiplying by
%  exp(-1*w.^2 ./ (4*a^2)) in the frequency domain,
%  scaled to have amplitude=1 in the time domain.
%  Frequency response is approximately
%  .1 at .5*a, .5 at .267*a, .9 at .1*a
%
%  Dave Wilson, Mar. 2004

sz=size(z);
if sz(1)>sz(2), z=z.'; end;

lz=length(z);
z  = [ z zeros(1,length(z))];

fdat = fft(z);
n = length(z);
df = fs/n;
w = [(0:df:fs/2) -((fs/2-df):-df:df)].*(2*pi);
G =  exp(-1*w.^2 ./ (4*a^2));
Gt = real(ifft(G));
Gt = Gt./max(Gt);
G = fft(Gt);

dataf=real(ifft(fdat.*G));
dataf=dataf(1:lz);
if sz(1)>sz(2), dataf=dataf.'; end;
return;




