spectrum_lib 1.0.1 copy "spectrum_lib: ^1.0.1" to clipboard
spectrum_lib: ^1.0.1 copied to clipboard

Mathematical library for calculating the EEG signal spectrum

example/lib/main.dart

import 'dart:ffi';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:spectrum_lib/spectrum_lib.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  int samplingRate = 500;
  int processWinRate = 2;
  int fftWindow = 500 * 4;

  late final SpectrumLib spectrumLib;

  @override
  void initState() {
    super.initState();

    spectrumLib = SpectrumLib(samplingRate, fftWindow, processWinRate);

    int bordFrequency = 30;
    spectrumLib.initParams(bordFrequency, true);
  }

  @override
  void dispose() {
    spectrumLib.dispose();
    super.dispose();
  }

  void _onButtonPressed() {
    double deltaCoef = 0.0;
    double thetaCoef = 1.0;
    double alphaCoef = 1.0;
    double betaCoef = 1.0;
    double gammaCoef = 0.0;
    spectrumLib.setWavesCoeffs(deltaCoef, thetaCoef, alphaCoef, betaCoef, gammaCoef);

    double nBinsFor1hz = spectrumLib.getFFTBinsFor1Hz();

    int winLen = 500;
    List<double> data = List.filled(winLen, 0.0);

    for (var i = 0; i < 100; i++) {
      for (int j = 0; j < 40; j++) {
        for (int i = 0; i < winLen; i++) {
          data[i] = 10 * sin(10 * i * (2 * pi / samplingRate));
        }

        spectrumLib.pushAndProcessData(data);

        List<RawSpectrumData> rawSpectData = spectrumLib.readRawSpectrumInfoArr();
        nBinsFor1hz = spectrumLib.getFFTBinsFor1Hz();

        for (int i = 0; i < rawSpectData.length; i++) {
          print("Bins: $nBinsFor1hz AllBinsValue: ${rawSpectData[i].allBinsValues.length} RawPow: ${rawSpectData[i].totalRawPow}");
        }

        spectrumLib.setNewSampleSize();
        
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SpectrumLib example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: _onButtonPressed,
                child: const Text('Start Demo'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
pub points
0%
popularity

Publisher

verified publisherbrainbit.com

Mathematical library for calculating the EEG signal spectrum

Homepage
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

ffi, flutter, plugin_platform_interface

More

Packages that depend on spectrum_lib