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: time_variant_ar_kalman.m
    path of file: ./repos/OSET/matlab/tools/generic
    
    the code of the file until where you have to start completion: function [ARCoefsKF , ARCoefsKS] = time_variant_ar_kalman(data, order, x0, q, R, p0, alpha)
% time_variant_ar_kalman - Time variant auto-regressive (AR) model estimated by Kalman Filter and Kalman Smoother
%
% Syntax: [ARCoefsKF , ARCoefsKS] = time_variant_ar_kalman(data, order, x0, q, R, p0, alpha)
%
% Inputs:
%   data: Template noise used for model training
%   order: AR model order
%   x0: A time-invariant set of AR-coefficients estimated by applying a global AR-model estimation on the entire input signal
%   q: AR coefficients covariance
%   R: Noise variance
%   p0: Covariance of the KF initial state
%   alpha: KF forgetting factor (alpha = 1 for standard KF)
%
% Outputs:
%   ARCoefsKF: AR coefficients estimated by a Kalman Filter
%   ARCoefsKS: AR coefficients estimated by a Kalman Smoother
%
%   Revision History:
%       2006: First release
%       2023: Renamed from deprecated version TimeVariantAR()
% 
%   Reza Sameni, 2006-2023
%   The Open-Source Electrophysiological Toolbox
%   https://github.com/alphanumericslab/OSET

N = length(data); % Length of the data
A = 1;
Q = q * eye(order);
Wmean = zeros(order, 1);
Vmean = mean(data);
ARCoefsKF = zeros(order, N);
Xminus = x0;
Pminus = p0 * eye(order);

Pbar = zeros(order, order, N);
Phat = zeros(order, order, N);
Xhat = zeros(order, N);
Xbar = zeros(order, N);

% Filtering
for i = 1:N

    
function [ARCoefsKF , ARCoefsKS] = time_variant_ar_kalman(data, order, x0, q, R, p0, alpha)
% time_variant_ar_kalman - Time variant auto-regressive (AR) model estimated by Kalman Filter and Kalman Smoother
%
% Syntax: [ARCoefsKF , ARCoefsKS] = time_variant_ar_kalman(data, order, x0, q, R, p0, alpha)
%
% Inputs:
%   data: Template noise used for model training
%   order: AR model order
%   x0: A time-invariant set of AR-coefficients estimated by applying a global AR-model estimation on the entire input signal
%   q: AR coefficients covariance
%   R: Noise variance
%   p0: Covariance of the KF initial state
%   alpha: KF forgetting factor (alpha = 1 for standard KF)
%
% Outputs:
%   ARCoefsKF: AR coefficients estimated by a Kalman Filter
%   ARCoefsKS: AR coefficients estimated by a Kalman Smoother
%
%   Revision History:
%       2006: First release
%       2023: Renamed from deprecated version TimeVariantAR()
% 
%   Reza Sameni, 2006-2023
%   The Open-Source Electrophysiological Toolbox
%   https://github.com/alphanumericslab/OSET

N = length(data); % Length of the data
A = 1;
Q = q * eye(order);
Wmean = zeros(order, 1);
Vmean = mean(data);
ARCoefsKF = zeros(order, N);
Xminus = x0;
Pminus = p0 * eye(order);

Pbar = zeros(order, order, N);
Phat = zeros(order, order, N);
Xhat = zeros(order, N);
Xbar = zeros(order, N);

% Filtering
for i = 1:N
    Pbar(:, :, i) = Pminus;
    Xbar(:, i) = Xminus;

    if (i < order + 1)
        H = [-data(i - 1:-1:1)' zeros(1, order - i + 1)];
    else
        H = -data(i - 1:-1:i - order)';
    end