计算FFT振幅的不确定度

2024-10-01 13:27:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我的Python编程问题如下:

我想创建一个测量结果数组。每个结果都可以描述为正态分布,其平均值是测量结果本身,标准偏差是其不确定度。在

伪代码可以是:

x1 = N(result1, unc1)
x2 = N(result2, unc2)
...

x = array(x1, x2, ..., xN)

我想计算x的FFT

^{pr2}$

我想要的是,x中包含的测量不确定度通过FFT计算传播,因此f是振幅的一个数组及其不确定度,如下所示:

f = (a +/- unc(a), b +/- unc(b), ...)

你能给我个建议吗?在


Tags: 代码fft编程数组array平均值x1x2
1条回答
网友
1楼 · 发布于 2024-10-01 13:27:14

由离散傅里叶变换计算的每个傅里叶系数 数组的xx元素的线性组合;请参见 关于wikipedia page on the discrete Fourier transform上X_k的公式, 我写为

X_k = sum_(n=0)^(n=N-1) [ x_n * exp(-i*2*pi*k*n/N) ]

(也就是说,X是{}的离散傅里叶变换。) 如果x帴n是正态分布的,且均值和方差σ2是正态分布的, 再加上一点代数,就可以知道X_k的方差是和 x的方差

^{pr2}$

换言之,每个傅立叶系数的方差是相同的; 它是x中测量值的方差之和。在

使用你的符号,其中unc(z)z的标准偏差

unc(X_0) = unc(X_1) = ... = unc(X_(N-1)) = sqrt(unc(x1)**2 + unc(x2)**2 + ...)

(请注意,xuk的量级的分布是Rice distribution。)

下面的脚本演示了这个结果。在本例中,标准 x值的偏差从0.01线性增加到0.5。在

import numpy as np
from numpy.fft import fft
import matplotlib.pyplot as plt


np.random.seed(12345)

n = 16
# Create 'x', the vector of measured values.
t = np.linspace(0, 1, n)
x = 0.25*t - 0.2*t**2 + 1.25*np.cos(3*np.pi*t) + 0.8*np.cos(7*np.pi*t)
x[:n//3] += 3.0
x[::4] -= 0.25
x[::3] += 0.2

# Compute the Fourier transform of x.
f = fft(x)

num_samples = 5000000

# Suppose the std. dev. of the 'x' measurements increases linearly
# from 0.01 to 0.5:
sigma = np.linspace(0.01, 0.5, n)

# Generate 'num_samples' arrays of the form 'x + noise', where the standard
# deviation of the noise for each coefficient in 'x' is given by 'sigma'.
xn = x + sigma*np.random.randn(num_samples, n)

fn = fft(xn, axis=-1)

print "Sum of input variances: %8.5f" % (sigma**2).sum()
print
print "Variances of Fourier coefficients:"
np.set_printoptions(precision=5)
print fn.var(axis=0)

# Plot the Fourier coefficient of the first 800 arrays.
num_plot = min(num_samples, 800)
fnf = fn[:num_plot].ravel()
clr = "#4080FF"
plt.plot(fnf.real, fnf.imag, 'o', color=clr, mec=clr, ms=1, alpha=0.3)
plt.plot(f.real, f.imag, 'kD', ms=4)
plt.grid(True)
plt.axis('equal')
plt.title("Fourier Coefficients")
plt.xlabel("$\Re(X_k)$")
plt.ylabel("$\Im(X_k)$")
plt.show()

打印输出为

Sum of input variances:  1.40322

Variances of Fourier coefficients:
[ 1.40357  1.40288  1.40331  1.40206  1.40231  1.40302  1.40282  1.40358
  1.40376  1.40358  1.40282  1.40302  1.40231  1.40206  1.40331  1.40288]

如预期,傅里叶系数的样本方差为 所有(大约)与测量方差之和相同。在

这是脚本生成的情节。黑钻石是 单个x向量的傅立叶系数。蓝点是 800个x + noise实现的Fourier系数。你可以看到 每个Fourier系数周围的点云大致是对称的 所有的“尺寸”都一样(当然,除了真正的系数, 在这个图中显示为实际轴上的水平线)。在

Plot of Fourier coefficients

相关问题 更多 >