当前位置: 首页>>代码示例>>Python>>正文


Python fft.fft方法代码示例

本文整理汇总了Python中numpy.fft.fft方法的典型用法代码示例。如果您正苦于以下问题:Python fft.fft方法的具体用法?Python fft.fft怎么用?Python fft.fft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.fft的用法示例。


在下文中一共展示了fft.fft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _dhtm

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def _dhtm(mag):
    """Compute the modified 1D discrete Hilbert transform

    Parameters
    ----------
    mag : ndarray
        The magnitude spectrum. Should be 1D with an even length, and
        preferably a fast length for FFT/IFFT.
    """
    # Adapted based on code by Niranjan Damera-Venkata,
    # Brian L. Evans and Shawn R. McCaslin (see refs for `minimum_phase`)
    sig = np.zeros(len(mag))
    # Leave Nyquist and DC at 0, knowing np.abs(fftfreq(N)[midpt]) == 0.5
    midpt = len(mag) // 2
    sig[1:midpt] = 1
    sig[midpt+1:] = -1
    # eventually if we want to support complex filters, we will need a
    # np.abs() on the mag inside the log, and should remove the .real
    recon = ifft(mag * np.exp(fft(sig * ifft(np.log(mag))))).real
    return recon 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:fir_filter_design.py

示例2: get_tunes

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def get_tunes(tr_x, tr_y):
    v = np.zeros(len(tr_x))
    for i in range(len(v)): v[i] = float(tr_x[i])

    u = np.zeros(len(tr_y))
    for i in range(len(u)): u[i] = float(tr_y[i])

    sv = fft.fft(v)
    su = fft.fft(u)

    sv = np.abs(sv * np.conj(sv))
    su = np.abs(su * np.conj(su))

    freq = np.fft.fftfreq(len(sv))

    return (freq[np.argmax(sv[1:len(sv) / 2 - 1], axis=0)], freq[np.argmax(su[1:len(su) / 2 - 1], axis=0)]) 
开发者ID:ocelot-collab,项目名称:ocelot,代码行数:18,代码来源:madx.py

