473,378 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

? on scipy.fftpack

I've been debugging a simulation I wrote a while ago, and it seems that
the problem is in the fft module itself. I'm trying a simple test by
just feeding the function a basic real gaussian. Obviously, I should
get back the same real gaussian, but what I get is not even close. Can
anyone help me? Thanks in advance.

<code>
from scipy import *
import pylab

fft, ifft = fftpack.rfft, fftpack.irfft

def main():
sigma = 50.
x = arange(-100, 100, 1, 'f')
g = exp(-x**2 / (2 * sigma)) / sqrt(2 * pi)
testFFT(x, g)

def testFFT(x, f):
pylab.plot(x, f)
pylab.title('Initial gaussian')
pylab.show()
pylab.clf()

f = fft(f)
pylab.plot(x, f)
pylab.title('After first FFT')
pylab.show()
pylab.clf()

f = fft(f)
pylab.plot(x, f)
pylab.title('After first iFFt')
pylab.show()
pylab.clf()

if __name__ == '__main__': main()
</code>

Jun 28 '06 #1
3 3340
Mike Duffy wrote:
I've been debugging a simulation I wrote a while ago, and it seems that
the problem is in the fft module itself. I'm trying a simple test by
just feeding the function a basic real gaussian. Obviously, I should
get back the same real gaussian, but what I get is not even close. Can
anyone help me? Thanks in advance.


You will probably want to ask scipy questions on scipy-user. There aren't many
scipy people here.

http://www.scipy.org/Mailing_Lists

I haven't run your code, yet, but one of the things you are running into is the
FFT packing convention for FFTs on real functions. Please read the docstring:

Type: function
Base Class: <type 'function'>
String Form: <function rfft at 0x204fbf0>
Namespace: Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/scipy-0.5.0.1980-py2.4-mac
osx-10.4-ppc.egg/scipy/fftpack/basic.py
Definition: rfft(x, n=None, axis=-1, overwrite_x=0)
Docstring:
rfft(x, n=None, axis=-1, overwrite_x=0) -> y

Return discrete Fourier transform of real sequence x.

The returned real arrays contains
[y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2))] if n is even
[y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2)),Im(y(n/2))] if n is odd
where
y(j) = sum[k=0..n-1] x[k] * exp(-sqrt(-1)*j*k* 2*pi/n)
j = 0..n-1
Note that y(-j) = y(n-j).

Optional input:
n
Defines the length of the Fourier transform. If n is not
specified then n=x.shape[axis] is set. If n<x.shape[axis],
x is truncated. If n>x.shape[axis], x is zero-padded.
axis
The transform is applied along the given axis of the input
array (or the newly constructed array if n argument was used).
overwrite_x
If set to true, the contents of x can be destroyed.

Notes:
y == rfft(irfft(y)) within numerical accuracy.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jun 28 '06 #2

Robert Kern wrote:
You will probably want to ask scipy questions on scipy-user. There aren't many
scipy people here.

http://www.scipy.org/Mailing_Lists

I haven't run your code, yet, but one of the things you are running into is the
FFT packing convention for FFTs on real functions. Please read the docstring:


Ok, thanks a lot. I was unaware of that mailing list, I will certainly
go there next. I have read the documentation, but I'm not sure what
packing convention you are referring to.

Jun 28 '06 #3
Oops, sorry. I see what you mean. I was reading the docs for the
regular (complex) fft function, since that was what I was initially
having the bug with. I was just using the rfft to simplify things, but
I guess that was ironic. Anyway, I appreciate your help and don't mean
to burden you. Again, I will suubmit this to the scipy list.

Jun 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: avik | last post by:
Hi. I need to use SciPy (a library of scientific tools for python) but I runned upon a problem after installing it. I downloaded the binaries from scipy.org and copied the contents of the archive...
3
by: hawkesed | last post by:
Hi All, has anyone out there recently set up scipy on Windows? Cause I am trying to do so know and I am not having much luck. I have ActiveState and Plone. When I try to import scipy in...
1
by: tkpmep | last post by:
I installed SciPy and NumPy (0.9.5, because 0.9.6 does not work with the current version of SciPy), and had some teething troubles. I looked around for help and observed that the tutorial is dated...
0
by: Julien Fiore | last post by:
Hi, I have problems trying to install the scipy.weave package. I run Python 2.4 on windows XP and my C compiler is MinGW. Below is the output of scipy.weave.test(). I read that the tests should...
2
by: Aage Andersen | last post by:
I am exploring the modules scipy and linalg using python under Win XP and IDLE. Defining m=matrix( .. ) and trying to compute the inverse of m: I get an array: This is unfortunate. I...
1
by: tkpmep | last post by:
I'm trying to optimize a function using SciPy's optimize.fmin, but am clearly getting the syntax wrong, and would be grateful for some guiidance. First, here's the function def func(Y,x): """Y...
2
by: robert | last post by:
I'm using latest numpy & scipy. What is this problem ? : RuntimeError: module compiled against version 1000002 of C-API but this version of numpy is 1000009 Traceback (most recent call last):...
2
by: Peter Maas | last post by:
I tried some scipy examples using scipy 0.52, numpy 1.02 and python 2.5 on a WinXP SP2 machine. numpy.linalg.det() works but scipy.linalg.det() crashes python. Has anybody experienced this and can...
2
by: Frank Moyles | last post by:
Hi, I want to use SciPy library. I am using W2k, and ActiveState Python 2.5. I have succesfully numpy, but when I run the scipy-0.6.0.win32-py2.5.exe (from the downloads section on the SciPy...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.