My Python programming problem is the following:
I want to create an array of measurement results. Each result can be described as a normal distribution for which the mean value is the measurement result itself and the standard deviation is its uncertainty.
Pseudo code could be:
x1 = N(result1, unc1)
x2 = N(result2, unc2)
...
x = array(x1, x2, ..., xN)
Than I would like to calculate the FFT of x:
f = numpy.fft.fft(x)
What I want is that the uncertainty of the measurements contained in x is propagated through the FFT calculation so that f is an array of amplitudes along with their uncertainty like this:
f = (a +/- unc(a), b +/- unc(b), ...)
Can you suggest me a way to do this?
Each Fourier coefficient computed by the discrete Fourier transform of the array
x
is a linear combination of the elements ofx
; see the formula for X_k on the wikipedia page on the discrete Fourier transform, which I'll write as(That is,
X
is the discrete Fourier transform ofx
.) If x_n is normally distributed with mean mu_n and variance sigma_n**2, then a little bit of algebra shows that the variance of X_k is the sum of the variances of x_nIn other words, the variance is the same for each Fourier coefficent; it is the sum of the variances of the measurements in
x
.Using your notation, where
unc(z)
is the standard deviation ofz
,(Note that the distribution of the magnitude of X_k is the Rice distribution.)
Here's a script that demonstrates this result. In this example, the standard deviation of the
x
values increase linearly from 0.01 to 0.5.The printed output is
As expected, the sample variances of the Fourier coefficients are all (approximately) the same as the sum of the measurement variances.
Here's the plot generated by the script. The black diamonds are the Fourier coefficients of a single
x
vector. The blue dots are the Fourier coefficients of 800 realizations ofx + noise
. You can see that the point clouds around each Fourier coefficent are roughly symmetric and all the same "size" (except, of course, for the real coeffcients, which show up in this plot as horizontal lines on the real axis).