Solving FFT Problems with MATLAB and FFTW in C

  • MATLAB
  • Thread starter birdhen
  • Start date
In summary, the speaker is having trouble with calculating the potential of a system from the overdensity using Fast Fourier Transforms. They have tried different approaches for handling the value of k=0, but are unsure of the correct solution and are seeking help.
  • #1
birdhen
35
0
Hi there,

I am having trouble with some Fast Fourier Transforms.
I have been using both MATLAB and FFTW in c.
The problem is that I want to calculate the potential of a system from the overdensity. The equation in Fourier space is simple

phi(k)= -del(k)/(k^2) ,

where del is the overdensity, phi is the potential and k is the wavenumber.

To test this I use a simple del(x) = x, and feed this into the fft. I then run through the k values and divide through by k squared. When k =0, I am not sure what to do as obviously you can't divide by zero.
I have tried a variety of things such as setting phi(k) = 0 when k=0, or just leaving phi(k) = del(k)..both of which I am sure are wrong.

When I reverse FFT this phi(k), my result is always a sine wave with a wavelength the size of the x range, where as I am expecting (1/6)*x^3.

I am having trouble finding the answer online. Maybe I am searching for the wrong thing. Can anyone help?
Best wishes,
 
Physics news on Phys.org
  • #2
birdhen said:
When k =0, I am not sure what to do as obviously you can't divide by zero.
I have tried a variety of things such as setting phi(k) = 0 when k=0, or just leaving phi(k) = del(k)..both of which I am sure are wrong.
The best choice here is to set up a grid of points such that ##k=0## is not included. This may require a shift that will add a complex phase to the result of the FFT, which can then be removed.
 

1. What is FFT and why is it important?

FFT (Fast Fourier Transform) is a mathematical algorithm used to analyze and transform signals from the time domain to the frequency domain. It is important because it allows for efficient analysis and processing of signals, making it a crucial tool in many scientific and engineering applications.

2. What is the difference between MATLAB and FFTW in C?

MATLAB is a high-level programming language and interactive environment designed for numerical computation and visualization. It has built-in functions for FFT calculations and is generally easier to use for beginners. FFTW (Fastest Fourier Transform in the West) is a C library that provides highly optimized routines for computing FFTs. It requires more programming knowledge but can offer faster performance for large datasets.

3. How do I use FFT in MATLAB?

To use FFT in MATLAB, you can use the built-in function "fft" which takes in a signal as an input and returns its discrete Fourier transform (DFT). You can also use the "fft2" function for 2-dimensional signals or "fftn" for n-dimensional signals. Remember to specify the sampling frequency and number of data points in the input signal when using these functions.

4. How do I use FFTW in C?

To use FFTW in C, you first need to download and install the library on your system. Then, you can include the necessary header files and link the library to your code. You can then use the "fftw_plan_dft_1d" function to create a plan for computing the FFT of a 1-dimensional signal and "fftw_execute" to actually perform the transformation.

5. How do I interpret the results of FFT?

The result of FFT is a complex array of numbers representing the frequencies and their corresponding amplitudes in the input signal. The magnitude of each complex number represents the amplitude of the corresponding frequency, and the phase represents the phase shift of that frequency. To visualize the results, you can plot the magnitude spectrum or use the "abs" function to get the magnitudes and the "angle" function to get the phases.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
560
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top