コード例 #1
0
    // Start is called before the first frame update

    void Start()
    {
        try
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.MINDROVE_BLUETOOTH_BOARD;//= parse_args(args, input_params);

            board_shim = new BoardShim(board_id, input_params);
            board_shim.prepare_session();

            board_shim.start_stream(); // use this for default options
                                       //board_shim.start_stream(450000, "file://file_stream.csv:w");

            BrainFlowModelParams concentration_params = new BrainFlowModelParams((int)BrainFlowMetrics.CONCENTRATION, (int)BrainFlowClassifiers.REGRESSION);
            concentration = new MLModel(concentration_params);
            concentration.prepare();
            sampling_rate = 250;//BoardShim.get_sampling_rate(board_id);
            eeg_channels  = BoardShim.get_eeg_channels(board_id);
        }
        catch (BrainFlowException ex)
        {
            Debug.Log(ex);
        }
    }
コード例 #2
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id      = (int)BoardIds.SYNTHETIC_BOARD;
            int sampling_rate = BoardShim.get_sampling_rate(board_id);
            int nfft          = DataFilter.get_nearest_power_of_two(sampling_rate);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(10000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_board_data();
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            // use second channel of synthetic board to see 'alpha'
            int channel = eeg_channels[1];

            board_shim.release_session();
            double[] detrend = DataFilter.detrend(data.GetRow(channel), (int)DetrendOperations.LINEAR);
            Tuple <double[], double[]> psd = DataFilter.get_psd_welch(detrend, nfft, nfft / 2, sampling_rate, (int)WindowFunctions.HANNING);
            double band_power_alpha        = DataFilter.get_band_power(psd, 7.0, 13.0);
            double band_power_beta         = DataFilter.get_band_power(psd, 14.0, 30.0);

            Console.WriteLine("Alpha/Beta Ratio:" + (band_power_alpha / band_power_beta));
        }
コード例 #3
0
ファイル: band_power_all.cs プロジェクト: ywdxll/brainflow
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id      = (int)BoardIds.SYNTHETIC_BOARD;
            int sampling_rate = BoardShim.get_sampling_rate(board_id);
            int nfft          = DataFilter.get_nearest_power_of_two(sampling_rate);

            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(10000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_board_data();
            board_shim.release_session();

            Tuple <double[], double[]> bands = DataFilter.get_avg_band_powers(data, eeg_channels, sampling_rate, true);

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Avg: " + bands.Item1[i] + " Stddev: " + bands.Item2[i]);
            }
        }
コード例 #4
0
ファイル: downsampling.cs プロジェクト: xinterface/brainflow
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            for (int i = 0; i < eeg_channels.Length; i++)
            {
                Console.WriteLine("Before processing:");
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(eeg_channels[i])));
                // you can use MEAN, MEDIAN or EACH for downsampling
                double[] filtered = DataFilter.perform_downsampling(unprocessed_data.GetRow(eeg_channels[i]), 3, (int)AggOperations.MEDIAN);
                Console.WriteLine("Before processing:");
                Console.WriteLine("[{0}]", string.Join(", ", filtered));
            }
        }
コード例 #5
0
ファイル: get_board_data.cs プロジェクト: node2319/brainflow
        static void Main(string[] args)
        {
            BoardShim board_shim = new BoardShim((int)Cython.board_id, "COM3");

            board_shim.prepare_session();
            Console.WriteLine("Session is ready");

            board_shim.start_stream(3600);
            Console.WriteLine("Started");
            System.Threading.Thread.Sleep(5000);

            board_shim.stop_stream();
            Console.WriteLine("Stopped");

            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_board_data();

            // check serialization
            DataHandler dh = new DataHandler((int)BoardIds.CYTHON_BOARD, data_from_board: unprocessed_data);

            dh.save_csv("before_processing.csv");
            dh = new DataHandler((int)BoardIds.CYTHON_BOARD, csv_file: "before_processing.csv");
            dh.save_csv("before_preprocessing2.csv");
            // check preprocessing
            dh.remove_dc_offset();
            dh.bandpass(1.0, 50.0);
            dh.save_csv("after_preprocessing.csv");

            board_shim.release_session();
            Console.WriteLine("Released");
            Console.ReadKey();
        }
