You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ft_preproc_denoise.m
    path of file: ./repos/malini/Codes/deconvolution - model/spm8/external/fieldtrip/preproc
    
    the code of the file until where you have to start completion: function [dat, w] = ft_preproc_denoise(dat, refdat, hilbertflag)

% FT_PREPROC_DENOISE performs a regression of the matrix dat onto
% refdat, and subtracts the projected data. This is for the 
% purpose of removing signals generated by coils during continuous
% head motion tracking, for example.
%
% Use as
%   [dat] = ft_preproc_denoise(dat, refdat, hilbertflag)
% where
%   dat         data matrix (Nchan1 X Ntime)
%   refdat      data matrix (Nchan2 X Ntime)
%   hilbertflag specifying to regress out the real and imaginary parts of 
%                 the hilbert transformed signal. Only meaningful for narrow
%                 band reference data
%

    
function [dat, w] = ft_preproc_denoise(dat, refdat, hilbertflag)

% FT_PREPROC_DENOISE performs a regression of the matrix dat onto
% refdat, and subtracts the projected data. This is for the 
% purpose of removing signals generated by coils during continuous
% head motion tracking, for example.
%
% Use as
%   [dat] = ft_preproc_denoise(dat, refdat, hilbertflag)
% where
%   dat         data matrix (Nchan1 X Ntime)
%   refdat      data matrix (Nchan2 X Ntime)
%   hilbertflag specifying to regress out the real and imaginary parts of 
%                 the hilbert transformed signal. Only meaningful for narrow
%                 band reference data
%
% See also PREPROC

% Copyright (C) 2009, Jan-Mathijs Schoffelen
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    FieldTrip is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id: ft_preproc_denoise.m 7123 2012-12-06 21:21:38Z roboos $

if nargin<3,
  hilbertflag = 0;
end