-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuildPElsMatrix.m
73 lines (71 loc) · 1.83 KB
/
buildPElsMatrix.m
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
64
65
66
67
68
69
70
71
72
73
% Function to build the P matrix for the ELS identification process.
%
% written by: Renato Naville Watanabe
%
% p = buildPElsMatrix(u, y, e, I, noise, Mp)
%
% Inputs:
%
% u: vector of floats, input signal.
%
% y: vector of floats, output signal.
%
% e: vector of floats, residue signal.
%
% I: cell, obtained from the modelLags function.
%
% noise: boolean, indicate if you have a residue signal. Normally you call it set to 0. The recursive
% calls will call it set to 1.
%
% Mp: integer, number of terms found in the identification process, without the residues.
%
%
% Outputs:
%
% p: matrix of floats, matrix for the ELS identification process.
function p = buildPElsMatrix(u, y, e, I, noise, Mp)
if (noise == 1)
Nl = length(I);
N = length(e);
begin = length(u) - length(e);
else
Nl = Mp;
N = length(u);
begin = 0;
end
%%
maxLag = 0;
for i = 1:length(I)
Nt = length(I{i})/2;
for j = 1:Nt
if maxLag < I{i}(j*2)
maxLag = I{i}(j*2);
end
end
end
%%
if (noise == 1)
begin = length(u) - length(e) + maxLag;
else
begin = maxLag;
end
%%
p = zeros(N-maxLag,Nl);
for k = 1:N-maxLag
for i = 1:Nl
p(k,i) = 1;
Nt = length(I{i})/2;
for j = 1:Nt
if (I{i}((j-1)*2+1) == 117)
p(k,i) = p(k,i)*u(begin+k-I{i}(j*2));
else if (I{i}((j-1)*2+1) == 121)
p(k,i) = p(k,i)*y(begin+k-I{i}(j*2));
else if (I{i}((j-1)*2+1) == 101)
p(k,i) = p(k,i)*e(maxLag+k-I{i}(j*2));
end
end
end
end
end
end
end