Created
November 16, 2015 16:48
-
-
Save jokamjohn/ab5d51baa9f29b64dd2c to your computer and use it in GitHub Desktop.
Method one. Try following up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Created by jokamjohn on 11/16/2015. | |
| */ | |
| //This is a sample program to calculate a DFT Coefficients using the formula | |
| import java.util.Scanner; | |
| public class DFT | |
| { | |
| double real, img; | |
| public DFT() | |
| { | |
| 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 dft_val = new DFT(); | |
| 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(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment