Beispiel #1
0
def fft(data):
    """Compute the fast Fourier transform on the input data.

    The normalized output is relative to the positive frequencies and takes
    into account the power loss due to discarding half of the result.

    Keywords:
        data list of data values.

    Return:
        Normalized fft.
    """
    def nextpow(x, b):
        """Find the smallest integer p such that b ** p >= x.
        """
        p = 0
        n = 1
        while n < x:
            n *= b
            p += 1
        return p

    N = len(data)
    M = 2 ** nextpow(len(data), 2)
    normfact = 1.4142135623730951 / N
    data = normfact * _fft(data, M)
    return data[:N // 2]
Beispiel #2
0
def fft(*args):
    """
    Wrap MATLAB fft with numpy's
    """
    if (len(args) == 1):
        return _fft(args[0])
    tmp = list(args)
    try:
        if len(tmp[1]) == 0:
            # in case [] is specified (as MATLAB sees this as empty)
            tmp[1] = None
    except TypeError:
        # in the case that a number was specified that has no len
        pass
    # print(args)
    args = tuple(tmp)
    return _fft(*args)
Beispiel #3
0
def fft_BUG(n, x, y, sn):
    z=[x[i]+y[i]*1j for i in range(1,n+1)]
    z = array(z)
    if sn>0.0: z=_ifft(z)*n
    else:      z=_fft(z)
    for i in range(1,n+1):
        x[i]=z[i-1].real; y[i]=z[i-1].imag
    return (x,y)
Beispiel #4
0
def fft(n, x, y, sn):
    z=[x[i]+y[i]*1j for i in range(0,n)]
    z = array(z)
    if sn>0.0: z=_ifft(z)*n
    else:      z=_fft(z)
    xx = zeros(n+1,float); yy = zeros(n+1,float)
    for i in range(0,n):
        xx[i]=z[i].real; yy[i]=z[i].imag
    return (xx,yy)
Beispiel #5
0
def find_frequencies(data, freq = 44100, bits = 16):
    # Fast fourier transform
    n = len(data)
    p = _fft(data)
    uniquePts = numpy.ceil((n + 1) / 2.0)

    # Scale by the length (n) and square the value to get the amplitude
    p = [ (abs(x) / float(n)) ** 2 * 2 for x in p[0:uniquePts] ]
    p[0] = p[0] / 2
    if n % 2 == 0:
        p[-1] = p[-1] / 2

    # Generate the frequencies and zip with the amplitudes
    s = freq / float(n)
    freqArray = numpy.arange(0, uniquePts * s, s)
    return zip(freqArray, p)
Beispiel #6
0
def find_frequencies(data, freq = 44100, bits = 16):
    """Convert audio data into a frequency-amplitude table using fast fourier transformation. \
Returns a list of tuples (frequency, amplitude). Data should only contain one channel of audio."""

    # Fast fourier transform
    n = len(data)
    p = _fft(data)
    uniquePts = numpy.ceil((n + 1) / 2.0)

    # Scale by the length (n) and square the value to get the amplitude
    p = [ (abs(x) / float(n)) ** 2 * 2 for x in p[0:uniquePts] ]
    p[0] = p[0] / 2
    if n % 2 == 0:
        p[-1] = p[-1] / 2

    # Generate the frequencies and zip with the amplitudes
    s = freq / float(n)
    freqArray = numpy.arange(0, uniquePts * s, s)
    return zip(freqArray, p)
Beispiel #7
0
def find_frequencies(data, freq=44100, bits=16):
    """Convert audio data into a frequency-amplitude table using fast fourier \
transformation. Returns a list of tuples (frequency, amplitude). Data should \
only contain one channel of audio."""

    # Fast fourier transform

    n = len(data)
    p = _fft(data)
    uniquePts = numpy.ceil((n + 1) / 2.0)

    # Scale by the length (n) and square the value to get the amplitude

    p = [(abs(x) / float(n)) ** 2 * 2 for x in p[0:uniquePts]]
    p[0] = p[0] / 2
    if n % 2 == 0:
        p[-1] = p[-1] / 2

    # Generate the frequencies and zip with the amplitudes

    s = freq / float(n)
    freqArray = numpy.arange(0, uniquePts * s, s)
    return zip(freqArray, p)