示例#1
0
    def process(self):
        # Grab only the new samples into a NumPy array
        x = np.array(self.__l1[-self.__new_samples:])

        # Filter the signal (detrend, LP, MA, etc…)
        # ...
        # ...
        # ...
        # Store the filtered data

        ma = filt.moving_average(x, 20)  # Compute Moving Average
        dt = filt.detrend(ma)  # Detrend the Signal
        lp = filt.filter(self.__b, self.__a, dt)  # Low-pass Filter Signal

        grad = filt.gradient(lp)  # Compute the gradient
        x = filt.moving_average(
            grad, 20)  # Compute the moving average of the gradient

        self.__filtered.add(x.tolist())

        # Count the number of peaks in the filtered data
        count, peaks = filt.count_peaks(x, self.__thresh_low,
                                        self.__thresh_high)

        # Update the step count and reset the new sample count
        self.__steps += count
        self.__new_samples = 0

        # Return the step count, peak locations, and filtered data
        return self.__steps, peaks, np.array(self.__filtered)
    def process(self):
        # Grab only the new samples into a NumPy array
        x = np.array(self.__l1[-self.__new_samples:])

        # Filter the signal (detrend, LP, MA, etc…)
        x = filt.detrend(x)
        # x = filt.filter(self.__b, self.__a, x)
        x, self.__xi, self.__yi = filt.filter_ic(self.__b, self.__a, x,
                                                 self.__xi, self.__yi)
        x = filt.gradient(x)
        x = filt.moving_average(x, 25)

        # Store the filtered data
        self.__filtered.add(x.tolist())

        # Count the number of peaks in the filtered data
        count, peaks = filt.count_peaks(x, self.__thresh_low,
                                        self.__thresh_high)

        # Update the step count and reset the new sample count
        self.__steps += count
        self.__new_samples = 0

        # Return the step count, peak locations, and filtered data
        return self.__steps, peaks, np.array(self.__filtered)
    def process(self):
        # Grab only the new samples into a NumPy array
        x = np.array(self.__ppg[-self.__new_samples:])

        # Filter the signal (feel free to customize!)
        x = filt.detrend(x, 25)
        x = filt.moving_average(x, 5)
        x = filt.gradient(x)
        x = filt.normalize(x)

        # Store the filtered data
        self.__filtered.add(x.tolist())

        # Find the peaks in the filtered data
        _, peaks = filt.count_peaks(x, self.__thresh, 1)

        # Update the step count and reset the new sample count
        self.__hr = self.compute_heart_rate(peaks)
        self.__new_samples = 0

        # Return the heart rate, peak locations, and filtered data
        return self.__hr, peaks, np.array(self.__filtered)
示例#4
0
t = (t - t[0]) / 1e3
ax = data[:, 1]
ay = data[:, 2]
az = data[:, 3]

l1 = filt.l1_norm(ax, ay, az)  # Compute the L1-Norm
print(len(l1))
ma = filt.moving_average(l1, 20)  # Compute Moving Average
dt = filt.detrend(ma)  # Detrend the Signal

freqs, power = filt.psd(l1, len(l1), 50)  # Power Spectral Density

bl, al = filt.create_filter(3, 1, "lowpass", fs)  # Low-pass Filter Design
lp = filt.filter(bl, al, dt)  # Low-pass Filter Signal

grad = filt.gradient(lp)  # Compute the gradient
grad_avg = filt.moving_average(
    grad, 20)  # Compute the moving average of the gradient

count, peaks = filt.count_peaks(grad_avg, t_low,
                                t_high)  # Find & Count the Peaks

# Plot the results
plt.plot(t, grad_avg)
plt.title("Detected Peaks = %d" % count)
plt.plot(t[peaks], grad_avg[peaks], 'rx')
plt.plot(t, [t_low] * len(grad_avg), "b--")
plt.plot(t, [t_high] * len(grad_avg), "b--")
plt.show()

plt.plot(freqs, power)
plt.title("Detrend")
plt.plot(t, ppg)
plt.subplot(212)
plt.plot(t, dt)
plt.show()

ma = filt.moving_average(dt, 5)

plt.subplot(211)
plt.title("Moving Average")
plt.plot(t, ppg)
plt.subplot(212)
plt.plot(t, ma)
plt.show()

grad = filt.gradient(ma)

plt.subplot(211)
plt.title("Gradient")
plt.plot(t, ppg)
plt.subplot(212)
plt.plot(t, grad)
plt.show()

# Normalize the signal
norm = filt.normalize(grad)

plt.subplot(211)
plt.title("Normalize")
plt.plot(t, ppg)
plt.subplot(212)
示例#6
0
def process(x):
  x = filt.detrend(x, 25)
  x = filt.moving_average(x, 5)
  x = filt.gradient(x)
  return filt.normalize(x)