4 Replies Latest reply on Jan 31, 2014 2:37 AM by 1004409

# Problem with code???

class Dft {

public static void computeDft(double[] inreal, double[] inimag, double[] outreal, double[] outimag) {

int n = inreal.length;

for (int k = 0; k < n; k++) {  // For each output element

double sum_real = 0;

double sum_imag = 0;

for (int t = 0; t < n; t++) {  // For each input element

double angle = 2 * Math.PI * t * k / n;       // Phase angle is given by this

sum_real +=  inreal[t] * Math.cos(angle) + inimag[t] * Math.sin(angle); // Here we get Summmation of periodic complex series

sum_imag += -inreal[t] * Math.sin(angle) + inimag[t] * Math.cos(angle);

}

outreal[k] = sum_real;

outimag[k] = sum_imag;

}

}

}

class DiscreteFourier

{

public static void main(String args[])

{

Dft a=new Dft();

}

}

sir i just want to method computeDft to be called in main class how can i do it

• ###### 1. Re: Problem with code???

... you don't know how to invoke static methods?

• ###### 2. Re: Problem with code???

sir i just have problem in understanding in what form we will give input to compute discrete fourier transform......................

• ###### 3. Re: Problem with code???
sir i just have problem in understanding in what form we will give input to compute discrete fourier transform......................

You provide it in the form specified by the signature of the method you are calling.

public static void computeDft(double[] inreal, double[] inimag, double[] outreal, double[] outimag) {

That signature specified 4 arrays of type 'double'. You create and populate the 'inreal' and 'inimag' arrays, and provide the two arrays to hold the result and the fuction will populate those two result arrays.

Dft a=new Dft();

You don't need to create an instance of that class to call the static method in it.

• ###### 4. Re: Problem with code???

import  java.io.*;

class Dft {

public static void computeDft(double[] inreal, double[] inimag, double[] outreal, double[] outimag) {

int n = inreal.length;

for (int k = 0; k < n; k++) {  // For each output element

double sum_real = 0;

double sum_imag = 0;

for (int t = 0; t < n; t++) {  // For each input element

double angle = 2 * Math.PI * t * k / n;       // Phase angle is given by this

//                               System.out.println("phase angle is="+angle);

sum_real +=  inreal[t] * Math.cos(angle) + inimag[t] * Math.sin(angle); // Here we get Summmation of periodic complex series

sum_imag += -inreal[t] * Math.sin(angle) + inimag[t] * Math.cos(angle);

}

outreal[k] = sum_real;

outimag[k] = sum_imag;

System.out.println("Sum of real terms is "+outreal[k]+"\n"+"sum of imaginary terms is"+outimag[k]);

}

}

}

class DiscreteFourier

{

public static void main(String args[]) throws Exception

{

Dft a=new Dft();

//    System.out.println("DFT computing........");

double[] inreal=new double[2];

double[] inimag=new double[2];

double[] outreal=new double[2];

double[] outimag=new double[2];

int n=inreal.length;

System.out.println("enter the  inreal array fields ");

for(int i=0;i<n;i++)

{

//inreal[i]=i;

}

System.out.println("Enter imaginary fields");

for(int j=0;j<n;j++)

{

inimag[j]=j;

}

a.computeDft(inreal, inimag, outreal, outimag);

}

}

Sir lastly i have done this is this write to implement discrete fourier transform