Power-spectrum terms Examining equation (6), a final IIR filter pass to calculate term y[N] using a supplemental input value x[N]=0 applies a complex multiplier of magnitude 1 to the previous term y[N-1]. Consequently, y[N] and y[N-1] represent equivalent signal power. It is equally valid to apply equation (11) and calculate the signal power from term y[N] or to apply equation (2) and calculate the signal power from term y[N-1]. Both cases lead to the following expression for the signal power represented by DFT term X[k]: {{NumBlk|:|\begin{align} X[k] \, X'[k] & = y[N] \, y'[N] = y[N-1] \, y'[N-1] \\ & = s^2[N-1] + s^2[N-2] - 2 \cos \left(2 \pi \frac{k}{N} \right) \, s[N-1] \, s[N-2]. \end{align} |12}} In the
pseudocode below, the complex-valued input data is stored in the
array x and the variables sprev and sprev2 temporarily store output history from the IIR filter. Nterms is the number of samples in the array, and Kterm corresponds to the frequency of interest, multiplied by the sampling period. Nterms defined here Kterm selected here ω = 2 × π × Kterm / Nterms; coeff := 2 × cos(ω) sprev := 0 sprev2 := 0
for each index
n in range 0 to Nterms-1
do s := x[n] + coeff × sprev - sprev2 sprev2 := sprev sprev := s
end power := sprev
2 + sprev2
2 - (coeff × sprev × sprev2) It is possible to organise the computations so that incoming samples are delivered singly to a
software object that maintains the filter state between updates, with the final power result accessed after the other processing is done.
Single DFT term with real-valued arithmetic The case of real-valued input data arises frequently, especially in embedded systems where the input streams result from direct measurements of physical processes. When the input data are real-valued, the filter internal state variables sprev and sprev2 can be observed also to be real-valued, consequently, no complex arithmetic is required in the first IIR stage. Optimizing for real-valued arithmetic typically is as simple as applying appropriate real-valued data types for the variables. After the calculations using input term x[N-1], and filter iterations are terminated, equation (11) must be applied to evaluate the DFT term. The final calculation uses complex-valued arithmetic, but this can be converted into real-valued arithmetic by separating real and imaginary terms: {{NumBlk|:|\begin{align} c_r &= \cos(2 \pi \tfrac{k}{N}), \\ c_i &= \sin(2 \pi \tfrac{k}{N}), \\ y[N] &= c_r s[N-1] - s[N-2] + j c_i s[N-1]. \end{align} |13}} Comparing to the power-spectrum application, the only difference are the calculation used to finish: (Same IIR filter calculations as in the signal power implementation) XKreal = sprev * cr - sprev2; XKimag = sprev * ci;
Phase detection This application requires the same evaluation of DFT term X[k], as discussed in the previous section, using a real-valued or complex-valued input stream. Then the signal phase can be evaluated as {{NumBlk|:| \phi = \tan^{-1}\frac{\Im(X[k])}{ \Re(X[k])}, |14}} taking appropriate precautions for singularities, quadrant, and so forth when computing the inverse tangent function.
Complex signals in real arithmetic Since complex signals decompose linearly into real and imaginary parts, the Goertzel algorithm can be computed in real arithmetic separately over the sequence of real parts, yielding y_\text{r}[n], and over the sequence of imaginary parts, yielding y_\text{i}[n]. After that, the two complex-valued partial results can be recombined: {{NumBlk|:|y[n] = y_\text{r}[n] + j y_\text{i}[n].|15}} == Computational complexity ==