Why Does My FFT Integration Method Produce Nonzero Imaginary Parts?

  • Thread starter Thread starter SchroedingersLion
  • Start date Start date
  • Tags Tags
    Fft Integrals
Click For Summary

Discussion Overview

The discussion revolves around issues encountered while implementing a discrete Fourier transform (FFT) method for integrating functions, specifically the sine function, in the context of solving partial differential equations (PDEs). Participants explore potential errors in the integration method and the resulting nonzero imaginary parts in the output signal.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant expresses frustration over their FFT integration method producing nonzero imaginary parts when integrating a real function, suggesting a possible error in their theoretical formula.
  • Another participant notes that understanding the underlying mechanics of FFT is crucial and suggests that direct experience may be necessary for troubleshooting.
  • A participant mentions that FFT is commonly used for calculating integrals of acceleration from IMUs, implying that related literature may provide insights.
  • One participant proposes that the issue might be related to normalization of the FFT.
  • Another participant questions the need for certain exponential terms in the inverse transform, indicating a potential misunderstanding of their role.
  • A later reply identifies a possible mistake in the application of the Fourier transform properties, suggesting that the relationship between the discrete Fourier transform and the function's shifted version may not hold as assumed.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific cause of the issue. Multiple competing views and hypotheses regarding the integration method and its implementation remain, with some participants questioning the formula and others suggesting different aspects to investigate.

Contextual Notes

There are indications of missing assumptions regarding the application of the Fourier transform and its properties. The discussion reflects uncertainty about the normalization process and the handling of discrete data points in the FFT implementation.

SchroedingersLion
Messages
211
Reaction score
56
TL;DR
I am posting this in the EE forum since electrical engineers are typically skilled with Fourier transforms.
Hi guys,

for a project I had to get involved with discrete Fourier transforms to solve PDEs.
However, the code that I implemented according to a pseudo-code from a paper did not work - it seems like I calculated integrals incorrectly.

To search the error, I tried to integrate the sin(x) function with my method, and it did not work.
I already posted the formula I used for this sine integration, as well as the code, here:
https://scicomp.stackexchange.com/questions/33886/calculate-integrals-using-numpy-fft
Does anyone know what I am doing wrong? The error does not depend on N, and after my inverse FT my signal contains nonzero imaginary parts which should not happen! Is there something wrong with my formula?

I am a bit desperate, since my deadlines are getting closer...
SL
 
Last edited:
Engineering news on Phys.org
I don't think you're going to get much help with Thanksgiving coming up tomorrow.

I saw on Stack you got a couple of responses already.

These are the kinds of problems where you really need to dig in and gain some insight into what is actually going on. Sadly, unless someone has direct experience here its unlikely you'll get the help you need.

As a programmer, I can relate to using a function to do something not really knowing what's going on and trusting that it works as advertised. Most notably are the various integrators that folks like to use like Runge-Kutta RK4 and I have no idea how it does its magic but hey it works so I've use it.

Jedi
 
Don't know about Thanksgiving, I am sitting in Europe ^^

I only got two comments, and they imply that something seems to be wrong with the formula.
Isn't this a complete basic problem? I thought that was a trivial question for people who know their way around FTs.

edit: I edited the question, maybe it was not clear that I am talking about integration of sin(x) using fft in this example.
 
I can't help you directly but people use the FFT method for calculating integrals of acceleration to get velocity and position from IMUs (Inertial Measuring Units). The students here seem to find plenty of resources for doing this calculation in the IMU literature. Perhaps looking at some of this stuff may help.

Cheers
 
  • Like
Likes   Reactions: jedishrfu
Isn't it just a question of normalization of the FFT?
 
I would not know how. The deviation I am seeing is independent of number of data points N. Moreover, my final vector after the inverse transform has nonzero imaginary parts which should be impossible when I take the FFT of a purely real signal. To me, it looks like there is an error in my theoretical formula.

I expand the function in a Fourier series under the integral and truncate it for ##|k|>m##. In my code, I only know the function on ##2m+1## discrete data points and I try to calculate the ##A_k##, i.e. the coefficients of the Fourier series, via a FFT. Maybe there is something wrong with this approach?
 
You might have forgotten to multiply by the last ##e^{2piky}## term in your loop.
 
But why would I need these? They are simply the usual exponentials of the inverse transform, they do not belong to the amplitudes that are given by ifft.
 
I think I found the mistake.
If I know the discrete Fourier transform, i.e. $$ A_k =\sum_{i=-N}^{N} f(x_i)\cdot e^{-i2\pi x_i k}$$ and I write $$ f(x_i)=\sum_{k=-N}^{N} A_k\cdot e^{i2\pi x_i k},$$ then it does not follow that
$$f(x_i+y)=\sum_{k=-N}^{N} A_k\cdot e^{i2\pi (x_i+y) k}.$$

I tested this with a small code:

error.PNG


This would explain why I have not found this kind of integration online :D

What do you think?
 

Attachments

  • error.PNG
    error.PNG
    15.8 KB · Views: 231
  • error.PNG
    error.PNG
    15.1 KB · Views: 254
Last edited:

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 24 ·
Replies
24
Views
5K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K