[SciPy-User] Interpolation with sinc

Samuel Garcia sgarcia at olfac.univ-lyon1.fr
Tue Oct 1 06:27:07 EDT 2013


Hi list and numerical experts,

I would like to do an interplation with sinc. sinc if often used for 
oversampling but it is not what I want, I really want an interpolation 
(= shift in a signal)
It seems that it is not in scipy.interpolate.inter1d.

Here an example, where I do interpolate with a spline with interp1d 
(sig1)  and my own sinc interpolation with loop (sig2) and with convole 
(sig3):

import numpy as np
from matplotlib import pyplot
from scipy.interpolate import interp1d


t = np.arange(500,1000)
sig = np.sin(2*np.pi*0.01*t)

delta = 0.2
t2 = np.arange(702, 802) - delta

# solution 1
# spline with interp1d
interpolator = interp1d(t,sig, kind = 1)
sig1 = interpolator(t2)

# solution 2
# with sinc loop
s = np.sinc(t-delta)
sig2 = np.zeros(t2.size)
for i in range(t2.size):
     for j in range(sig.size):
         sig2[i] += sig[j] * np.sinc(t2[i]-t[j])

# solution 3
# with sinc convole
half = t.size//2
sig3 = np.convolve(sig, np.sinc(np.arange(-half, half)-delta+1), mode = 
'same')
sig3 = sig3[202:302]

pyplot.plot(t, sig, 'or-')
pyplot.plot(t2, sig1, '*b-')
pyplot.plot(t2, sig2, '^g-')
pyplot.plot(t2, sig3, '+y-')
pyplot.show()



The loop (solution 2) is slow of course. The version 2 is better because 
vectorized but it compute the all signal and then take a part after.
Does some one have a better solution than would look like solution 3 but 
do take all point ?



Thanks a lot.


Samuel garcia


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Samuel Garcia
Lyon Neuroscience
CNRS - UMR5292 -  INSERM U1028 -  Universite Claude Bernard LYON 1
Equipe R et D
50, avenue Tony Garnier
69366 LYON Cedex 07
FRANCE
Tél : 04 37 28 74 24
Fax : 04 37 28 76 01
http://olfac.univ-lyon1.fr/unite/equipe-07/
http://neuralensemble.org/trac/OpenElectrophy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




More information about the SciPy-User mailing list