Exemplo n.º 1
0
def prime_error_terms_in_dst():

    n = 128
    samples_per_unit =10
    cheby_list, cheby_ave_list, range_list= cheby_fun_real(n, samples_per_unit)

    plt.figure(1)
    plot_one_list(cheby_list, n, range_list, 'cheby')
    plot_one_list(range_list, n, range_list, 'x')
    #plt.show()

    plt.figure(2)

    # differ from cheby vs x itself
    # error = cheby - x
    error_terms = np.asarray(cheby_list) - np.asarray(range_list)
    plot_one_list(error_terms, n, range_list, 'error')
    #plt.show()

    # create a function
    # f2(x) = f(x) when x >=0
    # f2() = -f(-x) when x < 0
    # dst of f(x) will be -1/2j(fft(f2))
    error_term_ud = np.flipud(error_terms)
    error_term_ud_neg = np.multiply(-1, error_term_ud )

    error_term_extended = np.concatenate([error_term_ud_neg, error_terms])

    range_list_extended = range(0, len(error_term_extended))
    plt.figure(3)
    plot_one_list(error_term_extended, n,range_list_extended, 'error')
    plt.show()

    # fft of error terms, we use real fft, instead of fft
    error_terms_fft = np.fft.fft(error_term_extended)

    error_terms_fft_real = error_terms_fft.real
    error_terms_fft_imag = error_terms_fft.imag

    error_terms_fft_abs = np.absolute(error_terms_fft)
    error_terms_fft_abs = -1*error_terms_fft_abs

    error_terms_fft_abs_len = len(error_terms_fft_abs)

    print 'error_terms_fft_abs_len =', error_terms_fft_abs_len

    range_list2 = range(0, error_terms_fft_abs_len )
    range_list2_arr = np.asarray(range_list2)
    step = 1/float(samples_per_unit)
    range_list2_arr = np.multiply(step, range_list2_arr )

    plt.figure(3)
    # When we plot, we skip the DC term, because it can be quite larger.
    # plot_one_list(error_terms_fft_abs, n, range_list2_arr, 'error fft')
    plot_one_list(error_terms_fft_abs[1:], n, range_list2_arr[1:], 'error fft')
    plt.show()
    print error_terms
Exemplo n.º 2
0
def prime_error_terms_in_fft():

    n = 128
    samples_per_unit = 100
    cheby_list, cheby_ave_list, range_list= cheby_fun_real(n, samples_per_unit)

    plt.figure(1)
    plot_one_list(cheby_list, n, range_list, 'cheby')
    plot_one_list(range_list, n, range_list, 'x')
    #plt.show()

    plt.figure(2)

    # differ from cheby vs x itself
    # error = cheby - x
    error_terms = np.asarray(cheby_list) - np.asarray(range_list)
    plot_one_list(error_terms, n, range_list, 'error')
    #plt.show()

    # fft of error terms, we use real fft, instead of fft
    error_terms_fft = np.fft.rfft(error_terms)

    error_terms_fft_abs = np.absolute(error_terms_fft)
    error_terms_fft_abs = -1*error_terms_fft_abs

    error_terms_fft_abs_len = len(error_terms_fft_abs)

    print 'error_terms_fft_abs_len =', error_terms_fft_abs_len
    print 'len(range_list)', len(range_list)

    range_list2 = range(0, error_terms_fft_abs_len )
    range_list2_arr = np.asarray(range_list2)
    step = 1/float(samples_per_unit)
    range_list2_arr = np.multiply(step, range_list2_arr )

    plt.figure(3)
    # plot_one_list(error_terms_fft_abs, n, range_list2_arr, 'error fft')
    plot_one_list(error_terms_fft_abs[1:], n, range_list2_arr[1:], 'error fft')
    plt.show()
    print error_terms