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: Wrapper_EchoCombine_MEDInonlinearfit.m
    path of file: ./repos/sepia/wrapper/WrapperEchoCombine
    
    the code of the file until where you have to start completion: %% [totalField, N_std, headerAndExtraData] = Wrapper_EchoCombine_MEDInonlinearfit(fieldMap,mask,matrixSize,voxelSize,algorParam,headerAndExtraData)
%
% Input
% --------------
% fieldMap      : original single-/multi-echo wrapped phase image, in rad
% mask          : signal mask
% matrixSize    : size of the input image
% voxelSize     : spatial resolution of each dimension of the data, in mm
% algorParam    : structure contains fields with algorithm-specific parameter(s)
% headerAndExtraData : structure contains extra 
    
function [totalField, N_std, headerAndExtraData] = Wrapper_EchoCombine_MEDInonlinearfit(fieldMap,mask,matrixSize,voxelSize,algorParam,headerAndExtraData)

% get extra data such as magnitude/weights/B0 direction/TE/etc.
headerAndExtraData = check_and_set_SEPIA_header_data(headerAndExtraData);
% get some data from headerAndExtraData
TE      = headerAndExtraData.sepia_header.TE;
dt      = headerAndExtraData.sepia_header.delta_TE;
magn    = get_variable_from_headerAndExtraData(headerAndExtraData, 'magnitude', matrixSize);

sepia_addpath('MEDI');
if numel(TE)>3 && ((TE(2)-TE(1))-(TE(3)-TE(2))>1e-5)
    % Estimate the frequency offset in each of the voxel using a complex
    % fitting (uneven echo spacing)
    [iFreq_raw, N_std] = Fit_ppm_complex_TE(magn.*exp(-1i*fieldMap),TE);
else
    % Estimate the frequency offset in each of the voxel using a complex
    % fitting (even echo spacing)
    [iFreq_raw, N_std] = Fit_ppm_complex(magn.*exp(-1i*fieldMap));
end