# -------------------------------------------------------------
#  Functions for "fast" Fourier transform and Fourier synthesis
#  using numpy tools
# -------------------------------------------------------------
import numpy as np

def dft_fast_coeff(x):
    """
    Evaluate Fourier coefficients using Numpy's fast Fourier transform.
    This routine only returns the coefficients for the positive frequencies.
    If N is even, it goes up to n=N/2.
    If N is odd, it goes up to n=(N-1)/2.
    :param x: array of function samples
    """
    return np.fft.rfft(x, norm='forward')


def dft_fast_synthesis(fc, outnum='even'):
    """
    Use numpy's fast Fourier synthesis taking only Fourier coefficients for positive frequencies
    :param fc: aray of coefficients for positive frequencies only.
    :param outnum: specifies if output time series has an even or odd number of samples (default: 'even')
    """
    ns = 2*fc.size-2
    if outnum == 'odd': ns = 2*fc.size-1
    return np.fft.irfft(fc, ns, norm='forward')

