I've implemented Goertzel algorithm, now very simply in Python. But I cannot obtain the correct answer it's supposed to produce for a single DTF frequency. here is my code in Python:
import numpy as np
# omega frequency: radians/sample
omega = 0.23
# length of the data to generate
length = 200
# updated parameters
dft = 0.0
s1 = 0.0
s2 = 0.0
# initial phase
radians = 0.0
for i in range(length):
# generate signal value
value = np.cos(radians)
# goertzel algorithm update
s0 = value + 2.0 * np.cos(omega) * s1 - s2
s2 = s1
s1 = s0
# dft sum update
dft += value * np.exp(-1j * omega * i)
# next value
radians += omega
# final goertzel algorithm update
s0 = 2.0 * s1 * np.cos(omega) - s2
goe = s0 - np.exp(-1j * omega) * s1
# print results
print "DFT: {:.4f}".format(dft / length)
print "GOE: {:.4f}".format(goe / length)
Output:
DFT: 0.4979-0.0097j
GOE: -0.2065+0.4531j
The correct answer (with infinite data) is 0.5 + 0.0j.
DFT is therefore providing the correct result.
What's wrong with my Goertzel algorithm implementation?
https://en.wikipedia.org/wiki/Goertzel_algorithm
No comments:
Post a Comment