def fft_deconvolve(num, denom):
    s1 = num.shape[-1]
    s2 = denom.shape[-1]
    valid = abs(s2-s1) + 1
    fsize = 2**np.ceil(np.log2(s1+s2-1))

    deconvolver = 1.0/(EPS + signal.fft(denom, fsize, axis=-1))
    deconvolved = np.real(signal.ifft(deconvolver * signal.fft(num, fsize, axis=-1), axis=-1))
    return deconvolved[..., :valid]
def fft_convolve(v1, v2):
    s1 = v1.shape[-1]
    s2 = v2.shape[-1]
    valid = abs(s2-s1) + 1
    fsize = 2**np.ceil(np.log2(s1+s2-1))

    convolver = (EPS + signal.fft(v2, fsize, axis=-1))
    convolved = np.real(signal.ifft(convolver * signal.fft(v1, fsize, axis=-1), axis=-1))
    return _centered(convolved, valid)
Example #3
0
 def _custom_fft(self, y, fs):
     T = 1.0 / fs
     print(T)
     N = y.shape[0]
     Y = fft(y)
     freq = np.fft.fftfreq(len(y), T)
     return freq[0:N // 2], 2.0 / N * np.abs(Y[0:N // 2])
Example #4
0
def fourrier_time_compute():
    """
    time a fourrier convolution that is 100 elements long
    """
    if fourrier_time_compute.K is None:
        R = 10000
        vec = scipy.array([1 + 1j] * R)
        t1 = time.clock()
        for i in range(100):
            c = fft(vec)
        t2 = time.clock()
        t_total = (t2 - t1) / 100
        fourrier_time_compute.K = t_total / (R * log(R))
    return fourrier_time_compute.K
def fourrier_time_compute():
    """
    time a fourrier convolution that is 100 elements long
    """
    if fourrier_time_compute.K is None:
        R = 10000
        vec = scipy.array([1+1j]*R)
        t1 = time.clock()
        for i in range(100):
            c = fft(vec)
        t2 = time.clock()
        t_total = (t2-t1)/100
        fourrier_time_compute.K = t_total/(R*log(R))
    return fourrier_time_compute.K
Example #6
0
def fast_snip1d(y, w=4, numiter=2):
    """
    """
    bkg = np.zeros_like(y)
    zfull = np.log(np.log(np.sqrt(y + 1.) + 1.) + 1.)
    for k, z in enumerate(zfull):
        b = z
        for i in range(numiter):
            for p in range(w, 0, -1):
                kernel = np.zeros(p * 2 + 1)
                kernel[0] = 0.5
                kernel[-1] = 0.5
                b = np.minimum(b, signal.fft(z, kernel, mode='same'))
            z = b
        bkg[k, :] = (np.exp(np.exp(b) - 1.) - 1.)**2 - 1.
    return bkg
Example #7
0
# try to flatten lightcurves using Fourier Filter

import scipy.signal as sci
import pylab as pl
import os


X = pl.load('speclc_Ha.dat')
x = X[:,0]
y = X[:,1]



fft = sci.fft(y-pl.average(y))

l = len(fft)
dt = x[1]-x[0]

# kill the negative frequencies
#fft[l/2:] = 0.0

# kill the low frequency bits > ~ 1hour
k = int(24.0*l*dt)
print k

fft[0:5] = 0.0
fft[-5:] = 0.0

yy = sci.ifft(fft)

Example #8
0
def fft_value(signal):
    """ Gets the fft of a signal.
    """
    import scipy.signal as sig
    return sig.fft(signal)
Example #9
0
flux = pl.array(flux)

temp = []
temp.append(date)
temp.append(phase)
temp.append(flux)

pl.save('HeIIlightcurve.dat',pl.array(temp).transpose())

lt = phase < 7.9

date = date[lt]
flux = pl.array(flux)[lt]
phase = pl.array(phase)[lt]
# flatten lightcurve using fourier method
fft = sci.fft(flux)
fft[0:4] = 0.0
fft[-4:] = 0.0
flux = sci.ifft(fft)

f,a = ast.signal.dft(date,flux,0,4000,1)
pl.figure()
pl.subplot(211)
pl.plot(phase,flux)
#pl.ylim(-5e-8,5e-8)
pl.subplot(212)
pl.plot(f,a)
sort,argsort = stats.fastsort(a)
print 'Max amplitude of %s at %s' % (a[argsort[-1]],f[argsort[-1]])
#print 'Second highest amplitude of %s at %s' % (a[argsort[-2]],f[argsort[-2]])
pl.show()
Example #10
0
 def four_transform(self):
     ft_df = signal.fft(self.data)
     return ft_df
Example #11
0
 def dofft(ar):
     return abs(fft(array(ar) * window)) ** 2