<br><br><div><span class="gmail_quote">On 8/29/07, <b class="gmail_sendername">Anne Archibald</b> <<a href="mailto:peridot.faceted@gmail.com">peridot.faceted@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 29/08/2007, Charles R Harris <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:<br><br>> > Is this also appropriate for the other FFTs? (inverse real, complex,<br>> > hermitian, what have you) I have written a quick hack (attached) that
<br>> > should do just that rescaling, but I don't know that it's a good idea,<br>> > as implemented. Really, for a complex IFFT it's extremely peculiar to<br>> > add the padding where we do (between frequency -1 and frequency zero);
<br>> > it would make more sense to pad at the high frequencies (which are in<br>> > the middle of the array). Forward FFTs, though, can reasonably be<br>> > padded at the end, and it doesn't make much sense to rescale the last
<br>> > data point.<br>><br>> It all depends on the data and what you intend. Much of my experience is<br>> with Michaelson interferometers and in that case the interferogram is<br>> essentially an autocorrelation, so it is desirable to keep its center at
<br>> sample zero and let the left side wrap around, so ideally you fill in the<br>> middle as you suggest. You can also pad at the end if you don't put the<br>> center at zero, but then you need to phase shift the spectrum in a way that
<br>> corresponds to rotating the center to index zero and padding in the middle.<br>> I expect you would want to do the same thing for complex transforms if they<br>> are of real data and do the nyquist divided by two thingy. If the high
<br>> frequencies in a complex transform are actually high frequencies and not<br>> aliases of negative frequencies, then you will want to just append zeros.<br>> That case also occurs,  I have designed decimating complex filters that
<br>> produce output like that, they were like single sideband in the radi o<br>> world.<br><br>So is it a fair summary to say that for irfft, it is fairly clear that<br>one should adjust the Nyquist coefficient, but for the other varieties
<br>of FFT, the padding done by numpy is just one of many possible<br>choices?<br><br>Should numpy be modified so that irfft adjusts the Nyquist<br>coefficient? Should this happen only for irfft?</blockquote><div><br>Yes, I think that should be the case. If the complex transforms pad in the middle, then they are treating the high frequencies as aliases, but unless they explicitly duplicate the Nyquist coefficient scaling isn't needed. Hmm, actually, I think that is wrong. The original data points will be reproduced, but what happens in between points? In between there is a difference between positive and negative frequences. So in a complex transform of real data one would want to split the Nyquist coefficient between high and low frequencies. I don't think it is possible to make a general statement about the complex case. Just hope the middle frequency is zero so you can ignore the problem ;)  
<br><br>What happens in the real case is that the irfft algorithm uses the Hermitean symmetry of the spectrum, so the coefficient is implicitly duplicated.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> I usually multiply the forward transform by the sample interval, in secs or<br>> cm, and the unscaled inverse transform by the frequency sample interval, in<br>> Hz or cm^-1. That treats both the forward and inverse fft like
<br>> approximations to the integral transforms and makes the units those of<br>> spectral density. If you think trapezoidal rule, then you will also see<br>> factors of .5 at the ends, but that is a sort of apodization that is
<br>> consistent with how Fourier series converge at discontinuities. In the<br>> normal case where no interpolation is done the product of the sample<br>> intervals is 1/N, so it reduces to the usual convention. Note that in your
<br>> example the sampling interval decreases when you do the interpolation, so if<br>> you did another forward transform it would be scaled down to account for the<br>> extra points in the data.<br><br>That's a convenient normalization.
<br><br>Do you know if there's a current package to associate units with numpy<br>arrays? For my purposes it would usually be sufficient to have arrays<br>of quantities with uniform units. Conversions need only be<br>
multiplicative (I don't care about Celsius-to-Fahrenheit style<br>conversions) and need not even be automatic, though of course that<br>would be convenient. Right now I use Frink for that sort of thing, but<br>it would have saved me from making a number of minor mistakes in
<br>several pieces of python code I've written.</blockquote><div><br>There was a presentation by some fellow from CalTech at SciPy 2005 (4?) about such a system, but ISTR it looked pretty complex. C++ template programming does it with traits and maybe the Enthought folks have something useful along those lines. Otherwise, I don't know of any such system for general use. Maybe ndarray could be subclassed? It can be convenient to multiply and divide units, so maybe some sort of string with something to gather the same units together with a power could be a useful way to track them and wouldn't tie one down to any particular choice.
<br><br>Chuck<br></div></div><br>