This is the java implementation of calculating coefficients of the given function performing the Discrete-Fourier Transform. Formula for calculating the coefficient is X(k) = Sum(x(n)*cos(2*PI*k*n/N) – iSum(x(n)*sin(2*PI*k*n/N)) over 0 to N-1
Here is the source code of the Java Program to Compute DFT Coefficients Directly. 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 calculate a DFT Coefficients using the formula
import java.util.Scanner;
public class DFT_Coefficient
{
double real, img;
public DFT_Coefficient()
{
this.real = 0.0;
this.img = 0.0;
}
public static void main(String args[])
{
int N = 10;
Scanner sc = new Scanner(System.in);
System.out.println("Calculation DFT Coefficients");
System.out.println("Enter the coefficient of simple linear funtion:");
System.out.println("ax + by = c");
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
double []function = new double[N];
for(int i=0; i<N; i++)
{
function[i] = (((a*(double)i) + (b*(double)i)) - c);
//System.out.print( " "+function[i] + " ");
}
System.out.println("Enter the max K value: ");
int k = sc.nextInt();
double []cos = new double[N];
double []sin = new double[N];
for(int i=0; i<N; i++)
{
cos[i] = Math.cos((2 * i * k * Math.PI) / N);
sin[i] = Math.sin((2 * i * k * Math.PI) / N);
}
DFT_Coefficient dft_val = new DFT_Coefficient();
System.out.println("The coefficients are: ");
for(int i=0; i<N; i++)
{
dft_val.real += function[i] * cos[i];
dft_val.img += function[i] * sin[i];
}
System.out.println("("+dft_val.real + ") - " + "("+dft_val.img + " i)");
sc.close();
}
}
Output:
$ javac DFT_Coefficient.java $ java DFT_Coefficient Calculation DFT Coefficients Enter the coefficient of simple linear funtion: ax + by = c 1 2 3 Enter the max K value: 2 The coefficients are: (-15.00000000000001) - (-20.6457288070676 i)
Related posts:
Java Program to Implement Levenshtein Distance Computing Algorithm
Guide To CompletableFuture
Java Program to Perform the Sorting Using Counting Sort
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
A Guide to TreeSet in Java
Java Program to Implement Ford–Fulkerson Algorithm
REST Web service: Tạo ứng dụng Java RESTful Client với Jersey Client 2.x
Java Program to Implement Shell Sort
Hướng dẫn Java Design Pattern – Command
Introduction to Spring Cloud Stream
Java Program to Compute Discrete Fourier Transform Using Naive Approach
Guava – Join and Split Collections
Guide to the Java TransferQueue
Java Program to Perform String Matching Using String Library
Java Program to Print only Odd Numbered Levels of a Tree
Encode/Decode to/from Base64
Java Program to Perform Search in a BST
A Guide to Spring Boot Admin
ArrayList trong java
Java Program to Implement ArrayDeque API
The Registration API becomes RESTful
Java Program to Find Whether a Path Exists Between 2 Given Nodes
Java Program to Find MST (Minimum Spanning Tree) using Prim’s Algorithm
Entity To DTO Conversion for a Spring REST API
Configure a Spring Boot Web Application
Java Program to Find Inverse of a Matrix
Spring Boot - OAuth2 with JWT
A Guide to the finalize Method in Java
Collect a Java Stream to an Immutable Collection
Refactoring Design Pattern với tính năng mới trong Java 8
Java Program to Test Using DFS Whether a Directed Graph is Weakly Connected or Not
Spring Boot - Bootstrapping