Esempio n. 1
0
def test5():
    N = 1024
    H = genfhilbert(N)
    hc = fourier.ifft(H)
    h0 = [samp.real for samp in hc]
    #NOTE: h0 has the impulse response centered about sample 0
    #Negative time is the second half!
    h = h0[N//2:] + h0[0:N//2] + [h0[0]] # Number of samples becomes odd!
    stemplot(h)
Esempio n. 2
0
    def measure_methods(self, stopwatch, fil_data, freqs, DM, scale):
        """
            Run and time all methods/modules
        """
        # clipping

        time_clipping = timer()
        _, _ = clipping.clipping(freqs, fil_data)
        stopwatch['time_clipping'] = timer() - time_clipping
        # dedisperse
        time_dedisp = timer()
        fil_data = dedisperse.dedisperse(fil_data, disperion_measure=DM)
        stopwatch['time_dedisp'] = timer() - time_dedisp
        # timeseries
        time_t_series = timer()
        time_series = timeseries.Timeseries(fil_data)
        stopwatch['time_t_series'] = timer() - time_t_series
        # downsample
        time_downsamp = timer()
        time_series = time_series.downsample(scale)
        stopwatch['time_downsample'] = timer() - time_downsamp
        # fft vect
        time_fft_vect = timer()
        fourier.fft_vectorized(time_series)
        stopwatch['time_fft_vect'] = timer() - time_fft_vect
        # dft
        time_dft = timer()
        fourier.dft_slow(time_series)
        stopwatch['time_dft'] = timer() - time_dft
        # ifft
        time_ifft = timer()
        fourier.ifft(time_series)
        stopwatch['time_ifft'] = timer() - time_ifft
        # fft freq
        time_fft_freq = timer()
        fourier.fft_freq(10)
        stopwatch['time_fft_freq'] = timer() - time_fft_freq
        return stopwatch
Esempio n. 3
0
def fft_repack(avg_len, std_len, child_len, pow, c1, c2, a1, a2):
    # Zero-pad c1 and c2 if necessary
    c1.extend([0 for i in range(nextpow2(len(c1)) - len(c1))])
    c2.extend([0 for i in range(nextpow2(len(c2)) - len(c2))])

    # Invert fft
    c1   = ifft(c1)
    c2   = ifft(c2)

    #print "Truncated"
    c1 = c1[:child_len]
    c2 = c2[:child_len]
    # TODO -- try interpolating back down to a smaller (child_len) size?
    #print "fft crossover from:", \
    #        len(org1['org'][0]), len(org2['org'][0]), \
    #        "to", len(c1), len(c2)

    # Get rid of imaginary components...
    c1 = [ele.real for ele in c1]
    c2 = [ele.real for ele in c2]

    c1, c2 = repack(c1, c2, a1, a2)
    return c1, c2
Esempio n. 4
0
def test6():
    N = 1024
    f = 10
    signal = [math.sin(2*f*math.pi*x/N) for x in xrange(N)]
    Fsignal = fourier.fft(signal)
    H = genfhilbert(N)
    HFsignal = [Fsignal[i]*H[i] for i in xrange(len(Fsignal))]
    hsignalc = fourier.ifft(HFsignal)
    hsignal = [samp.real for samp in hsignalc]
    mag = [math.sqrt(signal[x]*signal[x] + hsignal[x]*hsignal[x]) for x in xrange(len(hsignal))]
    fig, ax = pyplot.subplots(1)
    ax.plot(hsignal,'-r')
    ax.plot(signal,'-b')
    ax.plot(mag,'-k')
    pyplot.show()
Esempio n. 5
0
def kernel(F, G, t=None):

    assert len(F) == len(G), "Input arrays must have equal length"
    if len(t) == 0: t = np.arange(len(F))

    # Calculate the fourier transforms of F and G
    FF, f = fft(F, t)
    FG, _ = fft(G, t)

    # Calculate the inverse fourier transform of the quotient
    k, tt = ifft(FG / FF, f)
    k = np.real(k)

    # Sort results by time value
    sort = np.argsort(tt)
    k = k[sort]
    tt = tt[sort]

    return k, tt
Esempio n. 6
0
def test9():
    N = 128
    H = genf2hilbert(N)
    hc = fourier.ifft(H)
    h0 = [samp.imag for samp in hc]
    h = h0[N//2:] + h0[0:N//2] + [h0[0]]
    print len(h)
    stemplot(h)
    #Signal
    Nsig = 1024
    f = 50
    signal = [math.sin(2*f*math.pi*x/Nsig) for x in xrange(Nsig)]
    hilbsign, origsign = convolution.convolveorig(h, N//2, signal)
    mag = [math.sqrt(origsign[x]*origsign[x] + hilbsign[x]*hilbsign[x]) for x in xrange(len(hilbsign))]
    fig, ax = pyplot.subplots(1)
    ax.plot(hilbsign,'-r')
    ax.plot(origsign,'-b')
    ax.plot(mag,'-k')
    pyplot.show()
Esempio n. 7
0
def test10():
    N = 1024
    f = 25
    dd = N/2
    nn = N/10
    signal = [math.exp(-((dd-x)/nn)**2/2)*math.sin(2*f*math.pi*x/N) for x in xrange(N)]
    ###
    Fsignal = fourier.fft(signal)
    H = genf2hilbert(N)
    HFsignal = [Fsignal[i]*H[i] for i in xrange(len(Fsignal))]
    hsignalc = fourier.ifft(HFsignal)
    hsignal = [samp.imag for samp in hsignalc]
    rsignal = [samp.real for samp in hsignalc]
    mag = [abs(hsignalc[x]) for x in xrange(len(hsignalc))]
    ###
    fig, ax = pyplot.subplots(1)
    ax.plot(signal,'-b')
    ax.plot(hsignal,'-r')
    ax.plot(mag,'-k')
    pyplot.show()
Esempio n. 8
0
def test11():
    N = 1024
    f = 25
    dd = N/2
    nn = N/10
    signal = [math.exp(-((dd-x)/nn)**2/2)*math.sin(2*f*math.pi*x/N) for x in xrange(N)]
    ###
    Nhilb = 256
    H = genf2hilbert(Nhilb)
    hc = fourier.ifft(H)
    h0 = [samp.imag for samp in hc]
    h = h0[Nhilb//2:] + h0[0:Nhilb//2] + [h0[0]]
    ###
    hsignal, origsig = convolution.convolveorig(h, Nhilb//2, signal)
    mag = [math.sqrt(origsig[x]*origsig[x] + hsignal[x]*hsignal[x]) for x in xrange(len(hsignal))]
    ###
    fig, ax = pyplot.subplots(1)
    ax.plot(origsig,'-b')
    ax.plot(hsignal,'-r')
    ax.plot(mag,'-k')
    pyplot.show()
Esempio n. 9
0
def test7():
    N = 1024
    f = 20
    signal = [math.sin(2*f*math.pi*x/N) for x in xrange(N)]
    #signal = [0]*512 + [1] + [0]*511
    t = [x/N for x in xrange(N)]
    Nhilb = 128
    H = genfhilbert(Nhilb)
    hc = fourier.ifft(H)
    h0 = [samp.real for samp in hc]
    hilb = h0[Nhilb//2:] + h0[0:Nhilb//2] + [h0[0]]
    print len(hilb)
    hilbsign, origsign = convolution.convolveorig(hilb, 64, signal)
    print len(origsign)
    print len(hilbsign)
    #fig, ax = pyplot.subplots(1)
    #ax.plot(t, signal,'-')
    #pyplot.show()
    mag = [math.sqrt(origsign[x]*origsign[x] + hilbsign[x]*hilbsign[x]) for x in xrange(len(hilbsign))]
    fig, ax = pyplot.subplots(1)
    ax.plot(hilbsign,'-r')
    ax.plot(origsign,'-b')
    ax.plot(mag,'-k')
    pyplot.show()