Skip to content

Fourier Transforms

Sambit Paul edited this page Dec 11, 2021 · 14 revisions

Forward Fourier Transform

We apply the Discrete Fourier Transform to decompose the signal and represent it as a sum of periodic components. On decomposition we get a real component and an imaginary component. For DFT on real signals, the frequencies are mirrored around the centre.

In this library, we are able to get all 4 variations:

  • Positive Absolute Values
  • Positive Complex Values
  • Full Absolute Values
  • Full Complex Values
The examples provided here use this signal:

\sin(40\pi t) + \frac{1}{2}\sin(400\pi t)

signal

CODE
Fourier dft = new DiscreteFourier(signal); //Works well for short signals (<200 points)
OR
Fourier dft = new FastFourier(signal); //Works well for longer signals (>200 points)
dft.transform();

dft

CODE
boolean onlyPositive = true;
double[] out = dft.getMagnitude(onlyPositive); //Positive Absolute
boolean onlyPositive = true;
double[][] out = dft.getComplex2D(onlyPositive); //Positive Complex
boolean onlyPositive = false;
double[] out = dft.getMagnitude(onlyPositive); //Full Absolute
boolean onlyPositive = false;
double[][] out = dft.getComplex2D(onlyPositive); //Full Complex

Inverse Discrete Fourier Transform

We apply the Inverse Discrete Fourier Transform to a complex sequence to reconstruct the original signal. This process also generate a signal with a real and an imaginary component.

In this library, the IDFT works in 2 modes:

  • For a real sequence
  • For a complex sequence
In the examples provided here the source signal is:

\sin(40\pi t) + \frac{1}{2}\sin(400\pi t)

sequence

CODE
// Automatically detects real and complex sequence and performs IDFT accordingly
InverseFourier idft = new InverseDiscreteFourier(complexSequence); //When DFT is performed using DiscreteFourier
OR
InverseFourier idft = new InverseFastFourier(complexSequence); //When DFT is performed using FasrFourier
idft.transform();
CODE
double[] outReal = idft.getReal(); //To get only the real component
double[] outAbsolute = idft.getMagnitude(); //To get the absolute value of the complex signal
double[][] out = idft.getComplex2D(); // To get the complex signal

The image shows the plot of the complex output. As you can see, the real component represents the original signal: \sin(40\pi t) + \frac{1}{2}\sin(400\pi t)

idft

Clone this wiki locally