Skip to content

Instantly share code, notes, and snippets.

View endolith's full-sized avatar
🤨

endolith

🤨
View GitHub Profile
def sosfiltfilt(sos, x, axis=-1, padtype='odd', padlen=None):
"""
A forward-backward filter.
This function applies a linear filter twice, once forward
and once backwards. The combined filter has linear phase.
Before applying the filter, the function can pad the data along the
given axis in one of three ways: odd, even or constant. The odd
and even extensions have the corresponding symmetry about the end point
@WarrenWeckesser
WarrenWeckesser / pz_match.py
Created November 21, 2014 05:05
Pole-zero matching scratch work
import numpy as np
from scipy.signal.filter_design import _cplxreal
def pop_real(p):
"""Pop the first real value in the list p."""
k = 0
while k < len(p) and p[k].imag != 0:
k += 1
if k == len(p):
# Python implementation of the Gibbons-Lester-Bird algorithm[1] for enumerating
# the positive rationals.
#
# James Tauber 2004-07-01
# http://jtauber.com/
#
# [1] http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/rationals.pdf
def rationals():
"""
import pyaudio
import wave
import numpy as np
from contextlib import contextmanager
import math
p = pyaudio.PyAudio()
chunk = 1024*4
FORMAT = pyaudio.paInt16

Remove me from this list and please don't contact me again by any means. That means don't e-mail me, don't call me, don't find me at conferences, don't send carrier pigeons to my house with small notes attached to their feet, don't even wave to me in the street if you see me. I'll snub you right there in public and that will be really awkward for you. I can't be held responsible if your friends don't talk to you anymore after that. And no, I don't care how great your position supposedly is, what technology it's using, where it's at, how many celebrities are invested, how close they are to closing funding, how much equity they're offering, how many times Paul Graham has high-fived the founders, how close they are to the Mission in San Francisco, how much the position is paying, how great the company is, who claims they know me that works there, how big their signing bonus is, or who I'll supposedly be working for/with. I'm not interested.

Just once more to be totally clear: don't contact me again. At al

@sblom
sblom / fracgen.m
Created April 12, 2012 17:47
Stern–Brocot generator: generate all positive rational numbers
frac[1] = {{0, 1}, {1, 1}, {1,0}}
frac[n_] := frac[n] = frac[n - 1] ~Riffle~ newFracs[n - 1]
newFracs[n_] := Apply[Plus, #] & /@ Partition[frac[n], 2, 1]
(* Example usage: *)
Map[Apply[Divide, #] &, frac[14]]
(*
A few very surprising things happen here:
@jul
jul / spect2.py
Created June 24, 2012 14:55
dumb spectogram
from scikits.audiolab import Sndfile
import numpy as np
import pylab as plt
import csv
import matplotlib.mlab as mlab
from math import floor, log
#NFFT windows make calculus faster if a power of 2
closest_2_power=lambda x : 1<<int(floor(log(x,2)))
def load_freq(fn="freq.csv"):
#/usr/bin/env python
# encoding: utf-8
import os
import sys
import atexit
import json
import time
import tempfile
import wave
@larsoner
larsoner / Output
Created January 3, 2014 15:03
SOS tests for scipy
========================== BESSELF =========================
z =
Empty matrix: 0-by-1
p =
-3.000000000000000e-01
k =
3.000000000000000e-01
z =
Empty matrix: 0-by-1
p =
@larsoner
larsoner / gist:8428867
Created January 15, 2014 00:48
Output2
clear all; close all; clc
format long e
format compact
[z, p, k] = ellip(5, 1, 40, [201 240], 'stop', 's')
[z, p, k] = cheby2(5, 20, [2010 2100], 'stop', 's')
[z, p, k] = cheby1(23, 0.8, 0.3, 'high') % high odd order
[z, p, k] = besself(1, 1)
[z, p, k] = besself(24, 100)
[z, p, k] = besself(23, 1000)