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:
How to Use if/else Logic in Java 8 Streams
Hướng dẫn Java Design Pattern – Memento
HashMap trong Java hoạt động như thế nào?
Hướng dẫn Java Design Pattern – MVC
New in Spring Security OAuth2 – Verify Claims
Java Program to Implement Binomial Tree
Java Program to Implement Fisher-Yates Algorithm for Array Shuffling
How to Count Duplicate Elements in Arraylist
LinkedHashSet trong Java hoạt động như thế nào?
A Guide to ConcurrentMap
JWT – Token-based Authentication trong Jersey 2.x
Java Program to Generate All Subsets of a Given Set in the Gray Code Order
Registration – Activate a New Account by Email
Java Program to Find a Good Feedback Edge Set in a Graph
New Features in Java 9
Spring Boot - Database Handling
Java Program to Optimize Wire Length in Electrical Circuit
Using Java Assertions
Java Program to Implement LinkedBlockingQueue API
Java Program to Implement ArrayDeque API
Converting between an Array and a List in Java
New Features in Java 13
Spring REST API + OAuth2 + Angular
Lớp Collectors trong Java 8
Batch Processing with Spring Cloud Data Flow
Shuffling Collections In Java
Java Program to Give an Implementation of the Traditional Chinese Postman Problem
Spring Boot - Quick Start
Hamcrest Collections Cookbook
Tạo ứng dụng Java RESTful Client với thư viện Retrofit
Converting String to Stream of chars
Java Program to Find the Nearest Neighbor Using K-D Tree Search