from cmath import phase
import math
import numpy
import numpy as np
from numpy import unwrap
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import scipy
from scipy import interpolate
from scipy.interpolate import interp1d
import scipy.signal.signaltools as sigtool
I have a data set produced by the the following codes.
for i in xrange(10000):
v = i/10000.0
if v < 0.25:
k=0.4*(math.sin(2*3.14*90*v))
l1.append(k)
elif 0.25 <= v < 0.5:
k=0.8*(math.sin(2*3.14*90*v))
l2.append(k)
elif 0.5 <= v < 0.75:
k=0.6*(math.sin(2*3.14*300*v))
l3.append(k)
elif 0.75 <= v < 1.0:
k=0.9*(math.sin(2*3.14*300*v))
l4.append(k)
comb= l1+l2+l3+l4
k=[]
for i in range(len(comb)):
i1=i/10000.
k.append(i1)
f.write(str(i1)+" "+(str(comb[i])+"\n"))
I am finding the local maxima and local minima along with their corresponding positions with the following codes:
loc_mx=[]
loc_mn=[]
loc_mnt=[]
loc_mxt=[]
for i in range(len(comb)-2):
if comb[i] < comb[i+1]:
if comb[i+1] > comb[i+2]:
loc_mx.append(comb[i+1])
loc_mxt.append(i+3)
if comb[i] > comb[i+1]:
if comb[i+1] < comb[i+2]:
loc_mn.append(comb[i+1])
loc_mnt.append(i+3)
Interpolating the the data with the help of local maxima and local minima with following code
loc_mn.append(comb[len(comb)-1])
loc_mx.append(comb[len(comb)-1])
loc_mnt.append(k[len(comb)-1])
loc_mxt.append(k[len(comb)-1])
loc_mn.reverse
loc_mx.reverse
loc_mn.append(comb[0])
loc_mx.append(comb[0])
loc_mnt.append(k[0])
loc_mxt.append(k[0])
loc_mn.reverse
loc_mx.reverse
min_mnt=min(loc_mnt)
min_mxt=min(loc_mxt)
max_mnt=max(loc_mnt)
max_mxt=max(loc_mxt)
x1=loc_mxt
y1=loc_mx
f1=interpolate.interp1d(x1,y1,kind="cubic")
x2=loc_mnt
y2=loc_mn
f2=interpolate.interp1d(x2,y2,kind="cubic")
f1(k)
f2(k)
I am getting the following error.
File "emd.py", line 150, in <module>
int_dt.write(str(k[i])+" "+str(f1(k[i]))+" "+str(f2(k[i])))
File "/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.py", line 54, in __call__
y = self._evaluate(x)
File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 448, in _evaluate
out_of_bounds = self._check_bounds(x_new)
File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 475, in _check_bounds
raise ValueError("A value in x_new is below the interpolation "
ValueError: A value in x_new is below the interpolation range.
Would be grateful to get any help in this regard.
k? In the first block of codekis a scalar, but in the last block of codekis used like a list. The error is saying thatk[i]is below the range of interpolation which meansf1orf2is defined with anx1orx2whose values are all greater thank[i]. In other words, the interpolator can not extrapolate.krange from 0 to 1 (roughly). The values inx1andx2range over values much greater than 1. It doesn't look likex1andx2are being chosen from the values inkx1andx2by 10000. as you do fork?