Esempio n. 1
0
def getCSI(scaled_csi, metric="amplitude"):
    no_frames = len(scaled_csi)
    no_subcarriers = scaled_csi[0]["csi"].shape[0]

    finalEntries = np.zeros((no_subcarriers, no_frames))

    for x in range(no_frames):
        scaled_entry = scaled_csi[x]["csi"]
        for y in range(no_subcarriers):
            if metric == "phasediff":
                if scaled_entry.shape[1] >= 2:
                    #Not 100% sure this generates correct Phase Difference.
                    finalEntries[y][x] = np.angle(
                        scaled_entry[y][1][0]) - np.angle(
                            scaled_entry[y][0][0])
                else:
                    #In cases where only one antenna is available,
                    #reuse the previous value.
                    finalEntries[y][x] = finalEntries[y][x - 1]
            elif metric == "amplitude":
                if scaled_entry.shape[1] >= 2:
                    finalEntries[y][x] = db(abs(scaled_entry[y][1][0]))
                else:
                    finalEntries[y][x] = db(abs(scaled_entry[y][0][0]))

    return (no_frames, no_subcarriers, finalEntries)
Esempio n. 2
0
    def updateVariance(self, data):

        self.all_data.append(data)
        if not self.updateTimestamps():
            self.all_data = self.all_data[:-1]
            return None
        scaled_csi = self.all_data

        no_frames = len(scaled_csi)
        no_subcarriers = scaled_csi[0]["csi"].shape[0]

        y = []

        finalEntry = np.zeros((no_subcarriers, no_frames))
        hampelData = np.zeros((no_subcarriers, no_frames))
        smoothedData = np.zeros((no_subcarriers, no_frames))

        for x in range(no_subcarriers):
            finalEntry[x] = [
                db(abs(scaled_csi[y]["csi"][x][0][0]))
                for y in range(no_frames)
            ]
            #hampelData = hampel(finalEntry[x].flatten(), 10)
            #smoothedData = running_mean(hampelData, 25)
            y.append(variance(finalEntry[x]))

        x = list(range(1, 31))

        self.plot.set_xdata(x)
        self.plot.set_ydata(y)

        self.ax.relim()
        self.ax.autoscale_view()
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
Esempio n. 3
0
    def updateContents(self, data):
        self.all_data.append(data)
        if not self.updateTimestamps():
            self.all_data = self.all_data[:-1]
            return None

        scaled_csi = self.all_data

        no_frames = len(scaled_csi)
        no_subcarriers = 30

        finalEntry = [
            db(abs(scaled_csi[x]["csi"][14][1][0])) for x in range(no_frames)
        ]

        x = list([x["timestamp"] for x in scaled_csi])

        #self.plotStand.set_xdata(x)
        #self.plotStand.set_ydata(finalEntry)

        hampelData = hampel(finalEntry, 20)
        #smoothedData = running_mean(hampelData.copy(), 15)

        self.plotHampel.set_xdata(x)
        self.plotHampel.set_ydata(hampelData)

        #self.plotAll.set_xdata(x)
        #self.plotAll.set_ydata(smoothedData)

        self.ax.relim()
        self.ax.autoscale_view()
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
Esempio n. 4
0
    def updateHeat2(self, data):
        self.all_data.append(data)
        if not self.updateTimestamps():
            self.all_data = self.all_data[:-1]
            return None
        scaled_csi = self.all_data

        no_frames = len(scaled_csi)
        no_subcarriers = scaled_csi[0]["csi"].shape[0]
        ylimit = scaled_csi[no_frames - 1]["timestamp"]

        if no_frames < 80:
            return None

        # limits = [1, no_subcarriers, 0, ylimit]
        limits = [0, ylimit, 1, no_subcarriers]

        finalEntry = np.zeros((no_subcarriers, no_frames))

        #Replace complex CSI with amplitude.
        for y in range(no_subcarriers):
            for x in range(no_frames):
                scaled_entry = scaled_csi[x]["csi"]
                finalEntry[y][x] = db(abs(scaled_entry[y][0][0]))

        for j in range(no_subcarriers):
            sig = finalEntry[j]
            #hampelData = hampel(sig, 10)
            #smoothedData = running_mean(sig, 30)

            y = sig.flatten()
            y = bandpass(5, 1.0, 1.3, 20, y)

            for x in range(70):
                y[x] = 0

            finalEntry[j] = y

        #x = subcarrier index
        #y = time (s)
        #z = amplitude (cBm)

        if not hasattr(self, "im"):
            self.im = self.ax.imshow(finalEntry,
                                     cmap="jet",
                                     extent=limits,
                                     aspect="auto")
            cbar = self.ax.figure.colorbar(self.im, ax=self.ax)
            cbar.ax.set_ylabel("Amplitude (dBm)", rotation=-91, va="bottom")
        else:
            self.im.set_array(finalEntry)
            self.im.set_extent(limits)

        self.ax.relim()
        self.ax.autoscale_view()
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
Esempio n. 5
0
    def get_total_rss(self, rssi_a, rssi_b, rssi_c, agc):
    # Calculates the Received Signal Strength (RSS) in dBm from
    # Careful here: rssis could be zero
        rssi_mag = 0
        if rssi_a != 0:
            rssi_mag = rssi_mag + dbinv(rssi_a)
        if rssi_b != 0:
            rssi_mag = rssi_mag + dbinv(rssi_b)
        if rssi_c != 0:
            rssi_mag = rssi_mag + dbinv(rssi_c)

        return db(rssi_mag) - 44 - agc
