Last active
June 7, 2022 21:38
-
-
Save BartMassey/77b90aaa9a42103aa450c007505bb4c6 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
import scipy.signal as ss | |
tau = 2 * np.pi | |
# Filter coefficients from | |
# | |
# cs = ss.iirfilter(1, (990, 1010), btype='bandpass', output='sos', fs=48000) | |
# | |
# Filter coefficient order is b0, b1, b2, a0, a1, a0. Filter | |
# sections must be normalized (a0 = 1). | |
cs = np.array( | |
[[ | |
1.30728645e-03, | |
0.00000000e+00, | |
-1.30728645e-03, | |
1.00000000e+00, | |
-1.98029921e+00, | |
9.97385427e-01, | |
]], | |
dtype = np.float64, | |
) | |
state = np.zeros((1, 2)) | |
nchunk = 100 | |
nsamples = 10_000 | |
for base in range(0, nsamples, chunk): | |
t0 = base / nsamples | |
t1 = (base + nchunk) / nsamples | |
t = np.linspace(t0, t1, endpoint=False, dtype=np.float64) | |
# https://en.wikipedia.org/wiki/Chirp#Linear | |
x = np.sin(0.5 * 0.5 * nsamples * tau * t * t) | |
y, state = ss.sosfilt(cs, x, zi=state) | |
# now do some processing on y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please ignore paper-bag bugs in previous revision.