brain_pipe.preprocessing.stimulus.audio.envelope.EnvelopeFromGammatone¶
- class EnvelopeFromGammatone(source, power_factor)¶
Bases:
Filterbank
Converts the output of a GammatoneFilterbank to an envelope.
Attributes
The duration of the filterbank.
nchannels
samplerate
The source of the filterbank, a
Bufferable
object, e.g. anotherFilterbank
or aSound
.- __init__(source, power_factor)¶
Initialize the envelope transformation.
- Parameters:
source (Gammatone) – Gammatone filterbank output to convert to envelope
power_factor (float) – The power factor for each sample.
Methods
__init__
(source, power_factor)Initialize the envelope transformation.
buffer_apply
(input_)buffer_fetch
(start, end)buffer_fetch_next
(samples)buffer_init
()change_source
(source)get_duration
()process
([func, duration, buffersize])Returns the output of the filterbank for the given duration.
set_duration
(duration)- property duration¶
The duration of the filterbank. If it is not specified by the user, it is computed by finding the maximum of its source durations. If these are not specified a
KeyError
will be raised.
- process(func=None, duration=None, buffersize=32)¶
Returns the output of the filterbank for the given duration.
func
If a function is specified, it should be a function of one or two arguments that will be called on each filtered buffered segment (of shape
(buffersize, nchannels)
in order. If the function has one argument, the argument should be buffered segment. If it has two arguments, the second argument is the value returned by the previous application of the function (or 0 for the first application). In this case, the method will return the final value returned by the function. See example below.duration=None
The length of time (in seconds) or number of samples to process. If no
func
is specified, the method will return an array of shape(duration, nchannels)
with the filtered outputs. Note that in many cases, this will be too large to fit in memory, in which you will want to process the filtered outputs online, by providing a functionfunc
(see example below). If no duration is specified, the maximum duration of the inputs to the filterbank will be used, or an error raised if they do not have durations.buffersize=32
The size of the buffered segments to fetch, as a length of time or number of samples. 32 samples typically gives reasonably good performance.
For example, to compute the RMS of each channel in a filterbank, you would do:
def sum_of_squares(input, running_sum_of_squares): return running_sum_of_squares+sum(input**2, axis=0) rms = sqrt(fb.process(sum_of_squares)/nsamples)
- property source¶
The source of the filterbank, a
Bufferable
object, e.g. anotherFilterbank
or aSound
. It can also be a tuple of sources. Can be changed after the object is created, although note that for some filterbanks this may cause problems if they do make assumptions about the input based on the first source object they were passed. If this is causing problems, you can insert a dummy filterbank (DoNothingFilterbank
) which is guaranteed to work if you change the source.