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: calcInstantaneousTheta2.m
    path of file: ./repos/CellExplorer/calc_CellMetrics
    
    the code of the file until where you have to start completion: function InstantaneousTheta = calcInstantaneousTheta2(session,varargin)
% Calculates the instantaneous theta with phase and power
% By Peter Petersen
% Last edited: 18-08-2019

p = inputParser;
addParameter(p,'forceReload',false,@islogical);
addParameter(p,'saveMat',true,@islogical);
addParameter(p,'saveAs','InstantaneousTheta',@isstr);

parse(p,varargin{:})

forceReload = p.Results.forceReload;
saveMat = p.Results.saveMat;
saveAs = p.Results.saveAs;

% Theta band
Fpass = [4,11];
freqlist = [Fpass(1):0.1:Fpass(2)];

% Output file
saveAsFullfile = fullfile(session.general.basePath,[session.general.name,'.',saveAs,'.lfp.mat']);

ch_theta = session.channelTags.Theta.channels;
ch_theta = ch_theta(1);
if ~forceReload && exist(saveAsFullfile,'file')
    disp('Loading existing InstantaneousTheta.lfp.mat file')
    InstantaneousTheta = [];

    
function InstantaneousTheta = calcInstantaneousTheta2(session,varargin)
% Calculates the instantaneous theta with phase and power
% By Peter Petersen
% Last edited: 18-08-2019

p = inputParser;
addParameter(p,'forceReload',false,@islogical);
addParameter(p,'saveMat',true,@islogical);
addParameter(p,'saveAs','InstantaneousTheta',@isstr);

parse(p,varargin{:})

forceReload = p.Results.forceReload;
saveMat = p.Results.saveMat;
saveAs = p.Results.saveAs;

% Theta band
Fpass = [4,11];
freqlist = [Fpass(1):0.1:Fpass(2)];

% Output file
saveAsFullfile = fullfile(session.general.basePath,[session.general.name,'.',saveAs,'.lfp.mat']);

ch_theta = session.channelTags.Theta.channels;
ch_theta = ch_theta(1);
if ~forceReload && exist(saveAsFullfile,'file')
    disp('Loading existing InstantaneousTheta.lfp.mat file')
    InstantaneousTheta = [];
    load(saveAsFullfile)
    if isempty(InstantaneousTheta) || isnumeric(InstantaneousTheta.ThetaInstantFreq)
        disp(['InstantaneousTheta not calculated correctly. Hold on'])
        InstantaneousTheta = [];
        forceReload = true;
    elseif isempty(InstantaneousTheta) || size(InstantaneousTheta.ThetaInstantFreq,2) < ch_theta || isempty(InstantaneousTheta.ThetaInstantFreq{ch_theta})
        forceReload = true;
        disp(['Selected channel not calculated yet. Hold on'])
    end