def detect(self, x_in):
        # Compute the instantaneous power for the current buffer
        x_envelope = cp.abs(x_in)
        # Filter and decimate the envelope to a lower data rate
        self._envelope[:] = cusignal.upfirdn(self._win,
                                             x_envelope)[self._filter_roi]
        # Update threshold
        # Add summation of current envelope to the threshold fifo array
        self._bkg_sum_arr[self._fifo_index] = cp.sum(self._envelope)
        # Update fifo index for next detection window
        self._fifo_index = (self._fifo_index + 1) % self._fifo_len
        # Calculate avg background power level for the previous buffers in fifo
        bkg_avg = np.sum(self._bkg_sum_arr) / (self._fifo_len * self._buff_len)
        # Calculate new threshold value
        self._thresh = bkg_avg * self._thresh_offset

        # Calc index vector where power is above the threshold
        envelope_det_idx = self._envelope > self._thresh
        n_detections = cp.sum(envelope_det_idx)
        # Make sure at least samp_above_thresh are higher than the threshold
        if n_detections > self._samp_above_thresh:
            # Copy to cupy array as workaround to issue cuSignal #178
            x_out = cp.array(x_in)
            x_out[~envelope_det_idx] = 0  # Zero out samples below threshold
        else:
            x_out = None
        return x_out
Exemple #2
0
    def test_upfirdn2d(self, rand_2d_data_gen, num_samps, up, down, use_numba):
        cpu_sig, gpu_sig = rand_2d_data_gen(num_samps)

        h = [1, 1, 1]

        cpu_resample = signal.upfirdn(h, cpu_sig, up, down)
        gpu_resample = cp.asnumpy(
            cusignal.upfirdn(h, gpu_sig, up, down, use_numba=use_numba))

        assert array_equal(cpu_resample, gpu_resample)
Exemple #3
0
 def gpu_version(self, sig, up, down, axis):
     with cp.cuda.Stream.null:
         out = cusignal.upfirdn([1, 1, 1], sig, up, down, axis)
     cp.cuda.Stream.null.synchronize()
     return out