2
votes

Im reconstructing signal from amplitude, frequency and phase obtained fft. After I do fft, I picked some of its frequencies and reconstructed time line signal from those fft data. I know IFFT is for this but, I dont want to use IFFT. Reconstruction seems fine but theres some time lag between two signals. This image shows this problem. Black one is the original signal and red one is that reconstructed. enter image description here

If I know correctly, amplitude of frequency bin t is sqrt(real[t]*real[t] + imag[t]*imag[t] and phase is atan2(imag[t], real[t]). So, I used formula amplitude * cos(2*π*x / frequency + phase) for a frequency bin. And I summed those regenerated waves. As far as I know, this should generate intact signal fits to original signal. But it ends up always with some time lag from original signal.

Yeah, I think its about phase but thats so simple to calculate and its working correctly. If it has error, reconstructed signal would not fit to its original signal in shape.

This is the code to generate cosine wave. I generated cosine wave from sin(x + π/2).

std::vector<short> encodeSineWavePCM(
    const double frequency,
    const double amplitude,
    const double offSetPhase)
{
    const double pi = 3.1415926535897932384626;
    const int N = 44100; // 1 sec length wave
    std::vector<short> s(N);
    const double wavelength = 1.0 * N / frequency;
    const double unitlength = 2 * pi / wavelength;
    for (int i = 0; i<N; i ++) {
        double val = sin(offSetPhase + i * unitlength);
        val *= amplitude;
        s[i] = (short)val;
    }

    return s;
}

What am I missing?

1
There's no need to re-post your question, you should edit your original question to preserve the discussion. - alter igel
"I know IFFT is for this" - and it's the only transform that gives you back the original. But why the irrational dislike for the IFFT? - MSalters
for test purpose. This is sound signal and I'm trying to make a original sound back from major frequencies of the original signal. Does it must make the same sound if I play each frequency at the same time? - Jay Kim
Sorry, I don't understand that last sentence. "Frequency" is associated with a sine wave, which is not localized in time, so you can't really talk about "the same time". - MSalters
yea, u r right. I was just trying to simulate "simultaneous" sound play back environment. make each frequency into sound signal and play them at once. thats what i meant. - Jay Kim

1 Answers

1
votes

Quite normal. You're doing a frame-by-frame transform. That means the FFT frame is produced after one time frame. When transforming back, you have the inverse effect: your time frame starts after the FFT frame has been decoded.