首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何计算nfft

如何计算nfft
EN

Stack Overflow用户
提问于 2019-08-09 18:47:50
回答 1查看 2K关注 0票数 3

我正在努力理解如何使用nfft方法的 module。不幸的是,这个例子并没有很好的说明性,因为我试图仅仅基于一个样本输入列表([(time0, signal0), (time1, signal1), ...])将所有内容参数化:

代码语言:javascript
复制
import numpy as np
from nfft import nfft

# define evaluation points
x = -0.5 + np.random.rand(1000)

# define Fourier coefficients
N = 10000
k = - N // 2 + np.arange(N)
f_k = np.random.randn(N)

# non-equispaced fast Fourier transform
f = nfft(x, f_k)

我试图在一个例子中计算f_k,其中样本间隔约10毫秒,间隔内有1到2毫秒的抖动。

执行文件:

代码语言:javascript
复制
def nfft(x, f_hat, sigma=3, tol=1E-8, m=None, kernel='gaussian',
         use_fft=True, truncated=True):
    """Compute the non-equispaced fast Fourier transform

    f_j = \sum_{-N/2 \le k < N/2} \hat{f}_k \exp(-2 \pi i k x_j)

    Parameters
    ----------
    x : array_like, shape=(M,)
        The locations of the data points. Each value in x should lie
        in the range [-1/2, 1/2).
    f_hat : array_like, shape=(N,)
        The amplitudes at each wave number k = range(-N/2, N/2).

我被困在那里:

代码语言:javascript
复制
import numpy as np
from nfft import nfft

def compute_nfft(sample_instants, sample_values):
    """
    :param sample_instants: `numpy.ndarray` of sample times in milliseconds
    :param sample_values: `numpy.ndarray` of samples values
    :return: Horizontal and vertical plot components as `numpy.ndarray`s
    """
    N = len(sample_instants)
    T = sample_instants[-1] - sample_instants[0]
    x = np.linspace(0.0, 1.0 / (2.0 * T), N // 2)
    y = 2.0 / N * np.abs(y[0:N // 2])
    y = nfft(x, y)
    return (x, y)
EN

回答 1

Stack Overflow用户

发布于 2019-08-09 20:58:07

该示例定义了一个变量f_k,该变量作为nfftf_hat参数传递。

f_j = \sum_{-N/2 \le k< N/2} \hat{f}_k \exp(-2 \pi i x_j)

给定情况下,f_hat表示指定采样瞬间的时域信号.在您的例子中,这只是对应于sample_values

另一个参数x of nfft是这些样本的实际时间瞬间。您还需要单独提供这些内容:

代码语言:javascript
复制
def compute_nfft(sample_instants, sample_values):
    N = len(sample_instants)
    T = sample_instants[-1] - sample_instants[0]
    x = np.linspace(0.0, 1.0 / (2.0 * T), N // 2)
    y = nfft(sample_instants, sample_values)
    y = 2.0 / N * np.abs(y[0:N // 2])
    return (x, y)
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57435660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档