Skip to content

Commit

Permalink
New time driving function handling (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
fs446 authored and mgeier committed Mar 13, 2019
1 parent 966e43c commit a30f08f
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 345 deletions.
12 changes: 6 additions & 6 deletions doc/examples/time_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
t = 0.008
# compute driving signals
d_delay, d_weight, selection, secondary_source = \
sfs.time.drivingfunction.wfs_25d_point(array.x, array.n, xs)
d = sfs.time.drivingfunction.driving_signals(d_delay, d_weight, signal)
sfs.time.wfs.point_25d(array.x, array.n, xs)
d = sfs.time.wfs.driving_signals(d_delay, d_weight, signal)

# test soundfield
twin = sfs.tapering.tukey(selection, .3)
Expand All @@ -50,8 +50,8 @@

# compute driving signals
d_delay, d_weight, selection, secondary_source = \
sfs.time.drivingfunction.wfs_25d_plane(array.x, array.n, npw)
d = sfs.time.drivingfunction.driving_signals(d_delay, d_weight, signal)
sfs.time.wfs.plane_25d(array.x, array.n, npw)
d = sfs.time.wfs.driving_signals(d_delay, d_weight, signal)

# test soundfield
twin = sfs.tapering.tukey(selection, .3)
Expand All @@ -72,8 +72,8 @@
nfs = sfs.util.normalize_vector(xref - xs) # main n of fsource
t = 0.003 # compute driving signals
d_delay, d_weight, selection, secondary_source = \
sfs.time.drivingfunction.wfs_25d_focused(array.x, array.n, xs, nfs)
d = sfs.time.drivingfunction.driving_signals(d_delay, d_weight, signal)
sfs.time.wfs.focused_25d(array.x, array.n, xs, nfs)
d = sfs.time.wfs.driving_signals(d_delay, d_weight, signal)

# test soundfield
twin = sfs.tapering.tukey(selection, .3)
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/time_domain_nfchoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
npw = [0, -1, 0] # propagating direction
t = 0 # observation time
delay, weight, sos, phaseshift, selection, secondary_source = \
sfs.time.drivingfunction.nfchoa_25d_plane(array.x, R, npw, fs, max_order)
d = sfs.time.drivingfunction.nfchoa_25d_driving_signals(
sfs.time.nfchoa.plane_25d(array.x, R, npw, fs, max_order)
d = sfs.time.nfchoa.driving_signals_25d(
delay, weight, sos, phaseshift, signal)
p = sfs.time.synthesize(d, selection, array, secondary_source,
observation_time=t, grid=grid)
Expand All @@ -37,8 +37,8 @@
xs = [1.5, 1.5, 0] # position
t = np.linalg.norm(xs) / sfs.default.c # observation time
delay, weight, sos, phaseshift, selection, secondary_source = \
sfs.time.drivingfunction.nfchoa_25d_point(array.x, R, xs, fs, max_order)
d = sfs.time.drivingfunction.nfchoa_25d_driving_signals(
sfs.time.nfchoa.point_25d(array.x, R, xs, fs, max_order)
d = sfs.time.nfchoa.driving_signals_25d(
delay, weight, sos, phaseshift, signal)
p = sfs.time.synthesize(d, selection, array, secondary_source,
observation_time=t, grid=grid)
Expand Down
55 changes: 51 additions & 4 deletions sfs/time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
.. autosummary::
:toctree:
drivingfunction
source
wfs
nfchoa
"""
from . import drivingfunction
from .. import array as _array
import numpy as np
from . import source

from .. import util as _util
from .. import array as _array


def synthesize(signals, weights, ssd, secondary_source_function, **kwargs):
Expand Down Expand Up @@ -63,3 +64,49 @@ def synthesize(signals, weights, ssd, secondary_source_function, **kwargs):
signal = channel, samplerate, signal_offset
p += a * weight * secondary_source_function(x, n, signal, **kwargs)
return p


def apply_delays(signal, delays):
"""Apply delays for every channel.
Parameters
----------
signal : (N,) array_like + float
Excitation signal consisting of (mono) audio data and a sampling
rate (in Hertz). A `DelayedSignal` object can also be used.
delays : (C,) array_like
Delay in seconds for each channel (C), negative values allowed.
Returns
-------
`DelayedSignal`
A tuple containing the delayed signals (in a `numpy.ndarray`
with shape ``(N, C)``), followed by the sampling rate (in Hertz)
and a (possibly negative) time offset (in seconds).
"""
data, samplerate, initial_offset = _util.as_delayed_signal(signal)
data = _util.asarray_1d(data)
delays = _util.asarray_1d(delays)
delays += initial_offset

delays_samples = np.rint(samplerate * delays).astype(int)
offset_samples = delays_samples.min()
delays_samples -= offset_samples
out = np.zeros((delays_samples.max() + len(data), len(delays_samples)))
for column, row in enumerate(delays_samples):
out[row:row + len(data), column] = data
return _util.DelayedSignal(out, samplerate, offset_samples / samplerate)


def secondary_source_point(c):
"""Create a point source for use in `sfs.time.synthesize()`."""

def secondary_source(position, _, signal, observation_time, grid):
return source.point(position, signal, observation_time, grid, c=c)

return secondary_source


from . import nfchoa
from . import wfs

0 comments on commit a30f08f

Please sign in to comment.