This is the java implementation of performing Discrete Fourier Transform using Fast Fourier Transform algorithm. This class finds the DFT of N (power of 2) complex elements, generated randomly, using FFT. The input to the class is a two dimensional array of sequence.
Here is the source code of the Java Perform to a 2D FFT Inplace Given a Complex 2D Array. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
//This is a sample program to perform 2D FFT inplace
import java.util.Scanner;
public class TwoD_FFT
{
static void twoDfft(double[][] inputData, double[][] realOut,
double[][] imagOut, double[][] amplitudeOut)
{
int height = inputData.length;
int width = inputData[0].length;
// Two outer loops iterate on output data.
for (int yWave = 0; yWave < height; yWave++)
{
for (int xWave = 0; xWave < width; xWave++)
{
// Two inner loops iterate on input data.
for (int ySpace = 0; ySpace < height; ySpace++)
{
for (int xSpace = 0; xSpace < width; xSpace++)
{
// Compute real, imag, and ampltude.
realOut[yWave][xWave] += (inputData[ySpace][xSpace] * Math
.cos(2
* Math.PI
* ((1.0 * xWave * xSpace / width) + (1.0
* yWave * ySpace / height))))
/ Math.sqrt(width * height);
imagOut[yWave][xWave] -= (inputData[ySpace][xSpace] * Math
.sin(2
* Math.PI
* ((1.0 * xWave * xSpace / width) + (1.0
* yWave * ySpace / height))))
/ Math.sqrt(width * height);
amplitudeOut[yWave][xWave] = Math
.sqrt(realOut[yWave][xWave]
* realOut[yWave][xWave]
+ imagOut[yWave][xWave]
* imagOut[yWave][xWave]);
}
System.out.println(realOut[yWave][xWave] + " + "
+ imagOut[yWave][xWave] + " i");
}
}
}
}
public static void main(String args[])
{
System.out.println("Enter the size: ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
double[][] input = new double[n][n];
double[][] real = new double[n][n];
double[][] img = new double[n][n];
double[][] amplitutude = new double[n][n];
System.out.println("Enter the 2D elements ");
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
input[i][j] = sc.nextDouble();
twoDfft(input, real, img, amplitutude);
sc.close();
}
}
Output:
$ javac TwoD_FFT.java $ java TwoD_FFT Enter the size: 2 Enter the 2D elements 2 3 4 2 2.5 + 0.0 i 5.5 + 0.0 i -0.5 + -1.8369701987210297E-16 i 0.5 + -3.0616169978683826E-16 i 2.5 + 0.0 i -0.5 + -3.6739403974420594E-16 i -0.5 + -1.8369701987210297E-16 i -1.5 + -1.8369701987210297E-16 i
Related posts:
Chuyển đổi từ HashMap sang ArrayList
Java Web Services – Jersey JAX-RS – REST và sử dụng REST API testing tools với Postman
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Guide to DelayQueue
Hướng dẫn sử dụng Java Generics
Java Program to Test Using DFS Whether a Directed Graph is Weakly Connected or Not
Java Program to Describe the Representation of Graph using Incidence List
Java – Combine Multiple Collections
Send email with JavaMail
Java Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence
Java Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree
Hướng dẫn Java Design Pattern – Proxy
Hướng dẫn sử dụng String Format trong Java
Java Program to Describe the Representation of Graph using Incidence Matrix
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
Java Switch Statement
Java Program to Implement Gauss Seidel Method
Spring REST API + OAuth2 + Angular (using the Spring Security OAuth legacy stack)
Java Program to Perform Searching in a 2-Dimension K-D Tree
Java Program to Implement Queue
Java Program to Check whether Graph is a Bipartite using 2 Color Algorithm
Guide to Java Instrumentation
Toán tử instanceof trong java
Hướng dẫn Java Design Pattern – Mediator
Java Program to Perform Left Rotation on a Binary Search Tree
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Receive email using POP3
Giới thiệu Java 8
Spring Security 5 for Reactive Applications
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
How to Manually Authenticate User with Spring Security
Java Program to Implement Warshall Algorithm