예제 #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)
예제 #2
0
data = load_data("./data/offline_data.csv")
t = data[:, 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()