0
|
1 function yhat=spence21(y)
|
|
2 % function for Spencer's 21-point graduation rule.
|
|
3 % set out following Spencer's hand-calculation method,
|
|
4 % which isn't the shortest computer program!
|
|
5
|
|
6 oten = ones(10,1);
|
|
7 n = length(y);
|
|
8 y = [ oten*y(1); y; oten*y(n) ];
|
|
9
|
|
10 n = length(y);
|
|
11 k = 4:(n-3);
|
|
12 y1 = -y(k-3) + y(k-1) + 2*y(k) + y(k+1) -y(k+3);
|
|
13
|
|
14 n = length(y1);
|
|
15 k = 4:(n-3);
|
|
16 y2 = y1(k-3)+y1(k-2)+y1(k-1)+y1(k)+y1(k+1)+y1(k+2)+y1(k+3);
|
|
17
|
|
18 n = length(y2);
|
|
19 k = 3:(n-2);
|
|
20 y3 = y2(k-2)+y2(k-1)+y2(k)+y2(k+1)+y2(k+2);
|
|
21
|
|
22 n = length(y3);
|
|
23 k = 3:(n-2);
|
|
24 y4 = y3(k-2)+y3(k-1)+y3(k)+y3(k+1)+y3(k+2);
|
|
25
|
|
26 yhat = y4/350;
|
|
27 return;
|