File: examples-hears_ircam_hrtf.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 (52 lines) | stat: -rw-r--r-- 1,429 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
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; title
   pair: example usage; imshow
   pair: example usage; shape
   pair: example usage; xlabel
   pair: example usage; ylabel
   pair: example usage; show
   pair: example usage; whitenoise
   pair: example usage; IRCAM_LISTEN

.. _example-hears_ircam_hrtf:

Example: ircam_hrtf (hears)
===========================

Example showing the use of HRTFs in Brian hears. Note that you will need to
download the :class:`IRCAM_LISTEN` database.

::

    from brian import *
    from brian.hears import *
    # Load database
    hrtfdb = IRCAM_LISTEN(r'F:\HRTF\IRCAM')
    hrtfset = hrtfdb.load_subject(1002)
    # Select only the horizontal plane
    hrtfset = hrtfset.subset(lambda elev: elev==0)
    # Set up a filterbank
    sound = whitenoise(10*ms)
    fb = hrtfset.filterbank(sound)
    # Extract the filtered response and plot
    img = fb.process().T
    img_left = img[:img.shape[0]/2, :]
    img_right = img[img.shape[0]/2:, :]
    subplot(121)
    imshow(img_left, origin='lower left', aspect='auto',
           extent=(0, sound.duration/ms, 0, 360))
    xlabel('Time (ms)')
    ylabel('Azimuth')
    title('Left ear')
    subplot(122)
    imshow(img_right, origin='lower left', aspect='auto',
           extent=(0, sound.duration/ms, 0, 360))
    xlabel('Time (ms)')
    ylabel('Azimuth')
    title('Right ear')
    show()