1

I have been attempting to implement a Inverse DFT (without using a FFT), but struggle a bit with the maths. From the implementations and pseudo codes I have read I cannot figure out the issue with my implementation.

'''

spectrum.clear();
spectrum.add(new ComplexNumber(36.0,0.0));
spectrum.add(new ComplexNumber(-4.000000000000002,9.65685424949238));
spectrum.add(new ComplexNumber(-4.000000000000002,3.9999999999999987));
spectrum.add(new ComplexNumber(-4.0,1.6568542494923788));
spectrum.add(new ComplexNumber(-4.0,0.0));
spectrum.add(new ComplexNumber(-3.999999999999999,-1.656854249492381));
spectrum.add(new ComplexNumber(-3.999999999999998,-4.000000000000001));
spectrum.add(new ComplexNumber(-3.999999999999995,-9.65685424949238));
        
int N = spectrum.size();
double twoPiOnN = 2 * Math.PI / N;

for(ComplexNumber c : spectrum) {
    waveform.add(0.0);
}
double twoPikOnN, twoPijkOnN;

for(int k=0; k<N; k++) {
    twoPikOnN = twoPiOnN *k;
    for(int j = 0; j < N; j++) {
        twoPijkOnN = twoPikOnN * j;
        double d = waveform.get(k);
        d += spectrum.get(j).getRe() * Math.cos(twoPijkOnN ) - spectrum.get(j).getIm() * Math.sin(twoPijkOnN );
        waveform.set(k,d);
        }
}
for(Double d : waveform) {
    System.out.println(d);
}

''' This case should result in a waveform arraylist of [1 ,2 ,3 ,4 ,5 ,6 ,7 ,8].

Any help is much appreciated.

luk2302
  • 55,258
  • 23
  • 97
  • 137

0 Answers0