WaveDetector

Overview

Example closed-loop program

 1#include <iostream>
 2#include "hal.h"
 3
 4#define SYS_START_BUFFER 50000
 5
 6int main(int argc, char *argv[]) {
 7    maxlab::verifyStatus(maxlab::DataStreamerFiltered_open(maxlab::FilterType::IIR));
 8
 9    int sampleRate = 10000;
10
11    // ignore system startup activity
12    for (int i = 0; i < SYS_START_BUFFER; i++) {
13        maxlab::FilteredFrameData frameData;
14        maxlab::Status status = maxlab::DataStreamerFiltered_receiveNextFrame(&frameData);
15
16        if (status == maxlab::Status::MAXLAB_NO_FRAME) {
17            i--;
18            continue;
19        }
20    }
21
22    char *configPath = "/home/mxwbio/config.cfg";
23
24    // window length, configuration path, burst threshold, min length, hz
25    WaveDetector wd = WaveDetector(200, configPath, 0.1, 1000, sampleRate);
26
27    // examine the culture for 20 seconds
28    for (int i = 0; i < 200000; i++) {
29        maxlab::FilteredFrameData frameData;
30        maxlab::Status status = maxlab::DataStreamerFiltered_receiveNextFrame(&frameData);
31
32        if (status == maxlab::Status::MAXLAB_NO_FRAME) {
33            i--;
34            continue;
35        }
36
37        // extend the window and check for burst waves
38        int val = wd.processFrame(frame, i + 200 + SYS_START_BUFFER);
39
40        if (val == Wave::leftToRight) {
41            cout << "Culture bursted left to right!" << endl;
42        } else if (val == Wave::rightToLeft) {
43            cout << "Culture bursted right to left!" << endl;
44        }
45    }
46
47    maxlab::verifyStatus(maxlab::DataStreamerFiltered_close());
48}

Members

class WaveDetector

Public Functions

WaveDetector()

Constructs a new Wave Detector object.

WaveDetector(int windowLength, const char *configPath, float threshold, int minFrames, int frameHz, float firstBurstThreshold, float burstDoneThreshold)

Constructs a new Wave Detector object and inititalizes the window.

Parameters:
  • windowLengthint length of the window

  • configPath – c-style string containing the full path of the electrode config

  • thresholdfloat threshold used to check the total spike count against

  • minFramesint minimum number of frames during which the window must be over the spike threshold in order to be considered a burst

  • frameHzint framerate, defaults to 10000. It shoud be 10000 for the MaxTwo, and 20000 for the MaxOne

  • firstBurstThresholdfloat the amount of time (in seconds) during which the total spike count of the window cannot go over the threshold in order for the first birst to be considered done.

  • burstDoneThresholdfloat the amount of time (in seconds) during which the total spike count of the window cannot go over the threshold in order for the entire birst to be considered done.

~WaveDetector()

Destroys the Wave Detector Object.

ChannelWindow *getWindow()

Returns the window.

Returns:

pointer to ChannelWindow

WaveMetadata getMetadata()

Gets metadata of the Wave Detector.

Returns:

WaveMetadata struct

void shiftWindow(maxlab::FilteredFrameData frame)

Shifts the window, adding a new frame.

Parameters:

framemaxlab::FilteredFrameData frame to add to the window

int processFrame(maxlab::FilteredFrameData frame, int frameNo)

Processes a frame.

Shifts the window, and returns the status of the burst

Parameters:
  • framemaxlab::FilteredFrameData frame to process

  • frameNoint frame number when frame was received

Returns:

int

int checkBurst(int frameNo)

Checks the direction of a burst.

Parameters:

frameNoint frame number of the most recently received frame

Returns:

int, corresponds to enum Wave

struct WaveMetadata

Wave metadata struct.

Public Members

bool firstBurstDone

indicates first burst is done

bool bursting

indicates if currently bursting

int spikeFrameCount

number of frames since the total spike count was below the threshold

int noSpikeFrameCount

number of frames since the total spike count went over the threshold

int burstStartLocation

starting location of the current or most recent burst

int burstStartSpikeCount

starting spike count of the current or most recent burst

int burstStartFrame

starting frame of the current or most recent burst

int burstEnd

frame when the last burst ended

int maxSpikes

spike count of the peak of the burst (or most recent peak within the burst)

int maxSpikesFrame

frame number where the peak of the burst occured (or most recent peak within the burst)

float maxSpikesLoc

locatin on the chpi of the peak of the burst (or most recent peak within the burst)

enum Wave

Wave enum.

Values:

enumerator noBurst

culture is not currently bursting

enumerator bursting

culture is currently bursting

enumerator burstStart

burst just started

enumerator endShortBurst

burst ended, but it was too short to be significant

enumerator leftToRight

burst ended, and it went left to right

enumerator rightToLeft

burst ended, and it went right to left