# Phase and Amplitude Calculation for a Pure Complex Tone in a DFT using Multiple Bins

__Introduction__

This is an article to hopefully give a better understanding of the Discrete Fourier Transform (DFT) by deriving exact formulas to calculate the phase and amplitude of a pure complex tone from several DFT bin values and knowing the frequency. This article is functionally an extension of my prior article "Phase and Amplitude Calculation for a Pure Complex Tone in a DFT"[1] which used only one bin for a complex tone, but it is actually much more similar to my approach for real valued tones in my article "Phase and Amplitude Calculation for a Pure Real Tone in a DFT: Method 1"[2].

__The Base Definitions__

The same variables and equation for describing the tone from my previous articles will be used. The variables are amplitude ($ M $), frequency ($ f $), phase ($ \phi $), and the sample count in the frame ($ N $). The signal definition is: $$ S_n = M \cdot { e^{ i(\alpha n + \phi) } } \tag {1} $$ Where: $$ \alpha = f \cdot \frac{ 2\pi }{ N } \tag {2} $$ The same $1/N$ normalized DFT definition is also used. $N$ is also the number of bins in the DFT so $k$ ranges from $0$ to $N-1$. $$ Z_k = \frac{ 1 }{ N } \sum_{n=0}^{N-1} { S_n e^{ -i\beta_k n } } \tag {3} $$ Where: $$ \beta_k = k \cdot \frac{ 2\pi }{ N } \tag {4} $$

__Finding the Frequency__

If the frequency of the tone is not known, the two or three DFT bin values nearest the peak magnitude bin can be used to find it. If the magnitude of a bin adjacent to the peak is fairly large, the two bin frequency calculation formula should be used[3]. If the bins adjacent to the peak are small in comparison, the three bin formula [4] centered at the peak should be used. In either case, the frequency can be calculated. In the noiseless single tone case, the calculation will be exact. There are other estimation methods as well.

__Integer Frequency Case__

If the frequency is an integer value in terms of cycles per frame, the next few sections do not apply. Simply set $q$ to the bin value of the frequency bin and skip ahead to the "Final Results" section.

__Bin Value Formula for a Pure Complex Tone__

The alternative bin value formula found in my previous blog article titled "DFT Bin Value Formulas for Pure Complex Tones" [5] will be used instead of the main one. The reason is that it replaces a complex valued divide with a real valued one. This saves a lot of calculations.

First a change of variable is needed: $$ \delta_k = \alpha - \beta_k \tag {5} $$ The formula is then: $$ Z_k = \frac{ M }{ N } e^{ i \left[ -\delta_k (N-1) / 2 + \phi \right] } \cdot \frac{ sin( \delta_k N / 2 ) }{ sin( \delta_k / 2 ) } \tag {6} $$

__Vector Formulation__

The formula (6) can be rearranged slightly to make it more stackable. $$ Z_k = q \cdot e^{ i \left[ -\delta_k \frac{(N-1)}{2} \right] } \cdot \frac{ sin( N \delta_k / 2 ) }{ N sin( \delta_k / 2 ) } \tag {7} $$ Where: $$ q = M e^{ i \phi } \tag {8} $$ The complex value $q$ contains the amplitude and phase being sought. Therefore this is the value to be solved for. This can be done by stacking the bin value equations around the peak bin $p$ into a vector equation. The size of the vectors is flexible. $$ \begin{bmatrix} . \\ . \\ Z_{p-1}\\ Z_{p}\\ Z_{p+1}\\ . \\ . \\ \end{bmatrix} = q \cdot \begin{bmatrix} . \\ . \\ e^{ i \left[ -\delta_{p-1} \frac{(N-1)}{2} \right] } \cdot \frac{ sin( N \delta_{p-1} / 2 ) }{ N sin( \delta_{p-1} / 2 ) } \\ e^{ i \left[ -\delta_{p} \frac{(N-1)}{2} \right] } \cdot \frac{ sin( N \delta_{p} / 2 ) }{ N sin( \delta_{p} / 2 ) } \\ e^{ i \left[ -\delta_{p+1} \frac{(N-1)}{2} \right] } \cdot \frac{ sin( N \delta_{p+1} / 2 ) }{ N sin( \delta_{p+1} / 2 ) } \\ . \\ . \\ \end{bmatrix} \tag {9} $$ This equation is much simpler in vector notation. $$ \vec Z = q \vec Y \tag {10} $$ $\vec Z$ has the selected bin values from the DFT and $\vec Y$ is the calculated basis vector.

__Solving for q__

Finding $q$ is a standard Linear Algebra best fit with a single basis vector. Dotting both sides of (10) with the complex conjugate of $\vec Y$ turns the vector equation into a simple scalar one. $$ \vec Z \cdot \vec Y^* = q \vec Y \cdot \vec Y^* \tag {11} $$ The value of $q$ can now be calculated. $$ q = \frac{ \vec Z \cdot \vec Y^* }{ \vec Y \cdot \vec Y^* } \tag {12} $$

__The Final Results__

Thanks to the polar form of complex numbers, once the value of q is known finding the values of $\phi$ and $M$ is very straightforward. $$ \phi = \arg( q ) = \operatorname{atan2}( Im[q], Re[q] ) \tag {13} $$ $$ M = \| q \| = \sqrt{ (Im[q])^2 + (Re[q])^2 } \tag {14} $$ That's all there is to it.

__Numerical Results__

Here are some numeric results for using different length vectors. A length one vector is identical to the one bin solution provided in my previous blog article[1]. The result values are the RMS values for the errors multiplied by 100. The magnitude of the signal is one.

*********************************************************** The sample count is 32 and the run size is 10000 The phase value is 0.123400 Errors are shown as RMS at 100x actual value Target Noise Level = 0.100 Freq One Vec Two Vec Three Vec Four Vec Five Vec Phase Mag Phase Mag Phase Mag Phase Mag Phase Mag ---- ------------ ----------- ----------- ----------- ----------- 3.1 1.30 1.27 1.28 1.27 1.28 1.26 1.28 1.26 1.28 1.26 3.2 1.35 1.36 1.31 1.33 1.29 1.31 1.29 1.30 1.28 1.30 3.3 1.49 1.49 1.36 1.37 1.33 1.34 1.31 1.33 1.30 1.32 3.4 1.68 1.68 1.39 1.41 1.35 1.37 1.32 1.34 1.31 1.33 3.5 1.96 1.98 1.40 1.41 1.36 1.37 1.33 1.33 1.31 1.32 3.6 1.69 1.68 1.40 1.40 1.37 1.37 1.34 1.33 1.33 1.32 3.7 1.48 1.47 1.36 1.35 1.33 1.32 1.31 1.31 1.30 1.30 3.8 1.38 1.36 1.33 1.32 1.32 1.30 1.31 1.29 1.31 1.29 3.9 1.30 1.30 1.30 1.29 1.29 1.29 1.29 1.28 1.29 1.28 ***********************************************************

The results clearly show that when a frequency is near an integer bin, increasing the number of bins in the vector does not significantly improve the results. However, when the frequency is closer to being between two bins, having more leakage, using the extra bin values reduces the errors. The values in the last two columns indicates diminishing returns on extra bins.

__Conclusion__

The phase and amplitude calculations of a pure complex tone from DFT bin values are significantly simpler than for a real valued tone. The derivation presented in this article is not very complicated and the results are easy to verify. It is important to keep in mind that these equations are exact as no approximation were used in their derivation.

__References__

[1] Dawg, Cedron, Phase and Amplitude Calculation for a Pure Complex Tone in a DFT

[2] Dawg, Cedron, Phase and Amplitude Calculation for a Pure Real Tone in a DFT: Method 1

[3] Dawg, Cedron, A Two Bin Exact Frequency Formula for a Pure Complex Tone in a DFT

[4] Dawg, Cedron, Three Bin Exact Frequency Formulas for a Pure Complex Tone in a DFT

[5] Dawg, Cedron, DFT Bin Value Formulas for Pure Complex Tones

- Comments
- Write a Comment Select to add a comment

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Registering will allow you to participate to the forums on ALL the related sites and give you access to all pdf downloads.