goertzel_freq
Builtin index · Signal processing
result = goertzel_freq(x, fs, freq)
Input: x, fs, freq · Output: result
What it is
x is a length-N real vector; fs (number, Hz) is the sample rate; freq is the frequency to evaluate (a number, Hz) or a length-K vector of frequencies.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = goertzel_freq(x, fs, freq) | x vectorx is a length-N real vector.fs numberfs (number, Hz) is the sample rate.freq number or vectorfreq is the frequency to evaluate (a number, Hz) or a length-K vector of frequencies. | result scalar or CVec | Returns a single complex scalar or a length-K CVec, same batching as goertzel above. goertzel parameterized by real frequencies rather than raw bin indices — the common case of checking one or several known tone frequencies at a fixed sample rate. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 8000
tone_hz = 941 # one DTMF tone
strength = abs(goertzel_freq(samples, fs, tone_hz))
from numerics-dsp
fs = 1000
n = 0:1:63
t = n / fs
x = sin(2*pi*100*t)
X = fft(x)
xr = idft(X)
print("idft roundtrip max err: {max(abs(xr - x))}")
k100 = 100 * length(x) / fs # bin index equivalent to 100 Hz
bin100 = goertzel(x, k100)
print("goertzel magnitude at bin {k100}: {abs(bin100)}")
same = goertzel_freq(x, fs, 100) # the Hz-parameterized convenience form
print("goertzel_freq agrees: {abs(same - bin100) < 1e-9}")
half = rfft(x)
back = irfft(half, 64)
print("rfft/irfft roundtrip max err: {max(abs(back - x))}")
idft roundtrip max err: 1.604386e-14 goertzel magnitude at bin 6.4: 32.158025 goertzel_freq agrees: true rfft/irfft roundtrip max err: 3.330669e-16
from signal-processing
How it works
goertzel_freq(x, fs, freq) -- goertzel parameterized by a real frequency in Hz rather than a raw bin index, the common case (a known tone frequency at a fixed sample rate). freq may also be a vector of frequencies, same K-point-DFT batching as goertzel above, returning a CVec.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.