Skip to content

Instantly share code, notes, and snippets.

View multivac61's full-sized avatar
🎯
Focusing

multivac61 multivac61

🎯
Focusing
View GitHub Profile
class KnightsTour():
'''Knights Tour using Warnsdorf's rule as heuristics'''
def __init__(self, N, start_point=(0,0)):
self.N = N
self.initial_state = (start_point, )
# all relative moves expressed as displacement in 2D
self._actions = [(1,2), (1,-2), (2,1), (2,-1),\
(-1,2), (-1,-2), (-2,1), (-2,-1)]
# A script to remind me how to check if an
# array contains a zero. If it does
# we should mask it with some tiny number
from sys import float_info
epsilon = float_info.epsilon
# X is input variable, f.x. FFT
X[X == 0] = epsilon
def freq_from_ZCR(sig, fs):
# Find all indices right before a rising-edge zero crossing
indices = find((sig[1:] >= 0) & (sig[:-1] < 0))
crossings = interpolate(indices, sig)
return fs / np.mean(np.diff(crossings))
def freq_from_AC(sig, fs):
corr = np.correlate(sig, sig, mode='full')
corr = corr[corr.size/2:]
# Find the first low point
d = diff(corr)
# first point with pos.
start = find(d > 0)
def freq_from_FFT(sig, fs):
# Compute Fourier transform of windowed signal
N = len(sig)
windowed = sig * blackmanharris(N)
X = np.abs(np.fft.rfft(windowed))
# Find the peak and interpolate
i = np.argmax(abs(X)) # Just use this for less-accurate, naive version
X[X == 0] = epsilon # Circumvent division by 0
def freq_from_HPS(sig, fs):
N = len(sig)
windowed = sig * blackmanharris(N)
X = np.abs(rfft(windowed))
hps = X
n_harmonic_partials = 6
for h in range(2, n_harmonic_partials):
# downsample the spectra
dec = scipy.signal.decimate(X, h)
def freq_from_CEPS(sig, fs):
N = len(sig)
windowed = sig * blackmanharris(N)
spectrum = np.fft.rfft(windowed, fs)
spectrum[spectrum == 0] = EPSILON
log_spectrum = np.log(np.abs(spectrum))
ceps = np.fft.irfft(log_spectrum)
start = int(fs / HIGH_FREQ)
# swampme.sh
# Create a 16GB swap space in current file system
dd if=/dev/zero of=/var/myswap bs=1M count=16384
mkswap /var/myswap
swapon /var/myswap
echo "/var/myswap swap swap defaults 0 0" >> /etc/fstab
# Supercollider and jack2 install script
# made for Raspberry Pi 3
# run script as root?
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get update && apt-get upgrade
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install -y mendeleydesktop htop
# Install f.lux
# Install dependencies
sudo apt-get install -y git python-appindicator python-xdg python-pexpect python-gconf python-gtk2 python-glade2 libxxf86vm1 -y
# Download and install xflux-gui
cd /tmp
git clone "https://github.com/xflux-gui/xflux-gui.git"