Ejemplo n.º 1
0
def fct(vector):

    n = len(vector)
    
    # auxiliary array
    aux = np.zeros(n);
    for i in range(0, n):
	aux[i] = np.sin(np.pi*(i+0.5)/n)*(vector[i] - vector[n-i-1]) + 0.5*(vector[i] + vector[n-i-1])

    vCompl = myfft.realfft(aux)

    # rearrange to give cosine transform
    for i in range(0, n/2):
	vector[2*i] = np.cos(np.pi*i/n)*vCompl[i].real + np.sin(np.pi*i/n)*vCompl[i].imag


    vector[n-1] = -0.5*vCompl[n/2].real
    i = n/2-1;
    while i > 0:
	vector[2*i-1] = vector[2*i+1] - np.sin(np.pi*i/n)*vCompl[i].real + np.cos(np.pi*i/n)*vCompl[i].imag
	vector[2*i+1] *= -1
	i -= 1

    vector[1] *= -1

    return vector
Ejemplo n.º 2
0
def fst(vector):  # fast sine transform

    n = len(vector)

    # auxiliary array
    aux = np.zeros(n)
    for i in range(1, n):
        aux[i] = np.sin(i * np.pi / n) * (vector[i] + vector[n - i]) + 0.5 * (vector[i] - vector[n - i])

    vCompl = myfft.realfft(aux)

    # rearrange to give sine transform
    vector[0] = -vCompl[0].imag
    vector[1] = 0.5 * vCompl[0].real
    for i in range(1, n / 2):
        vector[2 * i] = -vCompl[i].imag
        vector[2 * i + 1] = vector[2 * i - 1] + vCompl[i].real

    return vector
Ejemplo n.º 3
0
def fst(vector):  # fast sine transform

    n = len(vector)

    # auxiliary array
    aux = np.zeros(n)
    for i in range(1, n):
        aux[i] = np.sin(i * np.pi / n) * (vector[i] + vector[n - i]) + 0.5 * (
            vector[i] - vector[n - i])

    vCompl = myfft.realfft(aux)

    # rearrange to give sine transform
    vector[0] = -vCompl[0].imag
    vector[1] = 0.5 * vCompl[0].real
    for i in range(1, n / 2):
        vector[2 * i] = -vCompl[i].imag
        vector[2 * i + 1] = vector[2 * i - 1] + vCompl[i].real

    return vector