コード例 #1
0
ファイル: RZ6.py プロジェクト: buranconsult/tdtpy
 def setUp(self):
     from tdt import DSPCircuit
     from os.path import dirname, join
     circuit = join(dirname(__file__), self.CIRCUIT)
     self.circuit = DSPCircuit(circuit, 'RZ6')
     self.buffer_in = self.circuit.get_buffer('in', 'w')
     self.buffer_out = self.circuit.get_buffer('out',
                                               'r',
                                               src_type='int32',
                                               dest_type='int32',
                                               block_size=1)
     self.circuit.start()
コード例 #2
0
ファイル: RZ6.py プロジェクト: Eric89GXL/tdtpy
 def setUp(self):
     from tdt import DSPCircuit
     from os.path import dirname, join
     circuit = join(dirname(__file__), self.CIRCUIT)
     self.circuit = DSPCircuit(circuit, 'RZ6')
     self.buffer_in = self.circuit.get_buffer('in', 'w')
     self.buffer_out = self.circuit.get_buffer('out', 'r', src_type='int32',
                                               dest_type='int32',
                                               block_size=1)
     self.circuit.start()
コード例 #3
0
ファイル: window_tool.py プロジェクト: bburan/NeuroBehavior
 def init(self, info):
     filename = join(RCX_ROOT, 'physiology')
     self.iface = DSPCircuit(filename, 'RZ5')
     self.iface.set_tag('a_spike1', 1e-4)
     self.snippet_source = self.iface.get_buffer('spike1', 'r',
             block_size=32)
     self.snippet_store.fs = self.snippet_source.fs
     self.iface.start()
     self.iface.trigger('A', 'high')
     self.timer = Timer(100, self.monitor)
コード例 #4
0
ファイル: RZ6.py プロジェクト: buranconsult/tdtpy
class TestWithHardware(unittest.TestCase):

    CIRCUIT = '../components/test_RZ6_audio_out'

    def setUp(self):
        from tdt import DSPCircuit
        from os.path import dirname, join
        circuit = join(dirname(__file__), self.CIRCUIT)
        self.circuit = DSPCircuit(circuit, 'RZ6')
        self.buffer_in = self.circuit.get_buffer('in', 'w')
        self.buffer_out = self.circuit.get_buffer('out',
                                                  'r',
                                                  src_type='int32',
                                                  dest_type='int32',
                                                  block_size=1)
        self.circuit.start()

    def test_waveform_to_bits(self):
        from numpy.random import random
        from numpy.testing import assert_array_equal  # noqa
        waveform = random(100e3).astype('float32')
        self.circuit.set_tag('nHi', 100e3)
        self.buffer_in.set(waveform)
        actual = self.buffer_out.acquire(1, 'running', False).ravel()
        expected = waveform_to_bits(waveform, 1)

        # Due to various vagaries of shuffling bits around, I believe the least
        # significant bit is sometimes lost when uploading to the RZ6.  This
        # results in a maximum difference between the actual and expected
        # values of 256.  It's not clear exactly what the significance of this
        # number actually is to me.
        difference = actual - expected
        self.assertTrue(difference.max() <= 256)
コード例 #5
0
ファイル: RZ6.py プロジェクト: Eric89GXL/tdtpy
class TestWithHardware(unittest.TestCase):

    CIRCUIT = '../components/test_RZ6_audio_out'

    def setUp(self):
        from tdt import DSPCircuit
        from os.path import dirname, join
        circuit = join(dirname(__file__), self.CIRCUIT)
        self.circuit = DSPCircuit(circuit, 'RZ6')
        self.buffer_in = self.circuit.get_buffer('in', 'w')
        self.buffer_out = self.circuit.get_buffer('out', 'r', src_type='int32',
                                                  dest_type='int32',
                                                  block_size=1)
        self.circuit.start()

    def test_waveform_to_bits(self):
        from numpy.random import random
        from numpy.testing import assert_array_equal  # noqa
        waveform = random(100e3).astype('float32')
        self.circuit.set_tag('nHi', 100e3)
        self.buffer_in.set(waveform)
        actual = self.buffer_out.acquire(1, 'running', False).ravel()
        expected = waveform_to_bits(waveform, 1)

        # Due to various vagaries of shuffling bits around, I believe the least
        # significant bit is sometimes lost when uploading to the RZ6.  This
        # results in a maximum difference between the actual and expected
        # values of 256.  It's not clear exactly what the significance of this
        # number actually is to me.
        difference = actual-expected
        self.assertTrue(difference.max() <= 256)
