Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast Fourier Transform difference in result between wolframalpha and commons-math

I have a question related with Fast Fourier Transform. I downloaded "Math Commons 3.2" library where is FFT. But the result is different than I expected.

For instance, for data like, real: 1,0,0,0,0,0,0,0,0 imaginary: 0,0,0,0,0,0,0,0,0 I've got, real:1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 imaginary:0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 the same result I've got when I used this code (in "public static main" section this example exist as a "test") but in wolframalpha the real values are all 1/3 rather than 1.0.

The question:
Where/What is a difference and how can I get the same result like in wolframalpha
Best regards
Dawid D

like image 722
Dawid D Avatar asked Mar 23 '23 01:03

Dawid D


1 Answers

Ideally, the Discrete Fourier Transform is an orthonormal transformation. It just rotates the coordinate system to give a different set of coordinates for the same point in space.

Many implementations of the DFT are not normal; they change the magnitude of the vector simply for computational convenience. Essentially, all the additions they do multiply the vector length by the number of elements in it, and the implementations never multiply or divide to compensate for that.

Observe that the length of the vector WolframAlpha returned to you is 1, the same as the length of the input vector. (The length is the square root of the sum of the squares of the elements. The length of the input vector is sqrt(1+0+0+0+0+0+0+0+0) = 1. The length of the output vector is sqrt(1/9+1/9+1/9+1/9+1/9+1/9+1/9+1/9) = 1.)

It is a common convention for DFT implementations to ignore the normalization and return scaled results. This works because most operations used on the transform results do not care about the absolute magnitude. Additionally, a common process is to compute one or more DFTs, combine or process the results, and compute an inverse DFT. If the scaling is part of the DFTs, then it must be performed in each DFT and each inverse DFT. If you leave the scaling out of the DFTs, then the application can combine all of the scales that are involved into a single scaling operation at the end. It is better for computing performance to do a scaling once than many times, so this is preferred.

like image 75
Eric Postpischil Avatar answered Apr 06 '23 08:04

Eric Postpischil