Monday, January 13, 2020

dft - What's wrong with my Goertzel algorithm implementation?



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



Answer



Why do you think the two should be equal?



Check out the final line of equation (6) in the article you link to:


Wikipedia equation


I believe your misunderstanding is to not take account of the $e^{j\omega_0n}$ term.


No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...