1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
.. currentmodule:: brian
.. index::
pair: example usage; erbspace
pair: example usage; tone
pair: example usage; Gammatone
pair: example usage; sqrt
pair: example usage; whitenoise
.. _example-hears_online_computation:
Example: online_computation (hears)
===================================
Example of online computation using :meth:`~brian.hears.Filterbank.process`.
Plots the RMS value of each channel output by a gammatone filterbank.
::
from brian import *
from brian.hears import *
sound1 = tone(1*kHz, .1*second)
sound2 = whitenoise(.1*second)
sound = sound1+sound2
sound = sound.ramp()
sound.level = 60*dB
cf = erbspace(20*Hz, 20*kHz, 3000)
fb = Gammatone(sound, cf)
def sum_of_squares(input, running):
return running+sum(input**2, axis=0)
rms = sqrt(fb.process(sum_of_squares)/sound.nsamples)
sound_rms = sqrt(mean(sound**2))
axhline(sound_rms, ls='--')
plot(cf, rms)
xlabel('Frequency (Hz)')
ylabel('RMS')
show()
|