File: examples-hears_butterworth.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (62 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; Butterworth
   pair: example usage; figure
   pair: example usage; show
   pair: example usage; flipud
   pair: example usage; imshow
   pair: example usage; vstack
   pair: example usage; linspace
   pair: example usage; whitenoise

.. _example-hears_butterworth:

Example: butterworth (hears)
============================

Example of the use of the class :class:`~brian.hears.Butterworth` available in
the library. In this example, a white noise is filtered by a bank of butterworth
bandpass filters and lowpass filters which are different for every channels. The
centre or cutoff frequency of the filters are linearly taken between 100kHz and
1000kHz and its bandwidth frequency increases linearly with frequency.

::

    from brian import *
    from brian.hears import *
    
    level = 50*dB  # level of the input sound in rms dB SPL
    sound = whitenoise(100*ms).ramp()
    sound = sound.atlevel(level)
    order = 2 #order of the filters
    
    #### example of a bank of bandpass filter ################
    nchannels = 50
    center_frequencies = linspace(100*Hz, 1000*Hz, nchannels) 
    bw = linspace(50*Hz, 300*Hz, nchannels) # bandwidth of the filters
    #arrays of shape (2 x nchannels) defining the passband frequencies (Hz)
    fc = vstack((center_frequencies-bw/2, center_frequencies+bw/2))
    
    filterbank = Butterworth(sound, nchannels, order, fc, 'bandpass')
    
    filterbank_mon = filterbank.process()
    
    figure()
    subplot(211)
    imshow(flipud(filterbank_mon.T), aspect='auto')    
    
    ### example of a bank of lowpass filter ################
    nchannels = 50
    cutoff_frequencies = linspace(200*Hz, 1000*Hz, nchannels) 
    
    filterbank = Butterworth(sound, nchannels, order, cutoff_frequencies, 'low')
    
    filterbank_mon = filterbank.process()
    
    subplot(212)
    imshow(flipud(filterbank_mon.T), aspect='auto')    
    show()