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_spike_rate.m
    path of file: ./repos/fieldtrip/contrib/spike
    
    the code of the file until where you have to start completion: function [rate] = ft_spike_rate(cfg, spike)

% FT_SPIKE_RATE computes the firing rate of spiketrains and their variance
%
% Use as
%   [rate] = ft_spike_rate
    
function and scripts
ft_revision = '$Id$';
ft_nargin   = nargin;
ft_nargout  = nargout;

% do the general setup of the function
ft_defaults
ft_preamble init
ft_preamble provenance spike


% control input spike structure
spike = ft_checkdata(spike,'datatype', 'spike', 'feedback', 'yes');

% get the default options
if isfield(cfg,'trials') && isempty(cfg.trials), error('no trials were selected'); end