filters_sdk 1.0.0 copy "filters_sdk: ^1.0.0" to clipboard
filters_sdk: ^1.0.0 copied to clipboard

Library for filtering raw signal

example/lib/main.dart

import 'dart:math';

import 'package:filters_sdk/core/filters_list.dart';
import 'package:filters_sdk/core/iir_filter.dart';
import 'package:filters_sdk/core/iir_filter_param.dart';
import 'package:filters_sdk/core/iir_filter_type.dart';
import 'package:filters_sdk/core/preinstalled_filters.dart';
import 'package:flutter/material.dart';

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

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

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

class _MyAppState extends State<MyApp> {

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

  void _onButtonPressed() {
    Set<IIRFilterParam> pf = preinstalledFilters();
    print(preinstalledFilters());

    FiltersList fList = FiltersList();

    IIRFilter f1 = IIRFilter.createWithParams(IIRFilterParam(type: IirFilterType.hp, samplingFreq: 250, cutoffFreq: 10 ));
    IIRFilter f2 = IIRFilter.createWithParams(IIRFilterParam(type: IirFilterType.lp, samplingFreq: 250, cutoffFreq: 40 ));
    IIRFilter f3 = IIRFilter.createWithParams(IIRFilterParam(type: IirFilterType.bandStop, samplingFreq: 250, cutoffFreq: 100 ));

    fList.addFilter(f1);
    fList.addFilter(f2);
    fList.addFilter(f3);

    List<double> rawData = List.generate(10, (idx) => sin(50*idx)*2*3.14 / 180);
    print(rawData);
    var output = fList.filterArray(rawData);
    print(output);

    f1.dispose();
    f2.dispose();
    f3.dispose();
  
    fList.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Packages'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: _onButtonPressed,
                child: const Text('Start Demo'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}