コード例 #6
0
ファイル: calibrate_new.py プロジェクト: bburan/NeuroBehavior
def ref_cal(duration=1, averages=2, ref_freq=1e3, ref_level=93.8, gain=20,
        fft=False, mode='conv'):
    '''
    Calibrates measuring microphone against a known reference (e.g. a
    pistonphone).  Typically this is the B&K microphone, but certainly could be
    any microphone that is felt to produce a flat frequency response across the
    range of frequencies of interest.

    TODO: Update this so it incorporates the actual B&K calibration file
    (where do we get this?).

    level           Output of reference in dB SPL
    frequency       Frequency of reference in Hz

    verbose         Returns signal and FFT so it can be plotted
    '''

    circuit_path = join(get_config('RCX_ROOT'), 'play_record.rcx')
    circuit = DSPCircuit(circuit_path, 'RZ6')
    circuit.start(1)
    samples = circuit.convert(duration, 's', 'nPow2')

    # Important, rec_delay must be at least 1 or the circuit will not work
    circuit.set_tags(play_duration=0, rec_duration=samples, rec_delay=1)
    mic_buffer = circuit.get_buffer('mic', 'r')
    mic_data = mic_buffer.acquire_samples(1, samples, 1)
    print rms(mic_data)
    print tone_frequency(circuit.fs, mic_data[0].ravel(), 1e3)
    from pylab import plot, show
    plot(mic_data[0].ravel()[:5e3])
    show()
    return
    print mic_data.shape
    if circuit.get_tag('clipped'):
        print 'Clipping occured'
    for m in mic_data:
        #rms = np.mean(m.ravel()**2)**0.5
        magnitude, phase = tone_frequency(circuit.fs, m, 1e3)
        print magnitude/dbspltopa(ref_level+gain)
    #plot(mic_data[0].ravel())
    #show()
    return mic_data

    #print mic_data.shape
    return

    # Do the calibration!
    #result = tone_power(device, samples, averages=averages, freq=ref_freq,
    #                    fft=fft, mode=mode)

    log.debug('Measured %.2f Vrms at %.2f Hz from the pistonphone' % \
            (result[0], ref_freq))

    sens = result[0] / dbtopa(ref_level)

    debug_mesg = 'Using the pistonphone reference of %.2f dB SPL, ' + \
            'microphone sensitivity is %.4f Vrms/Pa'
    log.debug(debug_mesg % (ref_level, sens))

    # Phase is meaningless since we have little control over the pistonphone, so
    # we do not return this, just microphone sensitivity.
    if fft: return sens, result[-1]
    else: return sens
コード例 #7
0
ファイル: window_tool.py プロジェクト: bburan/NeuroBehavior
class DemoController(Controller):

    iface = Any
    timer = Any
    snippet_source = Any
    snippet_store = Any
    plot = Any
    container = Any
    button = Button
    tool = Any

    def _button_fired(self):
        hoops = self.tool.windows
        coeffs = np.zeros((30, 3))
        for i, hoop in enumerate(hoops):
            x = round(hoop[0]*self.snippet_source.fs)
            coeffs[x] = hoop[1], hoop[2], i+1
            print x, hoop[1], hoop[2], i+1
        #self.iface.set_coefficients('c_spike1', coeffs.ravel())
        #self.plot.last_reset = len(self.snippet_store.buffer)

    def _container_default(self):
        container = OverlayPlotContainer(padding=[50, 50, 50, 50])
        index_range = DataRange1D(low=0, high=0.0012)
        value_range = DataRange1D(low=-0.00025, high=0.0005)
        index_mapper = LinearMapper(range=index_range)
        value_mapper = LinearMapper(range=value_range)
        plot = SnippetChannelPlot(history=100, channel=self.snippet_store,
                value_mapper=value_mapper, index_mapper=index_mapper)
        self.plot = plot

        # Add the axes
        axis = PlotAxis(orientation='left', component=plot)
        plot.overlays.append(axis)
        axis = PlotAxis(orientation='bottom', component=plot)
        plot.overlays.append(axis)

        plot.overlays.append(ZoomTool(plot, axis='value'))

        self.tool = WindowTool(component=plot)
        plot.overlays.append(self.tool)
        container.add(plot)

#        plot = SnippetChannelPlot(history=100, channel=self.snippet_store,
#                value_mapper=value_mapper, index_mapper=index_mapper,
#                classifier=1, line_color='red')
#        container.add(plot)
#
        #plot = SnippetChannelPlot(history=100, channel=self.snippet_store,
        #        value_mapper=value_mapper, index_mapper=index_mapper,
        #        classifier=2, line_color='green')
        #container.add(plot)

        #plot = SnippetChannelPlot(history=5, channel=self.snippet_store,
        #        value_mapper=value_mapper, index_mapper=index_mapper,
        #        classifier=2, line_color='blue')
        #container.add(plot)

	print 'adding container'
        return container

    def _snippet_store_default(self):
        datafile = get_temp_file()
        return FileSnippetChannel(node=datafile.root, name='snippet',
                snippet_size=30)

    def init(self, info):
        filename = join(RCX_ROOT, 'physiology')
        self.iface = DSPCircuit(filename, 'RZ5')
        self.iface.set_tag('a_spike1', 1e-4)
        self.snippet_source = self.iface.get_buffer('spike1', 'r',
                block_size=32)
        self.snippet_store.fs = self.snippet_source.fs
        self.iface.start()
        self.iface.trigger('A', 'high')
        self.timer = Timer(100, self.monitor)

    def monitor(self):
        data = self.snippet_source.read().reshape((-1, 32))
        self.snippet_store.send(data[:,1:-1], data[:,0].view('int32'),
                data[:,-1].view('int32'))