Browse Source

sinefit: move initial estimate into the main iteration loop

Just a little less code.  Same results.
tags/nilmtools-1.1.8
Jim Paris 11 years ago
parent
commit
4da658e960
1 changed files with 3 additions and 4 deletions
  1. +3
    -4
      src/sinefit.py

+ 3
- 4
src/sinefit.py View File

@@ -188,12 +188,11 @@ def sfit4(data, fs):
# if something fails with the least squares fit, etc.
try:
# first guess for A0, B0 using 3-parameter fit (step c)
s = zeros(3)
w = 2*pi*f0
D = c_[cos(w*t), sin(w*t), ones(N)]
s = linalg.lstsq(D, data)[0]

# Now iterate 6 times (step i)
for idx in range(6):
# Now iterate 7 times (step i)
for idx in range(7):
D = c_[cos(w*t), sin(w*t), ones(N),
-s[0] * t * sin(w*t) + s[1] * t * cos(w*t) ] # eqn B.16
s = linalg.lstsq(D, data)[0] # eqn B.18


Loading…
Cancel
Save