Skip to content

Instantly share code, notes, and snippets.

@Orpheon
Created October 11, 2013 10:07
Show Gist options
  • Select an option

  • Save Orpheon/6932423 to your computer and use it in GitHub Desktop.

Select an option

Save Orpheon/6932423 to your computer and use it in GitHub Desktop.
from __future__ import division, print_function
import struct, math
data = ""
for i in range(1, 2):
text = open("output1", "r")
data += text.read()
text.close()
cutoff = 2
Q = 1
w0 = 2*math.pi * cutoff/128
cos_w0 = math.cos(w0)
sin_w0 = math.sin(w0)
alpha = sin_w0/(2*Q)
# Highpass
a0 = 1 + alpha
a1 = -2*cos_w0
a2 = 1 - alpha
b0 = (1 + cos_w0)/2
b1 = -(1 + cos_w0)
b2 = (1 + cos_w0)/2
x = [0, 0]
y = [0, 0]
while len(data) > 0:
x.append(struct.unpack_from("<f", data)[0])
data = data[struct.calcsize("<f"):]
y.append(max(-1, min(1, (b0/a0)*x[-1] + (b1/a0)*x[-2] + (b2/a0)*x[-3] - (a1/a0)*y[-1] - (a2/a0)*y[-2])))
data = ""
for num in y:
data += struct.pack("<f", num)
text = open("output3", "w")
text.write(data)
text.close()
from __future__ import division, print_function
import struct, math
data = ""
for i in range(1, 2):
text = open("output1", "r")
data += text.read()
text.close()
cutoff = 2
Q = 1
w0 = 2*math.pi * cutoff/128
cos_w0 = math.cos(w0)
sin_w0 = math.sin(w0)
alpha = sin_w0/(2*Q)
# Lowpass
a0 = 1 + alpha
a1 = -2*cos_w0
a2 = 1 - alpha
b0 = (1 - cos_w0)/2
b1 = 1 - cos_w0
b2 = (1 - cos_w0)/2
x = [0, 0]
y = [0, 0]
while len(data) > 0:
x.append(struct.unpack_from("<f", data)[0])
data = data[struct.calcsize("<f"):]
y.append((b0/a0)*x[-1] + (b1/a0)*x[-2] + (b2/a0)*x[-3] - (a1/a0)*y[-1] - (a2/a0)*y[-2])
data = ""
for num in y:
data += struct.pack("<f", num)
text = open("output2", "w")
text.write(data)
text.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment