Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from HEnquist/numpyless
Numpyless
- Loading branch information
Showing
10 changed files
with
320 additions
and
182 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from camilladsp_plot.plot_filters import plot_filters, plot_filter, plot_filterstep, plot_all_filtersteps | ||
from camilladsp_plot.plot_pipeline import plot_pipeline | ||
from camilladsp_plot.eval_filterconfig import eval_filter, eval_filterstep |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Adapted from https://jeremykun.com/2012/07/18/the-fast-fourier-transform/ | ||
import cmath | ||
import math | ||
|
||
def omega(p, q): | ||
return cmath.exp((2.0 * cmath.pi * 1j * q) / p) | ||
|
||
def _fft(signal): | ||
n = len(signal) | ||
if n == 1: | ||
return signal | ||
else: | ||
Feven = _fft([signal[i] for i in range(0, n, 2)]) | ||
Fodd = _fft([signal[i] for i in range(1, n, 2)]) | ||
|
||
combined = [0] * n | ||
for m in range(int(n/2)): | ||
combined[m] = Feven[m] + omega(n, -m) * Fodd[m] | ||
combined[m + int(n/2)] = Feven[m] - omega(n, -m) * Fodd[m] | ||
|
||
return combined | ||
|
||
def fft(signal): | ||
orig_len = len(signal) | ||
fft_len = 2**(math.ceil(math.log2(orig_len))) | ||
for _n in range(fft_len-orig_len): | ||
signal.append(0.0) | ||
fftsig = _fft(signal) | ||
return fftsig |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import math | ||
import cmath | ||
from camilladsp_plot.filters import Biquad, BiquadCombo, Conv, DiffEq, Gain | ||
|
||
|
||
def logspace(minval, maxval, npoints): | ||
logmin = math.log10(minval) | ||
logmax = math.log10(maxval) | ||
perstep = (logmax-logmin)/npoints | ||
values = [10.0**(logmin+n*perstep) for n in range(npoints)] | ||
return values | ||
|
||
def eval_filter(filterconf, name=None, samplerate=44100, npoints=1000): | ||
fvect = logspace(1.0, samplerate*0.95/2.0, npoints) | ||
if name is None: | ||
name = "unnamed {}".format(filterconf['type']) | ||
result = {"name": name, "samplerate": samplerate, "f": fvect } | ||
if filterconf['type'] in ('Biquad', 'DiffEq', 'BiquadCombo'): | ||
if filterconf['type'] == 'DiffEq': | ||
currfilt = DiffEq(filterconf['parameters'], samplerate) | ||
elif filterconf['type'] == 'BiquadCombo': | ||
currfilt = BiquadCombo(filterconf['parameters'], samplerate) | ||
else: | ||
currfilt = Biquad(filterconf['parameters'], samplerate) | ||
|
||
_fplot, magn, phase = currfilt.gain_and_phase(fvect) | ||
result["magnitude"] = magn | ||
result["phase"] = phase | ||
elif filterconf['type'] == 'Conv': | ||
if 'parameters' in filterconf: | ||
currfilt = Conv(filterconf['parameters'], samplerate) | ||
else: | ||
currfilt = Conv(None, samplerate) | ||
_ftemp, magn, phase = currfilt.gain_and_phase(fvect) | ||
t, impulse = currfilt.get_impulse() | ||
result["magnitude"] = magn | ||
result["phase"] = phase | ||
result["time"] = t | ||
result["impulse"] = impulse | ||
return result | ||
|
||
def eval_filterstep(conf, pipelineindex, name="filterstep", npoints=1000, toimage=False): | ||
|
||
samplerate = conf['devices']['samplerate'] | ||
fvect = logspace(1.0, samplerate*0.95/2.0, npoints) | ||
pipelinestep = conf['pipeline'][pipelineindex] | ||
totcgain=[1.0 for n in range(npoints)] | ||
for filt in pipelinestep['names']: | ||
filterconf = conf['filters'][filt] | ||
if filterconf['type'] == 'DiffEq': | ||
currfilt = DiffEq(filterconf['parameters'], samplerate) | ||
elif filterconf['type'] == 'BiquadCombo': | ||
currfilt = BiquadCombo(filterconf['parameters'], samplerate) | ||
elif filterconf['type'] == "Biquad": | ||
currfilt = Biquad(filterconf['parameters'], samplerate) | ||
elif filterconf['type'] == "Conv": | ||
currfilt = Conv(filterconf['parameters'], samplerate) | ||
elif filterconf['type'] == "Gain": | ||
currfilt = Gain(filterconf['parameters']) | ||
else: | ||
continue | ||
_, cgainstep = currfilt.complex_gain(fvect) | ||
totcgain = [cg * cgstep for (cg, cgstep) in zip(totcgain, cgainstep)] | ||
gain = [20.0 * math.log10(abs(cg) + 1e-15) for cg in totcgain] | ||
phase = [180 / math.pi * cmath.phase(cg) for cg in totcgain] | ||
result = {"name": name, "samplerate": samplerate, "f": fvect, "magnitude": gain, "phase": phase} | ||
return result | ||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.