2

I understand the complex output of a DFT contains both "amplitude" and "phase" information at discrete frequencies.

Amplitude[n] = sqrt((r[n]*r[n]) + (i[n]*i[n]))
Phase[n] = (atan2(i[n],r[n]))
Frequency[n] = n * (sample_rate / (fft_input_length / 2))

It seems that I should be able to use the frequency, amplitude, and phase information to calculate the amplitude of each output bin as if the input at the corresponding frequency had a zero-phase alignment in the FFT input. But I am drawing a blank.


Hmm, digging deeper into my problem I discovered that the imaginary potion of the FFT output is always 0.0 regardless of the input. So I am guessing my code is flawed or the algorithm is not what I need.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
  • 1
    Question doesn't make sense - you already have the expression for amplitude at a given bin above ? – Paul R Dec 08 '12 at 13:23
  • True, but it seems the amplitude value should be influenced by the phase. For example, if I generate a two sine wave signals of the same frequency and amplitude but shift the phase of the second signal, won't the amplitude calculated from the FFT output be different? That seems to be the case in my tests. Perhaps I have a flaw in my code somehwere. – Richard Buckmaster Dec 08 '12 at 15:55
  • If you combine two sine waves at the same frequency you get one sine wave at the same frequency with a new amplitude and phase - you can't separate these two sine waves since they are at the same frequency. – Paul R Dec 08 '12 at 18:15
  • Let me clarify. Consider a 2 Hz sine wave signal sampled 100 times per second. The first five samples passed to the FFT will be at T0, T0 + 1/100, T0 + 2/100, T0 + 3/100, and T0 + 4/100. Now consider the fft output if the samples are delayed by 1/200 of a second. The first five samples will be T0 + 1/200, T0 + 1/100 + 1/200, T0 + 2/100 + 1/200, T0 + 3/100 + 1/200, and T0 + 4/100 + 1/200. The 1/200 delay will appear as a phase shift and thus affect the amplitude calculated from the fft output. I just want to know how to remove the affect of that 1/200 second phase shift from the fft output. – Richard Buckmaster Dec 08 '12 at 18:27
  • No - the phase change doesn't affect the amplitude - you will just see a rotation in the complex output vector at the given bin, but the magnitude will be the same. – Paul R Dec 08 '12 at 18:36
  • Hmm, digging deeper into my problem I discovered that the imaginary potion of the FFT output is always 0.0 regardless of the input. So I am guessing my code is flawed or the algorithm is not what I need. – Richard Buckmaster Dec 09 '12 at 14:13

1 Answers1

2

If you want to rotate all DFT result bins to a phase of zero with reference to the start (sample 0): set r[n] = amplitude[n], i[n] = 0; make sure r[n] is symmetric over the full DFT length if you want strictly real data; and compute the IDFT if needed.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153