For a few weeks now, I have been trying to implement a DFT that takes an arbitrary set of bytes and treats them as a signal. It then transforms them to the frequency domain. Following that it transforms them back. It originally only attempted to use some of the components to reconstruct the original signal. When this failed, I tried using all of the components and it still failed.
I have been following Wikipedia's Equations as a guide for how to do this and my code seems to match the equations given (in my mind) given this code:
DFT:
for (int k = 0; k < frequency_domain_magnitude.length; k++) {
for (int n = 0; n < data.length; n++) {
double val = (-2.0 * Math.PI * n * k / data.length);
freq_imag[k] += data[n] * -Math.sin(val);
freq_real[k] += data[n] * Math.cos(val);
}
frequency_domain_magnitude[k] = Math.sqrt(freq_imag[k] * freq_imag[k] + freq_real[k] * freq_real[k]);
}
IDFT:
for (int n = 0; n < data.length; n++) {
doubleValue[n] = 0;
for (int k = 0; k < freqUsed.length; k++) {
double val = (2.0 * Math.PI * n * k / data.length);
doubleValue[n] = freq_real[k] * Math.cos(val) - freq_imag[k] * Math.sin(val);
}
time_real[n] = (byte) (Math.floor(doubleValue[n]));
}
Can anybody help me identify what the problem is?
I asked a previous question that is about the same project, but it was worded terribly and editing may have caused more confusion, not less. Also, although that question may have been answered, I still have more to figure out. That can be found here