-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathar_extend.m
More file actions
64 lines (53 loc) · 1.76 KB
/
ar_extend.m
File metadata and controls
64 lines (53 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [x_ext, params] = ar_extend(x, nsamp, varargin)
% ar_extend: extend x by nsamp samples using an AR model.
%
% Syntax: [x_ext, params] = ar_extend(x, nsamp, [nsamp_ar]=<size(x,1)>, [order]=20, ...
% [mean_models]=false, [method]='burg')
%
% If x is a vector, a column vector is returned. Otherwise, operates along
% the columns of x (fitting a separate model to each column).
%
% If nsamp_ar is provided, uses only the last nsamp_ar samples of x to
% calculate the AR model. nsamp_ar (or length(x) if not specified) must be
% at least order+1.
%
% If order is provided, uses an AR(order) model.
%
% If mean_models is set to true, averages the AR model estimates of each
% column of the matrix x and uses this mean model to predict forward for
% each column. (Experimental feature!)
%
% 'method', if provided, specifies the AR estimation method - either 'burg'
% (the default) or 'yule' (for Yule-Walker).
%
% If requested, 'params' contains the AR model(s) used for prediction
% (formatted as in the output of arburg). If mean_models is true, this is
% the single average model.
if isvector(x)
x = x(:);
end
lenx = size(x, 1);
noptarg = length(varargin);
nsamp_ar = lenx;
if noptarg > 0 && ~isempty(varargin{1})
nsamp_ar = varargin{1};
end
order = 20;
if noptarg > 1 && ~isempty(varargin{2})
order = varargin{2};
end
mean_models = false;
if noptarg > 2 && ~isempty(varargin{3})
mean_models = varargin{3};
end
method = 'burg';
if noptarg > 3 && ~isempty(varargin{4})
method = varargin{4};
end
% use only nsamp_ar points to fit, if requested
x_clipped = x(lenx - (nsamp_ar - 1):lenx, :);
% fit model
params = ar_fit(x_clipped, order, method, mean_models);
% extend signal using model
x_ext = [x; ar_predict(x, nsamp, params)];
end