示例3: fftar

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def fftar(self, n=None):
        '''Fourier transform of AR polynomial, zero-padded at end to n

        Parameters
        ----------
        n : int
            length of array after zero-padding

        Returns
        -------
        fftar : ndarray
            fft of zero-padded ar polynomial
        '''
        if n is None:
            n = len(self.ar)
        return fft.fft(self.padarr(self.ar, n)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:fftarma.py

示例4: fftma

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def fftma(self, n):
        '''Fourier transform of MA polynomial, zero-padded at end to n

        Parameters
        ----------
        n : int
            length of array after zero-padding

        Returns
        -------
        fftar : ndarray
            fft of zero-padded ar polynomial
        '''
        if n is None:
            n = len(self.ar)
        return fft.fft(self.padarr(self.ma, n))

    #@OneTimeProperty  # not while still debugging things 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:fftarma.py

示例5: fftarma

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def fftarma(self, n=None):
        '''Fourier transform of ARMA polynomial, zero-padded at end to n

        The Fourier transform of the ARMA process is calculated as the ratio
        of the fft of the MA polynomial divided by the fft of the AR polynomial.

        Parameters
        ----------
        n : int
            length of array after zero-padding

        Returns
        -------
        fftarma : ndarray
            fft of zero-padded arma polynomial
        '''
        if n is None:
            n = self.nobs
        return (self.fftma(n) / self.fftar(n)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:fftarma.py

示例6: filter

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def filter(self, x):
        '''
        filter a timeseries with the ARMA filter

        padding with zero is missing, in example I needed the padding to get
        initial conditions identical to direct filter

        Initial filtered observations differ from filter2 and signal.lfilter, but
        at end they are the same.

        See Also
        --------
        tsa.filters.fftconvolve

        '''
        n = x.shape[0]
        if n == self.fftarma:
            fftarma = self.fftarma
        else:
            fftarma = self.fftma(n) / self.fftar(n)
        tmpfft = fftarma * fft.fft(x)
        return fft.ifft(tmpfft) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:fftarma.py

示例7: invpowerspd

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def invpowerspd(self, n):
        '''autocovariance from spectral density

        scaling is correct, but n needs to be large for numerical accuracy
        maybe padding with zero in fft would be faster
        without slicing it returns 2-sided autocovariance with fftshift

        >>> ArmaFft([1, -0.5], [1., 0.4], 40).invpowerspd(2**8)[:10]
        array([ 2.08    ,  1.44    ,  0.72    ,  0.36    ,  0.18    ,  0.09    ,
                0.045   ,  0.0225  ,  0.01125 ,  0.005625])
        >>> ArmaFft([1, -0.5], [1., 0.4], 40).acovf(10)
        array([ 2.08    ,  1.44    ,  0.72    ,  0.36    ,  0.18    ,  0.09    ,
                0.045   ,  0.0225  ,  0.01125 ,  0.005625])
        '''
        hw = self.fftarma(n)
        return np.real_if_close(fft.ifft(hw*hw.conj()), tol=200)[:n] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:fftarma.py

示例8: mode

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def mode(self, on):
        if on:
            self.changeState=1
            self.current=self.pwspec
            self.btnMode.setText("scope")
            self.btnMode.setIcon(Qt.QIcon(Qt.QPixmap(icons.scope)))
            self.btnMode.setChecked(True)
        else:
            self.changeState=0
            self.current=self.scope
            self.btnMode.setText("fft")
            self.btnMode.setIcon(Qt.QIcon(Qt.QPixmap(icons.pwspec)))
            self.btnMode.setChecked(False)
        if self.changeState==1:
            self.stack.setCurrentIndex(self.changeState)
            self.scope.plot.setDatastream(None)
            self.pwspec.plot.setDatastream(stream)
        else:
            self.stack.setCurrentIndex(self.changeState)
            self.pwspec.plot.setDatastream(None)
            self.scope.plot.setDatastream(stream) 
开发者ID:ggventurini,项目名称:dualscope123,代码行数:23,代码来源:main.py

示例9: to_powerspec

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def to_powerspec(x, sr, win_len, time_step):
    nperseg = int(win_len*sr)
    nperstep = int(time_step*sr)
    nfft = int(2**(ceil(log(nperseg)/log(2))))
    window = hanning(nperseg+2)[1:nperseg+1]

    indices = arange(int(nperseg/2), x.shape[0] - int(nperseg/2) + 1, nperstep)
    num_frames = len(indices)

    pspec = zeros((num_frames,int(nfft/2)+1))
    for i in range(num_frames):
        X = x[indices[i]-int(nperseg/2):indices[i]+int(nperseg/2)]
        X = X * window
        fx = fft(X, n = nfft)
        power = abs(fx[:int(nfft/2)+1])**2
        pspec[i,:] = power
    return pspec 
开发者ID:PhonologicalCorpusTools,项目名称:CorpusTools,代码行数:19,代码来源:representations.py

示例10: cconv

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def cconv(a, b):
    """
    Circular convolution of vectors

    Computes the circular convolution of two vectors a and b via their
    fast fourier transforms

    a \ast b = \mathcal{F}^{-1}(\mathcal{F}(a) \odot \mathcal{F}(b))

    Parameter
    ---------
    a: real valued array (shape N)
    b: real valued array (shape N)

    Returns
    -------
    c: real valued array (shape N), representing the circular
       convolution of a and b
    """
    return ifft(fft(a) * fft(b)).real 
开发者ID:mnick,项目名称:scikit-kge,代码行数:22,代码来源:util.py

示例11: ccorr

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def ccorr(a, b):
    """
    Circular correlation of vectors

    Computes the circular correlation of two vectors a and b via their
    fast fourier transforms

    a \ast b = \mathcal{F}^{-1}(\overline{\mathcal{F}(a)} \odot \mathcal{F}(b))

    Parameter
    ---------
    a: real valued array (shape N)
    b: real valued array (shape N)

    Returns
    -------
    c: real valued array (shape N), representing the circular
       correlation of a and b
    """

    return ifft(np.conj(fft(a)) * fft(b)).real 
开发者ID:mnick,项目名称:scikit-kge,代码行数:23,代码来源:util.py

示例12: cconv

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def cconv(a, b):
	"""
	Circular convolution of vectors

	Computes the circular convolution of two vectors a and b via their
	fast fourier transforms

	a \ast b = \mathcal{F}^{-1}(\mathcal{F}(a) \odot \mathcal{F}(b))

	Parameter
	---------
	a: real valued array (shape N)
	b: real valued array (shape N)

	Returns
	-------
	c: real valued array (shape N), representing the circular
	   convolution of a and b
	"""
	return ifft(fft(a) * fft(b)).real 
开发者ID:malllabiisc,项目名称:cesi,代码行数:22,代码来源:util.py

示例13: ccorr

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def ccorr(a, b):
	"""
	Circular correlation of vectors

	Computes the circular correlation of two vectors a and b via their
	fast fourier transforms

	a \ast b = \mathcal{F}^{-1}(\overline{\mathcal{F}(a)} \odot \mathcal{F}(b))

	Parameter
	---------
	a: real valued array (shape N)
	b: real valued array (shape N)

	Returns
	-------
	c: real valued array (shape N), representing the circular
	   correlation of a and b
	"""

	return ifft(np.conj(fft(a)) * fft(b)).real 
开发者ID:malllabiisc,项目名称:cesi,代码行数:23,代码来源:util.py

示例14: _frft2

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def _frft2(x, alpha):
    assert x.ndim == 2, "x must be a 2 dimensional array"
    m, n = x.shape
    # TODO please remove this confusing comment. Is it 'm' or 'm-1' ?
    # TODO If 'p = m', more code cleaning is easy to do.
    p = m  # m-1 # deveria incrementarse el sigiente pow
    y = zeros((2 * p, n), dtype=complex)
    z = zeros((2 * p, n), dtype=complex)

    j = indices(z.shape)[0]
    y[(p - m) // 2 : (p + m) // 2, :] = x * exp(
        -1.0j * pi * (j[0:m] ** 2) * float(alpha) / m
    )

    z[0:m, :] = exp(1.0j * pi * (j[0:m] ** 2) * float(alpha) / m)
    z[-m:, :] = exp(1.0j * pi * ((j[-m:] - 2 * p) ** 2) * float(alpha) / m)

    d = exp(-1.0j * pi * j ** 2 ** float(alpha) / m) * ifft(
        fft(y, axis=0) * fft(z, axis=0), axis=0
    )

    return d[0:m]


# TODO better docstring 
开发者ID:cihologramas,项目名称:pyoptools,代码行数:27,代码来源:frft.py

示例15: _ncc_c

# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fft [as 别名]
def _ncc_c(x, y):
    """
    >>> _ncc_c([1,2,3,4], [1,2,3,4])
    array([ 0.13333333,  0.36666667,  0.66666667,  1.        ,  0.66666667,
            0.36666667,  0.13333333])
    >>> _ncc_c([1,1,1], [1,1,1])
    array([ 0.33333333,  0.66666667,  1.        ,  0.66666667,  0.33333333])
    >>> _ncc_c([1,2,3], [-1,-1,-1])
    array([-0.15430335, -0.46291005, -0.9258201 , -0.77151675, -0.46291005])
    """
    den = np.array(norm(x) * norm(y))
    den[den == 0] = np.Inf

    x_len = len(x)
    fft_size = 1 << (2*x_len-1).bit_length()
    cc = ifft(fft(x, fft_size) * np.conj(fft(y, fft_size)))
    cc = np.concatenate((cc[-(x_len-1):], cc[:x_len]))
    return np.real(cc) / den 
开发者ID:johnpaparrizos,项目名称:kshape,代码行数:20,代码来源:core.py


注:本文中的numpy.fft.fft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。