コード例 #6
0
ファイル: eeg_metrics.cs プロジェクト: ywdxll/brainflow
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int       board_id      = parse_args(args, input_params);
            BoardShim board_shim    = new BoardShim(board_id, input_params);
            int       sampling_rate = BoardShim.get_sampling_rate(board_shim.get_board_id());
            int       nfft          = DataFilter.get_nearest_power_of_two(sampling_rate);

            int[] eeg_channels = BoardShim.get_eeg_channels(board_shim.get_board_id());

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(10000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_board_data();
            board_shim.release_session();

            Tuple <double[], double[]> bands = DataFilter.get_avg_band_powers(data, eeg_channels, sampling_rate, true);

            double[]             feature_vector = bands.Item1.Concatenate(bands.Item2);
            BrainFlowModelParams model_params   = new BrainFlowModelParams((int)BrainFlowMetrics.CONCENTRATION, (int)BrainFlowClassifiers.REGRESSION);
            MLModel concentration = new MLModel(model_params);

            concentration.prepare();
            Console.WriteLine("Concentration: " + concentration.predict(feature_vector));
            concentration.release();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id      = (int)BoardIds.SYNTHETIC_BOARD;
            int sampling_rate = BoardShim.get_sampling_rate(board_id);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_current_board_data(DataFilter.get_nearest_power_of_two(sampling_rate));
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            for (int i = 0; i < eeg_channels.Length; i++)
            {
                // optional: you can subtract mean from signal before PSD calculation
                Tuple <double[], double[]> psd = DataFilter.get_psd(data.GetRow(eeg_channels[i]), 0,
                                                                    data.GetRow(eeg_channels[i]).Length, sampling_rate, (int)WindowFunctions.HANNING);
                double band_power_alpha = DataFilter.get_band_power(psd, 7.0, 13.0);
                double band_power_beta  = DataFilter.get_band_power(psd, 14.0, 30.0);
                Console.WriteLine("Alpha/Beta Ratio:" + (band_power_alpha / band_power_beta));
            }
        }
コード例 #8
0
    public void init()
    {
        if (isBoardNull())
        {
            return;
        }

        try
        {
            BoardShim.set_log_file("brainflow_log.txt");
            BoardShim.enable_dev_board_logger();

            board_shim = new BoardShim(board_id, input_params);
            board_shim.prepare_session();
            //board_shim.config_board("n");
            board_shim.start_stream(450000, "file://brainflow_data.csv:w");

            samplingRate  = BoardShim.get_sampling_rate(board_id);
            eegChannels   = BoardShim.get_eeg_channels(board_id);
            accelChannels = BoardShim.get_accel_channels(board_id);
            Debug.Log("Brainflow streaming was started");
        }
        catch (BrainFlowException e)
        {
            Debug.Log(e);
            board_id = NO_BOARD_SELECTED;
        }
    }
コード例 #9
0
ファイル: serialization.cs プロジェクト: zybaugur/brainflow
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            Console.WriteLine("Before serialization:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();

            // demo for data serialization
            DataFilter.write_file(unprocessed_data, "test.csv", "w");
            double[,] restored_data = DataFilter.read_file("test.csv");
            Console.WriteLine("After Serialization:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", restored_data.GetRow(index)));
            }
        }
コード例 #10
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            // for demo apply different filters to different channels
            double[] filtered;
            for (int i = 0; i < eeg_channels.Length; i++)
            {
                Console.WriteLine("Before processing:");
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(eeg_channels[i])));
                switch (i)
                {
                case 0:
                    filtered = DataFilter.perform_lowpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 4, (int)FilterTypes.BESSEL, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 1:
                    filtered = DataFilter.perform_highpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 2.0, 4, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 2:
                    filtered = DataFilter.perform_bandpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 15.0, 5.0, 2, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 3:
                    filtered = DataFilter.perform_bandstop(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 50.0, 1.0, 6, (int)FilterTypes.CHEBYSHEV_TYPE_1, 1.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                default:
                    filtered = DataFilter.remove_environmental_noise(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), (int)NoiseTypes.FIFTY);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;
                }
            }
        }
コード例 #11
0
        //  Implementation
        #region Implementation

        public BoardDataReader()
        {
            BoardShim.set_log_level((int)LogLevels.LEVEL_OFF);

            CommandsQueue = new ConcurrentQueue <string>();

            BoardReadDelayMilliseconds = 50;    //  default 20 hz

            SettingsLock = new SemaphoreSlim(1);

            StreamRunning = false;
        }
コード例 #12
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(64);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();

            // for demo apply different methods to different channels
            double[] filtered;
            for (int i = 0; i < eeg_channels.Length; i++)
            {
                switch (i)
                {
                // first of all you can try simple moving average or moving median
                case 0:
                    filtered = DataFilter.perform_rolling_filter(unprocessed_data.GetRow(eeg_channels[i]), 3, (int)AggOperations.MEAN);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 1:
                    filtered = DataFilter.perform_rolling_filter(unprocessed_data.GetRow(eeg_channels[i]), 3, (int)AggOperations.MEDIAN);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                // if for your signal these methods dont work good you can try wavelet based denoising
                default:
                    // feel free to try different functions and different decomposition levels
                    filtered = DataFilter.perform_wavelet_denoising(unprocessed_data.GetRow(eeg_channels[i]), "db4", 3);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;
                }
            }
        }
コード例 #13
0
        public MainWindow()
        {
            InitializeComponent();

#if DEBUG
            BoardShim.set_log_file("./brainflowLogs.txt");
            BoardShim.log_message((int)LogLevels.LEVEL_DEBUG, "Logging Message Test");
#endif
            BrainflowBoard = null;
            LoggingWindow  = null;

            FileWriter      = new BrainHatFileWriter();
            FileWriter.Log += OnLog;
        }
コード例 #14
0
ファイル: transforms.cs プロジェクト: kusumikakd/Brainflow
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(64);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            for (int i = 0; i < eeg_channels.Length; i++)
            {
                Console.WriteLine("Original data:");
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(eeg_channels[i])));
                // demo for wavelet transform
                // tuple of coeffs array in format[A(J) D(J) D(J-1) ..... D(1)] where J is a
                // decomposition level, A - app coeffs, D - detailed coeffs, and array which stores
                // length for each block, len of this array is decomposition_length + 1
                Tuple <double[], int[]> wavelet_data = DataFilter.perform_wavelet_transform(unprocessed_data.GetRow(eeg_channels[i]), "db4", 3);
                // print app coeffs
                for (int j = 0; j < wavelet_data.Item2[0]; j++)
                {
                    Console.Write(wavelet_data.Item1[j] + " ");
                }
                Console.WriteLine();
                // you can do smth with wavelet coeffs here, for example denoising works via thresholds for wavelets coeffs
                double[] restored_data = DataFilter.perform_inverse_wavelet_transform(wavelet_data, unprocessed_data.GetRow(eeg_channels[i]).Length, "db4", 3);
                Console.WriteLine("Restored wavelet data:");
                Console.WriteLine("[{0}]", string.Join(", ", restored_data));

                // demo for fft
                // end_pos - start_pos must be a power of 2
                Complex[] fft_data = DataFilter.perform_fft(unprocessed_data.GetRow(eeg_channels[i]), 0, 64);
                // len of fft_data is N / 2 + 1
                double[] restored_fft_data = DataFilter.perform_ifft(fft_data);
                Console.WriteLine("Restored fft data:");
                Console.WriteLine("[{0}]", string.Join(", ", restored_fft_data));
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: MindRove/SDK_Public
        static void Main(string[] args)
        {
            try
            {
                BoardShim.enable_dev_board_logger();

                BrainFlowInputParams input_params = new BrainFlowInputParams();
                int board_id = (int)BoardIds.MINDROVE_WIFI_BOARD;//= parse_args(args, input_params);

                board_shim = new BoardShim(board_id, input_params);
                board_shim.prepare_session();

                board_shim.start_stream(); // use this for default options
                                           //board_shim.start_stream(450000, "file://file_stream.csv:w");

                board_shim.config_board(BoardShim.MindroveWifiConfigMode.EEG_MODE);
                BrainFlowModelParams concentration_params = new BrainFlowModelParams((int)BrainFlowMetrics.CONCENTRATION, (int)BrainFlowClassifiers.REGRESSION);
                concentration = new MLModel(concentration_params);
                concentration.prepare();

                sampling_rate = BoardShim.get_sampling_rate(board_id);
                eeg_channels  = BoardShim.get_eeg_channels(board_id);
                counter_idx   = BoardShim.get_package_num_channel(board_id);
            }
            catch (BrainFlowException ex)
            {
                Console.WriteLine(ex);
            }
            while (Update() >= 0)
            {
            }

            if (board_shim != null)
            {
                try
                {
                    board_shim.release_session();
                    concentration.release();
                }
                catch (BrainFlowException e)
                {
                    Console.WriteLine(e);
                }
                Console.WriteLine("Brainflow streaming was stopped");
            }
            Console.ReadLine();
        }
