diff --git a/examples/dsp.py b/examples/dsp.py index 0f22121..e620798 100644 --- a/examples/dsp.py +++ b/examples/dsp.py @@ -16,7 +16,7 @@ # this folder will contain a Kerkythea model named `model.xml` # and the `material_a.dat`, `material_b.dat` files pertaining # to the materials referenced in it. -anc = AncField('gpu', 'models/dsp') +anc = AncField('cpu', 'models/dsp') # Place a microphone at position x=3, y=1, z=1 in meters. # The acoustic pressure at this point will be recorder, and diff --git a/examples/ie224.py b/examples/ie224.py index 0f18984..38f830b 100644 --- a/examples/ie224.py +++ b/examples/ie224.py @@ -36,15 +36,14 @@ def add_microphones(ancObject): return ancObject # We create a simulation and immeatealy add microphones to it -anc = add_microphones(AncField('cpu', 'models/ie224')) - +# +# Trying to run this simulation on CPU failed on an i7-3770, compiling the +# lrs_1.cl file fails. It maybe because the scene's size is too large for +# the CPU. Compiling it for the built in integrated GPU worked though. +anc = add_microphones(AncField('gpu', 'models/ie224')) + # noise_source anc.AddSource([4,1.6,1.0], bandnoise([100,2000], 11*32000, 32000)) anc.Visualize(1.6) (x,y) = anc.Run(10) - -#h = EstimateIr(x[0,:], y, anc.fs) -#np.savetxt('h_'+sim+'.dat', h) -#h = EstimateIr(x[0::4], y[6,0::4], 3*8e3, 1e-4) -#savetxt('noise_to_reference_bottom.dat', h) \ No newline at end of file diff --git a/examples/room_modes.py b/examples/room_modes.py index c0480ce..4d861d5 100644 --- a/examples/room_modes.py +++ b/examples/room_modes.py @@ -11,7 +11,7 @@ from anc_field_py.ancfield import * from anc_field_py.ancutil import * -anc = AncField('cpu', 'models/room_modes') +anc = AncField('gpu', 'models/room_modes') anc.AddSource([0.48,0.48,0.48], 10*impulse(2000, 6*32000, 32000)) anc.AddMic([0.5,0.2,0.3]) diff --git a/impulse-anc-py/ancutil.py b/impulse-anc-py/ancutil.py deleted file mode 100644 index d1da801..0000000 --- a/impulse-anc-py/ancutil.py +++ /dev/null @@ -1,64 +0,0 @@ -from __future__ import division - -import numpy as np -from scipy import signal - -def EstimateIr(input, output, N, mu): - W = np.zeros(N) - - for m in range(0,16): - steps = min(np.size(input, 0), np.size(output, 0)) - # mu = 1e-4 - - x_buf = np.zeros(N) - - for k in range(0, steps): - x_buf = np.concatenate( (np.array([input[k]]), x_buf[0:-1]) ) - y_est = np.dot(W, x_buf) - e = output[k] - y_est - W = W + 2*mu*e*x_buf - - return W - -def bandnoise(bands, length, fs): - z = 2*np.random.rand(length)-1; - if len(bands) > 1 and bands[0] != 0: - b = signal.firwin(10000, [c/(fs/2) for c in bands], pass_zero=False) - elif len(bands) > 1: - b = GetLpFir(bands[1], 100, fs) - x = signal.lfilter(b, 1, z); - - return x - -def impulse(bw, length, fs): - x = np.zeros(length) - x[1] = 1 - b = GetLpFir(bw, 100, fs) - x = signal.lfilter(b, 1, x) - - return x - -def GetLpFir(cutoff, transition, fs): - #------------------------------------------------ - # Create a FIR filter and apply it to x. - #------------------------------------------------ - - # The Nyquist rate of the signal. - nyq_rate = fs / 2.0 - - # The desired width of the transition from pass to stop, - # relative to the Nyquist rate. We'll design the filter - # with a 5 Hz transition width. - width = transition/nyq_rate - - # The desired attenuation in the stop band, in dB. - ripple_db = 80.0 - - # Compute the order and Kaiser parameter for the FIR filter. - N, beta = signal.kaiserord(ripple_db, width) - - # Use firwin with a Kaiser window to create a lowpass FIR filter. - taps = signal.firwin(N, cutoff/nyq_rate, window=('kaiser', beta)) - - return taps - \ No newline at end of file