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: spm_gx_fnirs.m
    path of file: ./repos/spm/toolbox/dcm_fnirs
    
    the code of the file until where you have to start completion: function [g] = spm_gx_fnirs(x,u,P,M)
% fNIRS optics equation
% FORMAT [g] = spm_gx_fnirs(x,u,P,M)

    
function [g] = spm_gx_fnirs(x,u,P,M)
% fNIRS optics equation
% FORMAT [g] = spm_gx_fnirs(x,u,P,M)
%
% x   - state vector     (see spm_fx_fnirs)
% u   - experimental inputs
% P   - prior of latent variables
% M   - model structure
%
% g   - optical density changes
%__________________________________________________________________________
% References for optics equations:
% 1. Arridge, SR 1999. Optical tomography in medical imaging. Inverse Prob.
% 15: R41-R93.
% 2. Gagnon L, Yucel, MA, Dehaes, M, Cooper, RJ, Perdue, KL, Selb, J, Huppert TJ,
% Hoge RD, Boas DA, 2012. Quantification of the cortical contribution to
% the NIRS signal over NIRS-fMRI measurements. NeuroImage 59: 3933-3940.
% 3. Tak, S, Kempny, AM, Friston, KJ, Leff, AP, Penny WD, Dynamic causal
% modelling for functional near-infrared spectroscopy. NeuroImage 111: 338-349.
%__________________________________________________________________________

% Will Penny & Sungho Tak
% Copyright (C) 2015-2022 Wellcome Centre for Human Neuroimaging


% exponentiation of hemodynamic state variables
x(:, 3:6) = exp(x(:,3:6));

% optics parameters
%--------------------------------------------------------------------------
%   N(1) - oxygen saturation                                            SO2
%   N(2) - baseline total-hb concentration [mM]                P0
%   N(3) - cortical weighting factor                                   w
%--------------------------------------------------------------------------
N = [0.65 0.071 2];

% baseline dxy-hb concentration
base_hbr = N(2) .* (1-N(1));

% calculate changes in hemoglobin concentration
dq = (x(:,5)-1).*base_hbr; % dxy-Hb
dp = (x(:,6)-1).*N(2); % total Hb
dh = dp - dq; % oxy-Hb

% parameter for correction of pial vein contamination
if size(P.pv, 1) == (M.nch*2)
    % additionally correct pial vein oxygenation
    pv = N(3) .* exp(P.pv);
    pv = reshape(pv, M.nch, 2);
else
    pv = N(3).* exp(P.pv);
    pv = kron(ones(1,2), pv);
end