コード例 #16
0
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = parse_args(args, input_params);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(450000, "file://file_stream.csv:w");
            for (int i = 1; i < 5; i++)
            {
                System.Threading.Thread.Sleep(1000);
                board_shim.insert_marker(i);
            }
            board_shim.stop_stream();
            board_shim.release_session();
        }
コード例 #17
0
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();
            BoardShim board_shim;

            if (args.Length == 2)
            {
                board_shim = new BoardShim(Int32.Parse(args[0]), args[1]);
            }
            else
            {
                board_shim = new BoardShim(Int32.Parse(args[0]), null);
            }

            board_shim.prepare_session();
            Console.WriteLine("Session is ready");

            board_shim.start_stream(3600);
            Console.WriteLine("Started");
            System.Threading.Thread.Sleep(5000);

            board_shim.stop_stream();
            Console.WriteLine("Stopped");

            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_board_data();

            // check serialization
            DataHandler dh = new DataHandler(Int32.Parse(args[0]), data_from_board: unprocessed_data);

            dh.save_csv("before_processing.csv");
            dh = new DataHandler(Int32.Parse(args[0]), csv_file: "before_processing.csv");
            dh.save_csv("before_preprocessing2.csv");
            // check preprocessing
            dh.remove_dc_offset();
            dh.bandpass(1.0, 50.0);
            dh.save_csv("after_preprocessing.csv");

            board_shim.release_session();
            Console.WriteLine("Released");
        }
コード例 #18
0
ファイル: BoardIds.cs プロジェクト: GrahamBriggs/bcibeginner
        public static int GetSampleRate(int boardId)
        {
            int useBoardId = boardId;

            switch ((BrainhatBoardIds)boardId)
            {
            case BrainhatBoardIds.MENTALIUM:
                useBoardId = 0;
                break;
            }

            switch ((BrainhatBoardIds)useBoardId)
            {
            default:
                return(0);

            case BrainhatBoardIds.CYTON_BOARD:
            case BrainhatBoardIds.CYTON_DAISY_BOARD:
                return(BoardShim.get_sampling_rate(useBoardId));
            }
        }
コード例 #19
0
ファイル: BoardIds.cs プロジェクト: GrahamBriggs/bcibeginner
        public static int GetTimestampChannel(int boardId)
        {
            int useBoardId = boardId;

            switch ((BrainhatBoardIds)boardId)
            {
            case BrainhatBoardIds.MENTALIUM:
                useBoardId = 0;
                break;
            }

            switch ((BrainhatBoardIds)useBoardId)
            {
            default:
                return(0);

            case BrainhatBoardIds.CYTON_BOARD:
            case BrainhatBoardIds.CYTON_DAISY_BOARD:
                return(BoardShim.get_timestamp_channel(useBoardId));
            }
        }
コード例 #20
0
ファイル: BoardIds.cs プロジェクト: GrahamBriggs/bcibeginner
        public static int GetNumberOfAccelChannels(int boardId)
        {
            int useBoardId = boardId;

            switch ((BrainhatBoardIds)boardId)
            {
            case BrainhatBoardIds.MENTALIUM:
                useBoardId = 0;
                break;
            }

            switch ((BrainhatBoardIds)useBoardId)
            {
            default:
                return(0);

            case BrainhatBoardIds.CYTON_BOARD:
            case BrainhatBoardIds.CYTON_DAISY_BOARD:
                return(BoardShim.get_accel_channels(useBoardId).Length);
            }
        }
コード例 #21
0
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = parse_args(args, input_params);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            // board_shim.start_stream (); // use this for default options
            board_shim.start_stream(450000, "file://file_stream.csv:w");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();
        }
