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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | //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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $ 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:
Java Program to Implement Warshall Algorithm
Marker Interface trong Java
Spring Boot - Tomcat Deployment
Mix plain text and HTML content in a mail
Spring 5 Testing with @EnabledIf Annotation
Guide to Escaping Characters in Java RegExps
Hướng dẫn sử dụng Java Annotation
Hướng dẫn Java Design Pattern – Chain of Responsibility
A Guide to the ViewResolver in Spring MVC
Java Program to Implement Knight’s Tour Problem
Check if there is mail waiting
Map Serialization and Deserialization with Jackson
Java Program to Implement PriorityBlockingQueue API
Java Program to Implement Sorted Array
Java Program to Implement Stack using Linked List
Intro to Spring Boot Starters
Java Program to Perform Insertion in a BST
Java Program to Implement Gabow Algorithm
A Guide to JUnit 5 Extensions
Java Program to Implement PrinterStateReasons API
Hướng dẫn Java Design Pattern – Flyweight
The DAO with Spring and Hibernate
Hướng dẫn Java Design Pattern – Transfer Object
Guide to java.util.concurrent.BlockingQueue
String Joiner trong Java 8
Introduction to Using Thymeleaf in Spring
Java Program to Implement Hash Tree
Sort a HashMap in Java
How to Change the Default Port in Spring Boot
Java Program to Implement Selection Sort
An Intro to Spring Cloud Contract
Java Program to Implement LinkedHashSet API