[Numpy-discussion] numpy.fft, yet again

Jochen Schröder cycomanic at gmail.com
Mon Jul 12 22:00:05 EDT 2010


On 13/07/10 08:04, Eric Firing wrote:
> On 07/12/2010 11:43 AM, David Goldsmith wrote:
>>   > From the docstring:
>>
>> "A[0] contains the zero-frequency term (the mean of the signal)"
>>
>> And yet, consistent w/ the definition given in the docstring (and
>> included w/ an earlier email), the code gives, e.g.:
>>
>>   >>>  import numpy as np
>>   >>>  x = np.ones((16,)); x
>> array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
>>           1.,  1.,  1.])
>>   >>>  y = np.fft.fft(x); y
>> array([ 16.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,
>>            0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,
>>            0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j])
>>
>> i.e., the zero-th term is the sum, not the mean (which, again, is
>> consistent w/ the stated defining formula).
>>
>> So, same ol', same ol': bug in the doc (presumably) or bug in the code?
>
> Bug in the doc.  Good catch.  "mean" is correct for the ifft, not for
> the fft.
>
> Eric
>

I'd say that a pointer to a discussion about normalization of ffts would 
be good here. The issue is that numpy is doing a normalization to len(x) 
for the inverse fft. However to make ffts unitary it should actually be 
that fft and ifft are normalized by sqrt(len(x)). And some fft 
implementations don't do normalizations at all (FFTW).

Cheers
Jochen

>>
>> DG
>>
>>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list