コード例 #22
0
        public void OpenBciBoardIndicesTest()
        {
            var board = (int)BoardIds.GANGLION_BOARD;

            try
            {
                var exg = BoardShim.get_exg_channels(board);
                System.Diagnostics.Debug.WriteLine($"EXG: {string.Join(",", exg)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No EXG");
            }

            try
            {
                var ecg = BoardShim.get_ecg_channels(board);
                System.Diagnostics.Debug.WriteLine($"ECG: {string.Join(",", ecg)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No ECG");
            }



            try
            {
                var emg = BoardShim.get_emg_channels(board);
                System.Diagnostics.Debug.WriteLine($"EMG: {string.Join(",", emg)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No EMG");
            }

            try
            {
                var eog = BoardShim.get_eog_channels(board);
                System.Diagnostics.Debug.WriteLine($"EOG: {string.Join(",", eog)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No EOG");
            }

            try
            {
                var accel = BoardShim.get_accel_channels(board);
                System.Diagnostics.Debug.WriteLine($"ACCEL: {string.Join(",", accel)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No ACCEL");
            }

            try
            {
                var other = BoardShim.get_other_channels(board);
                System.Diagnostics.Debug.WriteLine($"OTHER: {string.Join(",", other)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No OTHER");
            }

            try
            {
                var ang = BoardShim.get_analog_channels(board);
                System.Diagnostics.Debug.WriteLine($"ANG: {string.Join(",", ang)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No ANG");
            }

            try
            {
                var time = BoardShim.get_timestamp_channel(board);
                System.Diagnostics.Debug.WriteLine($"TIME: {time}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No TIME");
            }

            try
            {
                var eda = BoardShim.get_eda_channels(board);
                System.Diagnostics.Debug.WriteLine($"EDA: {string.Join(",", eda)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No EDA");
            }

            try
            {
                var bat = BoardShim.get_battery_channel(board);
                System.Diagnostics.Debug.WriteLine($"BAT: {string.Join(",", bat)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No BAT");
            }

            try
            {
                var gyro = BoardShim.get_gyro_channels(board);
                System.Diagnostics.Debug.WriteLine($"GYRO: {string.Join(",", gyro)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No GYRO");
            }



            try
            {
                var pkg = BoardShim.get_package_num_channel(board);
                System.Diagnostics.Debug.WriteLine($"PKG: {string.Join(",", pkg)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No PKG");
            }

            try
            {
                var ppg = BoardShim.get_ppg_channels(board);
                System.Diagnostics.Debug.WriteLine($"PPG: {string.Join(",", ppg)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No PPG");
            }

            try
            {
                var res = BoardShim.get_resistance_channels(board);
                System.Diagnostics.Debug.WriteLine($"RES: {string.Join(",", res)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No RES");
            }

            try
            {
                var tmp = BoardShim.get_temperature_channels(board);
                System.Diagnostics.Debug.WriteLine($"TMP: {string.Join(",", tmp)}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("No TMP");
            }
        }
コード例 #23
0
        /// <summary>
        /// Init the board session
        /// </summary>
        private async Task InitializeBoardAsync()
        {
            try
            {
                Log?.Invoke(this, new LogEventArgs(this, "InitializeBoardAsync", $"Initializaing board", LogLevel.DEBUG));

                await ReleaseBoardAsync();

                RequestToggleStreamingMode = false;

                var useBoardId = BoardId;
                switch ((BrainhatBoardIds)BoardId)
                {
                case BrainhatBoardIds.MENTALIUM:
                    useBoardId = 0;
                    break;
                }

                TheBoard = new BoardShim(useBoardId, InputParams);

                SampleRate     = BrainhatBoardShim.GetSampleRate(BoardId);
                TimeStampIndex = BrainhatBoardShim.GetTimestampChannel(BoardId);

                TheBoard.prepare_session();
                await Task.Delay(TimeSpan.FromSeconds(1));

                TheBoard.config_board("s");


                BoardSettings = new CytonBoardsImplementation();
                if (!await LoadBoardRegistersSettings(1))
                {
                    throw new Exception("Unable to get board register settings");
                }

                //  TODO - clean up SRB1 start setting
                if (StartSrb1CytonSet)
                {
                    await SetSrb1Async(BoardSettings.Boards[0].Channels[0], true);

                    if (StartSrb1DaisySet && (BrainhatBoardIds)BoardId == BrainhatBoardIds.CYTON_DAISY_BOARD && BoardSettings.Boards.Count() > 1)
                    {
                        await SetSrb1Async(BoardSettings.Boards[1].Channels[0], true);
                    }

                    BoardSettings = new CytonBoardsImplementation();
                    if (!await LoadBoardRegistersSettings(1))
                    {
                        throw new Exception("Unable to get board register settings");
                    }
                }

                await StartStreamingAsync();

                await Task.Delay(TimeSpan.FromSeconds(5));

                ConnectToBoard?.Invoke(this, new ConnectToBoardEventArgs(BoardId, SampleRate));
            }
            catch (Exception e)
            {
                Log?.Invoke(this, new LogEventArgs(this, "InitializeBoardAsync", e, LogLevel.ERROR));

                if (TheBoard != null && TheBoard.is_prepared())
                {
                    TheBoard.release_session();
                }
                TheBoard = null;
            }
        }
コード例 #24
0
    // Update is called once per frame
    void Update()
    {
        //Early out if board was not init properly or no board was selected
        if (board_shim == null)
        {
            return;
        }

        int number_of_data_points = DataFilter.get_nearest_power_of_two(samplingRate);

        double[,] data = board_shim.get_current_board_data(number_of_data_points);

        if (data.GetRow(0).Length < number_of_data_points)
        {
            // wait for more data
            return;
        }

        //accelData = data.GetRow(accelChannels[0]);
        //Debug.Log(String.Format("[{0}]", string.Join(", ", accelData)));

        double[] filtered;
        for (int i = 0; i < numChan; i++)
        {
            //Debug.Log("Before processing:");
            //Debug.Log(String.Format("[{0}]", string.Join(", ", data.GetRow(eegChannels[i]))));

            filtered = DataFilter.perform_bandpass(data.GetRow(eegChannels[i]), BoardShim.get_sampling_rate(board_id), 15.0, 5.0, 2, (int)FilterTypes.BUTTERWORTH, 0.0);
            //Debug.Log("Filtered channel " + eegChannels[i]);
            //Debug.Log(String.Format("[{0}]", string.Join(", ", filtered)));

            /*
             * // calc bandpowers per channel
             * for (int i = 0; i < numChan; i++)
             * {
             *  Tuple<double[], double[]> psd = DataFilter.get_psd(data.GetRow(eegChannels[i]), 0,
             *      data.GetRow(eegChannels[i]).Length, samplingRate, (int)WindowFunctions.HANNING);
             *  double band_power_alpha = DataFilter.get_band_power(psd, 7.0, 13.0);
             *  double band_power_beta = DataFilter.get_band_power(psd, 14.0, 30.0);
             *  double band_power_gamma = DataFilter.get_band_power(psd, 31.0, 100.0);
             *  //double ratio = (band_power_alpha / band_power_beta);
             *
             *  //Debug.Log("Channel " + i + " | Alpha/Beta Ratio:" + ratio);
             *  ratios[i] = normalized_value(i, band_power_alpha);
             * }
             */

            /////WORKING HERE
            //for data size for 1 channel, add absolute value of all values, and divide by size
            double myAverage         = 0f;
            float  smoothing         = .25f;
            float  averagePeriod     = BoardShim.get_sampling_rate(board_id) * smoothing;
            float  acceptableLimitUV = 200f;
            for (int j = filtered.Length - (int)averagePeriod; j < filtered.Length; j++)
            {
                double value = Math.Abs(filtered[j]);
                if (value <= acceptableLimitUV)
                {                       //prevent BIG spikes from effecting the average
                    myAverage += value; //add value to average ... we will soon divide by # of packets
                }
                else
                {
                    myAverage += acceptableLimitUV; //if it's greater than the limit, just add the limit
                }
            }
            myAverage = myAverage / averagePeriod; // float(cfc.averagePeriod); //finishing the average


            double output_normalized = normalized_value(i, myAverage);

            if (output_normalized < 0)
            {
                output_normalized = 0; //always make sure this value is >= 0
            }
            //output_adjusted = ((-0.1d / (output_normalized * 255d)) + 255d);
            ratios[i] = output_normalized;

            //Debug.Log("CHAN " + i + " | output_norm = " + output_normalized);
        }
    }
コード例 #25
0
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = parse_args(args, input_params);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            Console.WriteLine("Before processing:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();

            // demo for data serialization
            DataFilter.write_file(unprocessed_data, "test.csv", "w");
            double[,] restored_data = DataFilter.read_file("test.csv");
            Console.WriteLine("After Serialization:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", restored_data.GetRow(index)));
            }

            // for demo apply different filters to different channels
            double[] filtered;
            for (int i = 0; i < eeg_channels.Length; i++)
            {
                switch (i)
                {
                case 0:
                    filtered = DataFilter.perform_lowpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 4, (int)FilterTypes.BESSEL, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 1:
                    filtered = DataFilter.perform_highpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 2.0, 4, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 2:
                    filtered = DataFilter.perform_bandpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 5.0, 2, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 3:
                    filtered = DataFilter.perform_bandstop(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 1.0, 6, (int)FilterTypes.CHEBYSHEV_TYPE_1, 1.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;
                }
            }
        }