first commit
This commit is contained in:
commit
1aca907e74
14
LICENSE
Normal file
14
LICENSE
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||||
|
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Reverse Goertzel
|
||||||
|
|
||||||
|
Code using the Goertzel algorithm in reverse.
|
||||||
44
reverse_goertzel.py
Normal file
44
reverse_goertzel.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import math
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def goertzel_sinusoid(freq, duration, sample_rate, amplitude):
|
||||||
|
n = int(duration * sample_rate)
|
||||||
|
omega = (2.0 * math.pi * freq) / sample_rate
|
||||||
|
coeff = 2.0 * math.cos(omega)
|
||||||
|
|
||||||
|
# Initialize state variables
|
||||||
|
q1 = 1.0
|
||||||
|
q2 = 1.0
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for i in range(n):
|
||||||
|
sample = coeff * q1 - q2
|
||||||
|
q2 = q1
|
||||||
|
q1 = sample
|
||||||
|
result.append(sample * amplitude)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def sinusoid(n, cycles=1):
|
||||||
|
result = []
|
||||||
|
for i in range(1, n+1):
|
||||||
|
sample = math.cos(2.0 * cycles * math.pi * (i/n))
|
||||||
|
result.append(sample)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cycles = 2
|
||||||
|
signal = goertzel_sinusoid(cycles, 1, 1024, 1)
|
||||||
|
reference = np.array(sinusoid(1024, cycles))
|
||||||
|
error = reference - signal
|
||||||
|
print("max error:", error.max())
|
||||||
|
x = np.array(range(0, 1024))
|
||||||
|
plt.plot(x, signal)
|
||||||
|
plt.plot(x, reference)
|
||||||
|
plt.plot(x, error)
|
||||||
|
#plt.plot(x, error*1000/3)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user