Esempio n. 6
0
    def updateHeat(self, data):
        self.all_data.append(data)
        if not self.updateTimestamps():
            self.all_data = self.all_data[:-1]
            return None
        scaled_csi = self.all_data

        no_frames = len(scaled_csi)
        no_subcarriers = scaled_csi[0]["csi"].shape[0]
        ylimit = scaled_csi[no_frames - 1]["timestamp"]

        if no_frames < 10:
            return None

        limits = [1, no_subcarriers, 0, ylimit]

        finalEntry = np.zeros((no_frames, no_subcarriers))

        #Replace complex CSI with amplitude.
        for y in range(no_subcarriers):
            for x in range(no_frames):
                scaled_entry = scaled_csi[x]["csi"]
                finalEntry[x][y] = db(abs(scaled_entry[y][0][0]))

        #x = subcarrier index
        #y = time (s)
        #z = amplitude (cBm)

        finalEntry = finalEntry[::-1]

        if not hasattr(self, "im"):
            self.im = self.ax.imshow(finalEntry,
                                     cmap=plt.cm.gist_rainbow_r,
                                     extent=limits,
                                     aspect="auto")
            cbar = self.ax.figure.colorbar(self.im, ax=self.ax)
            cbar.ax.set_ylabel("Amplitude (dBm)", rotation=-91, va="bottom")
        else:
            self.im.set_array(finalEntry)
            self.im.set_extent(limits)

        self.ax.relim()
        self.ax.autoscale_view()
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
Esempio n. 7
0
    def updateButterworth(self, data):
        self.all_data.append(data)
        self.updateTimestamps()

        if not self.updateTimestamps():
            self.all_data = self.all_data[:-1]
            return None
        scaled_csi = self.all_data

        no_frames = len(scaled_csi)
        no_subcarriers = scaled_csi[0]["csi"].shape[0]

        if no_frames < 50:
            return None

        #Replace complex CSI with amplitude.
        finalEntry = [
            db(abs(scaled_csi[x]["csi"][15][0][0])) for x in range(no_frames)
        ]

        hampelData = hampel(finalEntry, 10)
        smoothedData = running_mean(hampelData, 30)
        y = smoothedData

        x = list([x["timestamp"] for x in scaled_csi])
        tdelta = (x[-1] - x[0]) / len(x)

        Fs = 1 / tdelta
        n = no_frames

        y = bandpass(5, 1.0, 1.3, Fs, y)

        ffty = np.fft.rfft(y, len(y))
        freq = np.fft.rfftfreq(len(y), tdelta)
        freqX = [((i * Fs) / n) * 60 for i in range(len(freq))]

        self.plotButt.set_xdata(freqX)
        self.plotButt.set_ydata(np.abs(ffty))

        self.ax.relim()
        self.ax.autoscale_view()
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
Esempio n. 8
0
def getCSI(trace, metric="amplitude"):
    no_frames = len(trace)
    no_subcarriers = trace[0]["csi"].shape[0]

    csi = np.zeros((no_subcarriers, no_frames))

    for x in range(no_frames):
        scaled_entry = trace[x]["csi"]
        for y in range(no_subcarriers):
            if metric == "amplitude":
                csi[y][x] = db(abs(scaled_entry[y]))
                # csi[y][x] = abs(scaled_entry[y])
            elif metric == "phasediff":
                if scaled_entry.shape[1] >= 2:
                    #Not 100% sure this generates correct Phase Difference.
                    csi[y][x] = np.angle(scaled_entry[y][1][0]) - np.angle(
                        scaled_entry[y][0][0])
                else:
                    #In cases where only one antenna is available,
                    #reuse the previous value.
                    csi[y][x] = csi[y][x - 1]

    return (csi, no_frames, no_subcarriers)
Esempio n. 9
0
def shorttime(reader, subcarrier):

    scaled_csi = reader.csi_trace

    no_frames = len(scaled_csi)
    no_subcarriers = scaled_csi[0]["csi"].shape[0]

    finalEntry = np.zeros((no_frames, 1))
    hampelData = np.zeros((no_frames, 1))
    smoothedData = np.zeros((no_frames, 1))

    #Replace complex CSI with amplitude.

    finalEntry = [
        db(
            abs(scaled_csi[x]["csi"][subcarrier][reader.x_antenna][
                reader.y_antenna])) for x in range(no_frames)
    ]

    hampelData = hampel(finalEntry, 30)
    smoothedData = running_mean(hampelData, 20)
    y = smoothedData

    tdelta = 0.01
    x = list([x * tdelta for x in range(0, no_frames)])

    Fs = 1 / tdelta
    n = no_frames

    fmin = 0.7
    fmax = 2.3

    b, a = signal.butter(3, [fmin / (Fs / 2), fmax / (Fs / 2)], "bandpass")
    y = signal.lfilter(b, a, y)

    f, t, Zxx = signal.stft(y, Fs, nperseg=2000, noverlap=1750)

    #bin indices for the observed amplitude peak in each segment.
    Zxx = np.abs(Zxx)
    maxAx = np.argmax(Zxx, axis=0)

    freqs = []
    for i in maxAx:
        arc = f[i]
        if arc >= fmin and arc <= fmax:
            arc *= 60
            freqs.append(arc)
        else:
            freqs.append(None)

    bpms = []
    for freq in freqs:
        if freq != None:
            bpms.append(freq)

    print(bpms)
    print("Average HR: " + str(np.average(bpms)))

    #We're only interested in frequencies between 0.5 and 2.
    freq_slice = np.where((f >= fmin) & (f <= fmax))

    f = f[freq_slice]
    Zxx = Zxx[freq_slice, :][0]

    plt.pcolormesh(t, f * 60, np.abs(Zxx))
    plt.plot(t, freqs, color="red", marker="x")

    plt.title('STFT Magnitude')
    # plt.ylabel('Frequency [Hz]')
    plt.ylabel('Heart Rate [BPM]')
    plt.xlabel('Time [sec]')
    plt.show()