annotate rDiff/src/locfit/m/spence15.m @ 0:0f80a5141704

version 0.3 uploaded
author vipints
date Thu, 14 Feb 2013 23:38:36 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
1 function yhat=spence15(y)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
2 % function for Spencer's 15-point graduation rule.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
3 % set out following Spencer's hand-calculation method,
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
4 % which isn't the shortest computer program!
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
5
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
6 osev = ones(7,1);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
7 n = length(y);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
8 y = [ osev*y(1); y; osev*y(n) ];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
9
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
10 n = length(y);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
11 k = 3:(n-2);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
12 a3 = y(k-1) + y(k) + y(k+1);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
13 a2 = y(k-2) + y(k+2);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
14 y1 = y(k)+3*(a3-a2);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
15
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
16 n = length(y1);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
17 k = 1:(n-3);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
18 y2 = y1(k)+y1(k+1)+y1(k+2)+y1(k+3);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
19
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
20 n = length(y2);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
21 k = 1:(n-3);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
22 y3 = y2(k)+y2(k+1)+y2(k+2)+y2(k+3);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
23
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
24 n = length(y3);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
25 k = 1:(n-4);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
26 y4 = y3(k)+y3(k+1)+y3(k+2)+y3(k+3)+y3(k+4);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
27
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
28 yhat = y4/320;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
29 return;