Download Example - Read the Docs
Transcript
Brian Documentation, Release 1.4.1 class brian.hears.DoNothingFilterbank(source) Filterbank that does nothing to its input. Useful for removing a set of filters without having to rewrite your code. Can also be used for simply writing compound derived classes. For example, if you want a compound Filterbank that does AFilterbank and then BFilterbank, but you want to encapsulate that into a single class, you could do: class ABFilterbank(DoNothingFilterbank): def __init__(self, source): a = AFilterbank(source) b = BFilterbank(a) DoNothingFilterbank.__init__(self, b) However, a more general way of writing compound filterbanks is to use CombinedFilterbank. class brian.hears.ControlFilterbank(source, inputs, targets, updater, max_interval=None) Filterbank that can be used for controlling behaviour at runtime Typically, this class is used to implement a control path in an auditory model, modifying some filterbank parameters based on the output of other filterbanks (or the same ones). The controller has a set of input filterbanks whose output values are used to modify a set of output filterbanks. The update is done by a user specified function or class which is passed these output values. The controller should be inserted as the last bank in a chain. Initialisation arguments: source The source filterbank, the values from this are used unmodified as the output of this filterbank. inputs Either a single filterbank, or sequence of filterbanks which are used as inputs to the updater. targets The filterbank or sequence of filterbanks that are modified by the updater. updater The function or class which does the updating, see below. max_interval If specified, ensures that the updater is called at least as often as this interval (but it may be called more often). Can be specified as a time or a number of samples. The updater The updater argument can be either a function or class instance. If it is a function, it should have a form like: # A single input def updater(input): ... # Two inputs def updater(input1, input2): ... # Arbitrary number of inputs def updater(*inputs): ... Each argument input to the function is a numpy array of shape (numsamples, numchannels) where numsamples is the number of samples just computed, and numchannels is the number of channels in the corresponding filterbank. The function is not restricted in what it can do with these inputs. Functions can be used to implement relatively simple controllers, but for more complicated situations you may want to maintain some state variables for example, and in this case you can use a class. The object updater should be an instance of a class that defines the __call__ method (with the same syntax as above for functions). In addition, you can define a reinitialisation method reinit() which will be called when the buffer_init() method is called on the filterbank, although this is entirely optional. 320 Chapter 8. Reference