Created
March 26, 2013 09:55
-
-
Save blubberdiblub/5244254 to your computer and use it in GitHub Desktop.
filter diagram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import division | |
import sys | |
import math | |
OVERSAMPLING_FACTOR = 1 | |
SAMPLING_FREQUENCY = 48000 * OVERSAMPLING_FACTOR | |
PASSES = 100000 | |
F = 1000.0 | |
MINF = F / 1.1 | |
MAXF = F * 1.1 | |
Q = 1.0 / (1.0 + F / SAMPLING_FREQUENCY * (math.pi * 2.0)) | |
P = 1.0 - Q | |
R = 0.25 | |
MINR = R - 0.03 | |
MAXR = R + 0.03 | |
NUMX = 80 | |
NUMY = 23 | |
MAXX = NUMX - 1 | |
MAXY = NUMY - 1 | |
MINL = math.log(MINF) | |
MAXL = math.log(MAXF) | |
grid = [] | |
for i in range(NUMY): | |
grid.append([' '] * NUMX) | |
def dump(): | |
sys.stdout.write("\x1B[H") | |
for row in grid: | |
for char in row: | |
sys.stdout.write(char) | |
sys.stdout.write("\x1B[H\x1B[J") | |
for x in range(NUMX): | |
f = math.exp((x / MAXX) * (MAXL - MINL) + MINL) | |
ratio = f / SAMPLING_FREQUENCY * (math.pi * 2.0) | |
squaresum = 0.0 | |
squaresum2 = 0.0 | |
filtered = 0.0 | |
complementary = 0.0 | |
for i in range(PASSES): | |
v = (math.cos((i - 0.5) * ratio) - math.cos((i + 0.5) * ratio)) / ratio | |
filtered = v * P + filtered * Q | |
complementary = v - filtered | |
squaresum += filtered * filtered | |
squaresum2 += complementary * complementary | |
r = squaresum / PASSES | |
y = int(round((r - MAXR) / (MINR - MAXR) * MAXY)) | |
if 0 <= y < NUMY: | |
grid[y][x] = '+' | |
r = squaresum2 / PASSES | |
y = int(round((r - MAXR) / (MINR - MAXR) * MAXY)) | |
if 0 <= y < NUMY: | |
grid[y][x] = '*' | |
dump() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment