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: emg_quantification.m
    path of file: ./repos/OSET/matlab/tools/emg
    
    the code of the file until where you have to start completion: function [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl, varargin)
% 
% [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl)
% [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl, duration)
% 

    
function [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl, varargin)
% 
% [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl)
% [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl, duration)
% 
% *************************************************************************
% * EMG Signal Analysis and Quantification                                *
% *************************************************************************
% 
% Usage:    [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl)
%           [emg_quant, synch_emg2, ecg_estimate2_bl, time_vec] = emg_quantification(emg_data, fs, emg_onset_sampl, duration)
% inputs:
%           'emg_data': cell array containing emg signals of all trials
%           'fs': sampling frequency (Hz)
%           'emg_onset_sampl': vector containing movement onset samples of
%                              all trials (output of 'bdf2mat_main.m' function)
%     (opt) 'duration': duration of signal required after onset (default: 
%                       duration = 2 (Seconds))
% outputs:
%           'emg_quant': vector containing quantified emg values
%           'synch_emg2': cell array containing synchronized emg trials
%                         based on movement onset
%           'ecg_estimate2_bl': extracted ECG signal from EMG channels
%           'time_vec': time-vector required for plotting quantified EMG
% Note:
%           an empty bracket [] Must be assigned to not-specified values
%
% This program is provided by ESMAEIL SERAJ. Please make sure to cite BOTH 
% the original studies and the User Manual to help others find these items.
% 
% Authors:
% 			Esmaeil Seraj, Karthiga Mahalingam
% Websites:
%			https://github.com/EsiSeraj/ERP_Connectivity_EMG_Analysis
% 			http://oset.ir/category.php?dir=Tools
% 
%    Copyright (C) <2018>  <ESMAEIL SERAJ (eseraj3@gatech.edu)>
%
%    This program 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.
%
%    This program 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 this program. If not, see <http://www.gnu.org/licenses/> or
%    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
%    Floor, Boston, MA  02110-1301, USA.
% 

%% Checking inputs and assigning default values
if nargin < 3
    error('***wrong number of input arguments. Refer to Manual for details***')
elseif nargin == 3
    duration = 2;
elseif nargin > 3
    if size(varargin, 2) ~= 1
        error('***wong number of variable input arguments. Only <duration> is supposed to be entered***')
    else
        if isempty(varargin)
            duration = 2;
        else
            duration = varargin;
        end