示例#1
0
文件: devices.py 项目: wind666/axopy
def emgsim():
    # sampling rate of the simulated EMG data
    fs = 2000
    # update rate of the generated data
    update_rate = 20
    # gain to use in noise generation
    gain = 0.25
    # number of seconds of data the oscilloscope shows
    osc_view_time = 5

    samp_per_input = int(fs / update_rate)

    pipeline = Pipeline([
        # get keyboard inputs of past second
        Windower(update_rate),
        # take mean over last second and apply a gain
        Callable(lambda x: np.mean(x, axis=1, keepdims=True)),
        # generate noise with amplitude of previous output
        Callable(lambda x, k: gain * x * np.random.randn(x.shape[0], k),
                 func_args=(samp_per_input, )),
        # window for pretty display in oscilloscope
        Windower(osc_view_time * update_rate * samp_per_input),
    ])

    dev = Keyboard(rate=update_rate, keys=list('wasd'))
    run(dev, pipeline)
示例#2
0
    def make_pipeline(self, gain):
        b, a = butter(4, (10 / 2000. / 2., 900 / 2000. / 2.), 'bandpass')
        pipeline = Pipeline([
            Windower(250),
            Filter(b, a=a, overlap=150),  # overlap = winsize - read_rate
            Callable(lambda x: x[:, 0].reshape(-1, 1)),  # Downsampling
            Callable(lambda x: gain * x)
        ])

        return pipeline
示例#3
0
文件: devices.py 项目: wind666/axopy
def mouse():
    dev = Mouse(rate=20)
    pipeline = Pipeline([
        # just for scaling the input since it's in pixels
        Callable(lambda x: x / 100),
        # window to show in the oscilloscope
        Windower(40)
    ])
    run(dev, pipeline)
示例#4
0
文件: devices.py 项目: wind666/axopy
def keystick():
    dev = Keyboard(rate=20, keys=list('wasd'))
    pipeline = Pipeline([
        # window to average over
        Windower(10),
        # mean along rows
        Callable(lambda x: np.mean(x, axis=1, keepdims=True)),
        # window to show in the oscilloscope
        Windower(60)
    ])
    run(dev, pipeline)
示例#5
0
文件: emg.py 项目: krmdmn/axopy
    def make_mav_norm_pipeline(self):
        windower = Windower(int(self.rate * self.win_size_mav))
        if self.filter:
            filter = self.make_filter(win_size=self.win_size_mav)

        fe = FeatureExtractor([('MAV', MeanAbsoluteValue())])
        mmsc = MinMaxScaler(min_=self.c_min, max_=self.c_max)
        # Calibrated MAV is non-negative, but we allow values larger than 1
        nonneg = Callable(lambda x: np.clip(x, 0.0, None))
        if self.filter:
            self.pipeline['mav_norm'] = Pipeline(
                [windower, filter, fe, mmsc, nonneg])
        else:
            self.pipeline['mav_norm'] = Pipeline([windower, fe, mmsc, nonneg])
示例#6
0
def polar():
    num_channels = 5
    dev = RandomWalkGenerator(rate=60,
                              num_channels=num_channels,
                              amplitude=0.03,
                              read_size=1)
    # Polar plot can only show non-negative values
    pipeline = Pipeline([Callable(lambda x: np.abs(x))])
    Experiment(daq=dev, subject='test').run(
        PolarPlotter(pipeline,
                     color=[0, 128, 255],
                     fill=True,
                     n_circles=10,
                     max_value=5.))
示例#7
0
def bar():
    num_channels = 10
    channel_names = ['Ch ' + str(i) for i in range(1, num_channels + 1)]
    dev = NoiseGenerator(rate=100,
                         num_channels=num_channels,
                         amplitude=5.0,
                         read_size=10)
    pipeline = Pipeline(
        [Windower(100),
         Callable(lambda x: np.mean(x, axis=1, keepdims=True))])
    Experiment(daq=dev, subject='test').run(
        BarPlotter(pipeline=pipeline,
                   channel_names=channel_names,
                   group_colors=[[255, 204, 204]],
                   yrange=(-0.5, 0.5)))
示例#8
0
    def make_pipeline(self, rate, readsize, winsize, lowpass, highpass):
        b, a = butter(4, (lowpass / rate / 2., highpass / rate / 2.),
                      'bandpass')
        pipeline = Pipeline([
            Windower(winsize),
            # overlap = winsize - read_rate
            Filter(b, a=a, overlap=winsize - readsize),
            Callable(mean_absolute_value,
                     func_kwargs={
                         'axis': 1,
                         'keepdims': True
                     })
        ])

        return pipeline