我正在努力理解如何使用nfft方法的 module。不幸的是,这个例子并没有很好的说明性,因为我试图仅仅基于一个样本输入列表([(time0, signal0), (time1, signal1), ...])将所有内容参数化:
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毫秒的抖动。
执行文件:
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).我被困在那里:
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)发布于 2019-08-09 20:58:07
该示例定义了一个变量f_k,该变量作为nfft的f_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是这些样本的实际时间瞬间。您还需要单独提供这些内容:
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)https://stackoverflow.com/questions/57435660
复制相似问题