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_nirs_signalqualityindex.m
    path of file: ./repos/fieldtrip/external/artinis
    
    the code of the file until where you have to start completion: function dataout = ft_nirs_signalqualityindex(cfg, datain)

% FT_NIRS_SIGNALQUALITYINDEX processes NIRS data and returns a copy of the original
% data replaced with nans in the signal segements that are bellow the specified
% quality threshold.
%
% Use as

    
function dataout = ft_nirs_signalqualityindex(cfg, datain)

% FT_NIRS_SIGNALQUALITYINDEX processes NIRS data and returns a copy of the original
% data replaced with nans in the signal segements that are bellow the specified
% quality threshold.
%
% Use as
%   dataout = ft_nirs_signalqualityindex(cfg, datain)
% where cfg is a configuration structure and indata is raw NIRS-data (in optical
% densities, ODs) that is represented according to the output of FT_PREPROCESSING.
%
% The configuration should contain the following options
%   cfg.threshold    = scalar, the SQI (signal quality index) value that
%                      has to be exceeded to be labelled as a 'good'
%                      channel (default = 3.5)
%   cfg.windowlength = scalar, the length (in seconds) of the signal
%                      segments to be analyzed (default = 10)
%
% This function is based on:
% - Sappia, M. S., Hakimi, N., Colier, W. N., & Horschig, J. M. (2020).
%   Signal quality index: an algorithm for quantitative assessment of
%   functional near infrared spectroscopy signal quality. Biomedical Optics
%   Express, 11(11), 6732-6754. https://doi.org/10.1364/BOE.409317
%
% Please cite accordingly. Thank you!
%
% To facilitate data-handling and distributed computing you can use
%   cfg.inputfile   =  ...
%   cfg.outputfile  =  ...
% If you specify one of these (or both) the input data will be read from a *.mat
% file on disk and/or the output data will be written to a *.mat file. These mat
% files should contain only a single variable, corresponding with the% input/output structure.
%
% See also FT_NIRS_SCALPCOUPLINGINDEX, FT_NIRS_REFERENCECHANNELSUBTRACTION, FT_NIRS_TRANSFORM_ODS

% You are using the FieldTrip NIRS toolbox developed and maintained by
% Artinis Medical Systems (http://www.artinis.com). For more information
% on FieldTrip, see http://www.fieldtriptoolbox.org
%
% This work is licensed under a Creative Commons Attribution-ShareAlike 4.0
% International License. To view a copy of this license, visit
% http://creativecommons.org/licenses/by-sa/4.0/ or send