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: pspm_down.m
    path of file: ./repos/PsPM/src
    
    the code of the file until where you have to start completion: function [sts, newfile] = pspm_down(datafile, newsr, channel, options)
% ● Description
%   pspm_down downsamples a PsPm dataset to the desired new sample rate
%   this function applies anti-aliasing filtering at 1/2 of the new sample
%   rate. The data will be written to a new file, the original name will be
%   prepended with 'd'.
% ● Format
%   [sts, newfile] = pspm_down(datafile, newsr, channel, options)
% ● Arguments
%   datafile:  can be a name, or for convenience, a cell array of filenames
%    newfreq:  new frequency (must be >= 10 Hz)
%    channel:  channels to downsample (default: all channels)
%    options:  defines whether to overwrite the file.
%              Default value: overwrite, and also determined by pspm_overwrite.
% ● Output
%        sts:  1 if the function runs successfully
%    newfile:  the filename for the updated file, or cell array of filenames
% ● History
%   Introduced in PsPM 3.0
%   Written in 2010-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)

%% Initialise
global settings
if ise
    
function runs successfully
%    newfile:  the filename for the updated file, or cell array of filenames
% ● History
%   Introduced in PsPM 3.0
%   Written in 2010-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)

%% Initialise
global settings
if isempty(settings)
  pspm_init;
end
sts = -1;

%% check input arguments
if nargin<1
  errmsg='No data file'; warning('ID:invalid_input', errmsg); return;
elseif nargin<2
  errmsg='No frequency given'; warning('ID:invalid_input', errmsg); return;
elseif newsr < 10
  errmsg='This function does not support downsampling to frequencies below 10 Hz.';
  warning('ID:rate_below_minimum', errmsg);
  return;
end

if nargin < 3 || isempty(channel)
  channel = 0;
elseif isnumeric(channel) && isvector(channel)
  if numel(channel) == 1 && channel < 0
    warning('ID:invalid_input', 'channel must be nonnegative'); return;
  elseif any(channel < 0)
    warning('ID:invalid_input', 'All elements of channel must be positive'); return;
  end
elseif ischar(channel)
  if strcmpi(channel, 'all')
    channel = 0;
  else
    warning('ID:invalid_input', 'Channel argument must be a number, or ''all''.'); return;
  end
end

if nargin < 4
    options = struct();
end