Skip to content

Instantly share code, notes, and snippets.

View masip85's full-sized avatar

Vicente Masip masip85

View GitHub Profile
@endolith
endolith / Perfect_FFT.py
Last active June 16, 2023 08:25
Perfect FFT
from numpy import linspace, cos, pi, absolute
from numpy.fft import fft, fftfreq, fftshift
import matplotlib.pyplot as plt
# Sampling rate
fs = 64 # Hz
# Time is from 0 to 1 seconds, but leave off the endpoint, so
# that 1.0 seconds is the first sample of the *next* chunk
length = 1 # second
@endolith
endolith / frequency_estimator.py
Last active October 30, 2023 18:08
Frequency estimation methods in Python
from __future__ import division
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
from scipy.signal import blackmanharris, correlate
from time import time
import sys
try:
import soundfile as sf
except ImportError:
from scikits.audiolab import flacread
@shawnchin
shawnchin / shmemctypes.py
Created September 16, 2011 15:09
shm_open() version of multiprocessing.sharedctypes.RawArray
#
# Based on multiprocessing.sharedctypes.RawArray
#
# Uses posix_ipc (http://semanchuk.com/philip/posix_ipc/) to allow shared ctypes arrays
# among unrelated processors
#
# Usage Notes:
# * The first two args (typecode_or_type and size_or_initializer) should work the same as with RawArray.
# * The shared array is accessible by any process, as long as tag matches.
# * The shared memory segment is unlinked when the origin array (that returned
@endolith
endolith / fft_vs_fwt.md
Created November 14, 2011 04:52
FFT vs FWT face-off

Empirically testing whether FWT or FFT is faster. Disclaimer: I don't understand wavelets.

Speed of FFT implementation doesn't care what the data is:

In [23]: a = rand(2**20)

In [24]: timeit fft(a)
10 loops, best of 3: 128 ms per loop

In [25]: a = rand(2**20)
@endolith
endolith / istft.m
Created May 24, 2012 20:31
STFT ISTFT Matlab Python
function x = istft(d, ftsize, w, h)
% X = istft(D, F, W, H) Inverse short-time Fourier transform.
% Performs overlap-add resynthesis from the short-time Fourier transform
% data in D. Each column of D is taken as the result of an F-point
% fft; each successive frame was offset by H points (default
% W/2, or F/2 if W==0). Data is hann-windowed at W pts, or
% W = 0 gives a rectangular window (default);
% W as a vector uses that as window.
% This version scales the output so the loop gain is 1.0 for
% either hann-win an-syn with 25% overlap, or hann-win on
@sebpiq
sebpiq / gist:4128537
Last active April 22, 2024 15:20
Python implementation of the Goertzel algorithm for calculating DFT terms
# Copyright © 2020 Sébastien Piquemal sebpiq@protonmail.com
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the license text below for more details.
#
# --------------------------------------------------------------------
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
@jiffyclub
jiffyclub / snakeviz_magic.py
Last active February 8, 2021 14:16
Magics for starting Snakeviz from IPython. Use %snakeviz and %%snakeviz in place of %prun and %%prun to profile a block of code and launch a Snakeviz view of the profile.
import subprocess
import tempfile
import time
from IPython.core.magic import register_line_cell_magic
def snakeviz(line, cell=None):
"""
Profile code and display the profile in Snakeviz.
import numpy as np
import fftw3
import pyfftw
import multiprocessing
import matplotlib
import matplotlib.pyplot as pl
import time
def fft_comparison_tests(size=2048, dtype=np.complex128, byte_align=False):
@grenade
grenade / 01-generate-ed25519-ssh-key.sh
Last active April 14, 2024 14:27
generate ed25519 ssh and gpg/pgp keys and set file permissions for ssh keys and config
#!/bin/bash
# generate new personal ed25519 ssh key
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "rob thijssen <rthijssen@gmail.com>"
# generate new host cert authority (host_ca) ed25519 ssh key
# used for signing host keys and creating host certs
ssh-keygen -t ed25519 -f manta_host_ca -C manta.network
eval "$(ssh-agent -s)"
@phillipuniverse
phillipuniverse / ntp.conf
Last active November 8, 2022 14:40
Set up NTP with Ansible, dedicating one as a timelord
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable