### VibDataProcessing.removeArrayMean API Documentation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/removeArrayMean API reference for the static `removeArrayMean` method in the `VibDataProcessing` class. It details the method signature, parameters, return value, and provides an implementation example. ```APIDOC VibDataProcessing.removeArrayMean Signature: static List removeArrayMean(List data) Description: Removes the mean value from each element in a list of doubles. This is useful for centering data around zero. Parameters: - data: A List of double values from which to remove the mean. The list should not be empty. Returns: A new List where each element is the original element minus the mean of the input list. Returns an empty list if the input list is empty. Example: static List removeArrayMean(List data) { if (data.isEmpty) { return []; } double total = 0; for (var element in data) { total += element; } var avg = total / data.length; return data.map((e) { return e - avg; }).toList(); } ``` -------------------------------- ### Convert Acceleration to Distance Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/accToDist The accToDist method converts acceleration data to distance. It internally uses accToVel to get velocity and then dataIntegralFreqOne for integration. This function is part of the VibDataProcessing class. ```APIDOC VibDataProcessing.accToDist static List accToDist(List wave, double fs, double fMin, double fMax) Converts acceleration data to distance. Parameters: - wave: A List of doubles representing the input acceleration waveform. - fs: The sampling frequency of the input signal (double). - fMin: The minimum frequency for processing (double). - fMax: The maximum frequency for processing (double). Returns: A List of doubles representing the calculated distance. Dependencies: - accToVel(wave, fs, fMin, fMax) - dataIntegralFreqOne(vel, fs, fMin, fMax * 2.56 / 2) Implementation Example: static List accToDist( List wave, double fs, double fMin, double fMax) { var vel = accToVel(wave, fs, fMin, fMax); return dataIntegralFreqOne(vel, fs, fMin, (fMax * 2.56) / 2); } ``` -------------------------------- ### Get Magnitude of Complex Number Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex/magnitude Calculates and returns the magnitude (absolute value) of the complex number using the Pythagorean theorem. It requires the real and imaginary components. ```dart double get magnitude { return math.sqrt(real * real + imaginary * imaginary).abs(); } ``` -------------------------------- ### Publish Flutter Package Source: https://pub.dev/documentation/flutter_signal_processing/latest/index Publishes a Flutter package to the Dart package repository. Ensure you are in the package directory before executing. ```bash flutter packages pub publish --server=https://pub.dartlang.org ``` -------------------------------- ### VibDataProcessing.fftCalc Method Documentation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/fftCalc API documentation for the static fftCalc method within the VibDataProcessing class. It outlines the method signature, parameters, return values, and provides the implementation details. ```APIDOC VibDataProcessing.fftCalc static List fftCalc(List data, {bool removeMean = true, bool paddingWithZeros = true}) - Calculates the Fast Fourier Transform (FFT) of input data. - Parameters: - data: A list of double values representing the input signal. - removeMean: If true, the mean of the data will be removed before FFT. Defaults to true. - paddingWithZeros: If true, the data will be padded with zeros to the next power of two before FFT. Defaults to true. - Returns: A list of doubles representing the magnitudes of the FFT results, normalized by half the data length. ## Implementation ```dart static List fftCalc(List data, {bool removeMean = true, bool paddingWithZeros = true}) { var calcData = data; if (removeMean) { calcData = removeArrayMean(calcData); } if (paddingWithZeros) { calcData = padArrayWithZeros(calcData); } var fftResult = realFFT(calcData); var retLen = (calcData.length / 2).floor(); return fftResult.take(retLen).map((item) { return item.magnitude / (calcData.length / 2); }).toList(); } ``` ``` -------------------------------- ### VibDataProcessing Class API Reference (Dart) Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Provides detailed API documentation for the VibDataProcessing class, including its constructors, properties, methods, and operators. This class is part of the flutter_signal_processing package. ```APIDOC VibDataProcessing class Constructors: VibDataProcessing.new() - Creates a new instance of VibDataProcessing. Properties: hashCode → int - The hash code for this object. - inherited runtimeType → Type - A representation of the runtime type of the object. - inherited Methods: noSuchMethod(Invocation invocation) → dynamic - Invoked when a nonexistent method or property is accessed. - inherited toString() → String - A string representation of this object. - inherited Operators: operator ==(Object other) → bool - The equality operator. - inherited ``` -------------------------------- ### dsp.newArrayOfZeros Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Creates a new list of doubles initialized with zeros. ```APIDOC newArrayOfZeros(int n) -> List - Creates a new array of zeros. - Parameters: - n: The desired size of the array. - Returns: A list of doubles of size n, filled with zeros. ``` -------------------------------- ### Complex Class API Documentation Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex-class Provides a comprehensive overview of the Complex class, including its constructors for initialization, properties for accessing real and imaginary parts, methods for operations like division, and operators for comparison. ```APIDOC Complex Class API Documentation Constructors: * Complex.new([double real = 0, double imaginary = 0]) Description: Creates a new Complex number with specified real and imaginary parts. Parameters: - real: The real part of the complex number (default: 0). Type: double. - imaginary: The imaginary part of the complex number (default: 0). Type: double. * Complex.ri(double real, double imaginary) Description: Creates a new Complex number from real and imaginary components. Parameters: - real: The real part. Type: double. - imaginary: The imaginary part. Type: double. Properties: * hashCode → int Description: The hash code for this object. Inherited. * imaginary → double Description: The imaginary part of the complex number. Final. * magnitude → double Description: The magnitude (or modulus) of the complex number. No setter. * real → double Description: The real part of the complex number. Final. * runtimeType → Type Description: A representation of the runtime type of the object. Inherited. Methods: * div(Complex b1) → Complex Description: Divides this complex number by another complex number. Parameters: - b1: The complex number to divide by. Type: Complex. Returns: The result of the division. Type: Complex. * noSuchMethod(Invocation invocation) → dynamic Description: Invoked when a nonexistent method or property is accessed. Inherited. * toString() → String Description: A string representation of this object. Inherited. Operators: * operator ==(Object other) → bool Description: The equality operator. Inherited. ``` -------------------------------- ### accToVel Implementation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/accToVel The Dart implementation of the accToVel static method. It performs frequency domain integration by calling the dataIntegralFreqOne function with specific parameters derived from the inputs. ```dart static List accToVel( List wave, double fs, double fMin, double fMax) { return dataIntegralFreqOne(wave, fs, fMin, (fMax * 2.56) / 2); } ``` -------------------------------- ### Compile Dart to JavaScript Source: https://pub.dev/documentation/flutter_signal_processing/latest/index Compiles a Dart file to JavaScript using the Dart compiler. This command is useful for web or Node.js environments. ```dart dart compile js ./lib/vibdata_processing.dart -o 1.js -o0 ``` -------------------------------- ### VibDataProcessing Constructor (Dart) Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/VibDataProcessing Initializes a new instance of the VibDataProcessing class. This constructor is part of the flutter_signal_processing package and is used to create objects for processing vibration data. ```dart VibDataProcessing() - Constructor for the VibDataProcessing class. - Initializes a new instance of the class. - Parameters: None explicitly defined in the provided documentation. - Returns: An instance of the VibDataProcessing class. - Usage Example: final vibDataProcessor = VibDataProcessing(); ``` -------------------------------- ### dsp.transform Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Performs a forward transformation on real and imaginary components. ```APIDOC transform(List real, List imag) -> void - Performs a forward transformation. - Parameters: - real: Real parts of the input data. - imag: Imaginary parts of the input data. - Returns: void ``` -------------------------------- ### VibDataProcessing.accToVel Method Signature Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/accToVel Defines the signature, parameters, and return type for the accToVel static method. This method converts acceleration data to velocity using frequency domain integration. ```APIDOC VibDataProcessing.accToVel static List accToVel(List wave, double fs, double fMin, double fMax) Converts acceleration data to velocity. Parameters: - wave: A List of doubles representing the input acceleration signal. - fs: The sampling frequency of the signal (double). - fMin: The minimum frequency for filtering (double). - fMax: The maximum frequency for filtering (double). Returns: A List of doubles representing the calculated velocity signal. ``` -------------------------------- ### dsp.realFFT Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Computes the Fast Fourier Transform (FFT) for real-valued input data. ```APIDOC realFFT(List data) -> List - Computes the Fast Fourier Transform (FFT) for real input. - Parameters: - data: A list of doubles representing the time-domain signal. - Returns: A list of Complex numbers representing the frequency-domain data. ``` -------------------------------- ### Complex.ri Constructor Signature Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex/Complex.ri Defines the signature for the Complex.ri constructor, which takes two double arguments: 'real' and 'imaginary'. This is the primary way to instantiate a Complex number with specific real and imaginary parts. ```APIDOC Complex.ri(double real, double imaginary) - Initializes a Complex number. - Parameters: - real: The real part of the complex number (a double). - imaginary: The imaginary part of the complex number (a double). ``` -------------------------------- ### accToDistPro: Convert Acceleration to Displacement (Dart) Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/accToDistPro Converts acceleration data to displacement using FFT. This method takes a list of acceleration samples, sampling frequency, minimum frequency, and maximum frequency as input. It performs FFT, integrates the frequency domain data twice, and then performs an inverse FFT to obtain the displacement signal. Dependencies include realFFT, dataIntegralFreqOneComplex, and inverseFft functions. ```APIDOC accToDistPro static method [List](https://api.flutter.dev/flutter/dart-core/List-class.html)<[double](https://api.flutter.dev/flutter/dart-core/double-class.html)> accToDistPro( 1. [List](https://api.flutter.dev/flutter/dart-core/List-class.html)<[double](https://api.flutter.dev/flutter/dart-core/double-class.html)> wave, 2. [double](https://api.flutter.dev/flutter/dart-core/double-class.html) fs, 3. [double](https://api.flutter.dev/flutter/dart-core/double-class.html) fMin, 4. [double](https://api.flutter.dev/flutter/dart-core/double-class.html) fMax, ) Parameters: - wave: A List of double representing the input acceleration signal. - fs: The sampling frequency of the signal. - fMin: The minimum frequency for processing. - fMax: The maximum frequency for processing. Returns: A List of double representing the calculated displacement signal. ``` ```dart static List accToDistPro( List wave, double fs, double fMin, double fMax) { // var list = realToComplex(wave); var list = realFFT(wave); var res = dataIntegralFreqOneComplex(list.toList(), fs, fMin, (fMax * 2.56) / 2); res = dataIntegralFreqOneComplex(res.toList(), fs, fMin, (fMax * 2.56) / 2); var outData = inverseFft(res); return outData; } ``` -------------------------------- ### reverseBits Function Signature (Dart API) Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/reverseBits API documentation for the reverseBits function, specifying its parameters and return type. It takes an integer value and its bit width. ```APIDOC reverseBits(int val, int width) Parameters: val: The integer value whose bits are to be reversed. width: The number of bits to consider for reversal. Returns: The integer with reversed bits. ``` -------------------------------- ### dsp.inverseTransform Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Performs an inverse transformation on real and imaginary components. ```APIDOC inverseTransform(List real, List imag) -> void - Performs an inverse transformation. - Parameters: - real: Real parts of the input data. - imag: Imaginary parts of the input data. - Returns: void ``` -------------------------------- ### Complex Class API Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex/imaginary API documentation for the Complex class, detailing its properties and related data types. ```APIDOC Complex class: imaginary property - Description: Represents the imaginary part of a complex number. - Type: double - Declaration: final double imaginary; Related types: - double: The data type used for the imaginary property. ``` -------------------------------- ### Dart: Pad Array with Zeros to Power of 2 Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/padArrayWithZeros The `padArrayWithZeros` static method in Dart takes a list of doubles and pads it with zeros to the nearest power of 2. It's useful for signal processing algorithms that require input array sizes to be powers of two. The method returns the original list if its length is already a power of two. ```Dart static List padArrayWithZeros(List data) { var dataLength = data.length; if (isPowerOf2(dataLength)) { return data; } int nY = (math.log(dataLength) / math.log(2.0)).ceil(); int userDataLength = math.pow(2, nY).floor(); var userData = List.filled(userDataLength, 0); for (var i = 0; i < dataLength; i++) { userData[i] = data[i]; } return userData; } ``` -------------------------------- ### Dart: accToDistPro - Advanced Acceleration to Distance Conversion Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Performs an advanced conversion of an acceleration signal to a distance signal, likely with more sophisticated processing or parameters. Requires signal, sampling frequency, and frequency range. ```APIDOC accToDistPro(List wave, double fs, double fMin, double fMax) -> List Performs a professional or advanced conversion of acceleration data to distance data. Parameters: wave: The input acceleration signal (list of doubles). fs: The sampling frequency of the signal. fMin: The minimum frequency for filtering. fMax: The maximum frequency for filtering. Returns: The processed distance signal (list of doubles). ``` -------------------------------- ### dataIntegralFreqOne Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing Calculates the integral of real-valued data within a specified frequency range. It takes time-domain data, sampling frequency, and frequency bounds as input. ```APIDOC dataIntegralFreqOne(List data, double fs, double lowerFreq, double upperFreq) -> List Parameters: data: The input time-series data (List of doubles). fs: The sampling frequency of the data (double). lowerFreq: The lower bound of the frequency range for integration (double). upperFreq: The upper bound of the frequency range for integration (double). Returns: A List of double values representing the integrated frequency components. ``` -------------------------------- ### dsp.transformBluestein Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Performs a Fast Fourier Transform (FFT) using the Bluestein's algorithm. ```APIDOC transformBluestein(List real, List imag) -> void - Performs FFT using Bluestein's algorithm. - Parameters: - real: Real parts of the input data. - imag: Imaginary parts of the input data. - Returns: void ``` -------------------------------- ### dsp.transformRadix2 Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Performs a Fast Fourier Transform (FFT) using the Radix-2 Cooley-Tukey algorithm. ```APIDOC transformRadix2(List real, List imag) -> void - Performs FFT using Radix-2 algorithm. - Parameters: - real: Real parts of the input data. - imag: Imaginary parts of the input data. - Returns: void ``` -------------------------------- ### dsp.inverseFft Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Computes the inverse Fast Fourier Transform (FFT) of complex data. ```APIDOC inverseFft(List data) -> List - Computes the inverse Fast Fourier Transform (FFT). - Parameters: - data: A list of Complex numbers representing the frequency domain data. - Returns: A list of doubles representing the time-domain signal. ``` -------------------------------- ### dsp.reverseBits Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Reverses the bits of an integer up to a specified width. ```APIDOC reverseBits(int val, int width) -> int - Reverses the bits of an integer. - Parameters: - val: The integer value whose bits are to be reversed. - width: The number of bits to consider for reversal. - Returns: The integer with its bits reversed. ``` -------------------------------- ### Complex.ri Constructor Implementation Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex/Complex.ri Provides the Dart implementation for the Complex.ri constructor. It assigns the provided 'real' and 'imaginary' values to the instance variables of the Complex object. ```dart Complex.ri(this.real, this.imaginary); ``` -------------------------------- ### Dart: fftCalc - Fast Fourier Transform Calculation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Computes the Fast Fourier Transform (FFT) of a data signal. Supports optional mean removal and zero-padding for improved FFT performance and accuracy. ```APIDOC fftCalc(List data, {bool removeMean = true, bool paddingWithZeros = true}) -> List Calculates the Fast Fourier Transform (FFT) of the input data. Parameters: data: The input signal data (list of doubles). removeMean: Whether to remove the mean from the data before FFT (default: true). paddingWithZeros: Whether to pad the data with zeros to the next power of two (default: true). Returns: The frequency-domain representation of the signal (list of doubles). ``` -------------------------------- ### Dart: accToVel - Acceleration to Velocity Conversion Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Converts an acceleration signal to a velocity signal. This process typically involves integration and filtering. Requires the input signal, sampling frequency, and frequency range. ```APIDOC accToVel(List wave, double fs, double fMin, double fMax) -> List Converts acceleration data to velocity data. Parameters: wave: The input acceleration signal (list of doubles). fs: The sampling frequency of the signal. fMin: The minimum frequency for filtering. fMax: The maximum frequency for filtering. Returns: The processed velocity signal (list of doubles). ``` -------------------------------- ### Complex Constructor Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex/Complex Initializes a Complex number with optional real and imaginary components. Defaults to 0 for both if not specified. ```dart Complex({ double real = 0, double imaginary = 0, }); ``` ```APIDOC Complex constructor Initializes a Complex number. Parameters: - real: The real part of the complex number. Defaults to 0. - imaginary: The imaginary part of the complex number. Defaults to 0. Example: Complex c1 = Complex(); // Creates Complex(real: 0, imaginary: 0) Complex c2 = Complex(real: 5.0, imaginary: 3.0); // Creates Complex(real: 5.0, imaginary: 3.0) ``` -------------------------------- ### getWaveDataXInterval Static Method Implementation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/getWaveDataXInterval Calculates the time interval between samples in milliseconds based on the sampling frequency. ```dart static double getWaveDataXInterval(double fs) { return 1 / fs * 1000; } ``` -------------------------------- ### Dart: accToDist - Acceleration to Distance Conversion Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Converts an acceleration signal to a distance signal. Requires the input signal, sampling frequency, and frequency range for filtering. ```APIDOC accToDist(List wave, double fs, double fMin, double fMax) -> List Converts acceleration data to distance data. Parameters: wave: The input acceleration signal (list of doubles). fs: The sampling frequency of the signal. fMin: The minimum frequency for filtering. fMax: The maximum frequency for filtering. Returns: The processed distance signal (list of doubles). ``` -------------------------------- ### dataIntegralFreqOneComplex Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/flutter_signal_processing Computes the integral of complex-valued frequency-domain data within a specified frequency range. It returns a list of Complex numbers. ```APIDOC dataIntegralFreqOneComplex(List fx, double fs, double lowerFreq, double upperFreq) → List - Calculates the integral of complex frequency-domain data within a specified frequency band. - Parameters: - fx: The input frequency-domain data (list of Complex numbers). - fs: The sampling frequency (double). - lowerFreq: The lower bound of the frequency range for integration (double). - upperFreq: The upper bound of the frequency range for integration (double). - Returns: A list of Complex numbers representing the integrated signal in the specified frequency band. ``` -------------------------------- ### dataIntegralFreqOne Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/flutter_signal_processing Calculates the integral of data within a specified frequency range. It processes real-valued data and returns a list of doubles representing the integrated values. ```APIDOC dataIntegralFreqOne(List data, double fs, double lowerFreq, double upperFreq) → List - Calculates the integral of the signal within the specified frequency band. - Parameters: - data: The input time-domain signal data (list of doubles). - fs: The sampling frequency of the signal (double). - lowerFreq: The lower bound of the frequency range for integration (double). - upperFreq: The upper bound of the frequency range for integration (double). - Returns: A list of doubles representing the integrated signal in the specified frequency band. ``` -------------------------------- ### realToComplex Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/flutter_signal_processing Converts a list of real numbers (doubles) into a list of complex numbers. This is useful for preparing real-valued data for complex signal processing operations. ```APIDOC realToComplex(List data) → List - Converts a list of real numbers into a list of complex numbers. - Parameters: - data: The input list of real numbers (doubles). - Returns: A list of Complex numbers, where the imaginary part is zero for each input real number. ``` -------------------------------- ### reverseBits Function Implementation (Dart) Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/reverseBits Provides the Dart implementation for the reverseBits function. This function takes an integer `val` and its `width` and returns the integer with its bits reversed. ```dart int reverseBits(int val, int width) { int result = 0; for (var i = 0; i < width; i++) { result = (result << 1) | (val & 1); val >>>= 1; } return result; } ``` -------------------------------- ### newArrayOfZeros Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/newArrayOfZeros Creates a new list of doubles filled with zeros. This function is useful for initializing arrays or buffers with a default zero value. ```APIDOC List newArrayOfZeros(int n) Parameters: - n: The desired number of elements in the list (int). Returns: - A List of size 'n' with all elements initialized to 0.0. ``` ```dart List newArrayOfZeros(int n) { return List.filled(n, 0); } ``` -------------------------------- ### realToComplex Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing Converts a list of real numbers into a list of complex numbers. Typically, the imaginary part of the resulting complex numbers will be zero. ```APIDOC realToComplex(List data) -> List Parameters: data: The input list of real numbers (List of doubles). Returns: A List of Complex objects, where each object corresponds to a real number with a zero imaginary part. ``` -------------------------------- ### Dart: padArrayWithZeros - Pad Array with Zeros Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Pads a list of doubles with zeros at the end. This is often used in signal processing, particularly before FFT, to achieve a specific data length or power of two. ```APIDOC padArrayWithZeros(List data) -> List Pads the input list of doubles with zeros. Parameters: data: The list of doubles to pad. Returns: The padded list of doubles. ``` -------------------------------- ### dsp.convolveComplex Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp Performs complex convolution between two signals. It takes the real and imaginary parts of two input signals and writes the result to output lists. ```APIDOC convolveComplex(List xreal, List ximag, List yreal, List yimag, List outreal, List outimag) -> void - Performs complex convolution. - Parameters: - xreal: Real part of the first input signal. - ximag: Imaginary part of the first input signal. - yreal: Real part of the second input signal. - yimag: Imaginary part of the second input signal. - outreal: Output list for the real part of the result. - outimag: Output list for the imaginary part of the result. - Returns: void (modifies output lists) ``` -------------------------------- ### Dart transform function for signal processing Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/transform The `transform` function in Dart processes real and imaginary signal components. It validates input list lengths, handles empty inputs, and selects an appropriate transform algorithm (Radix-2 or Bluestein) based on the signal size. It includes error handling for mismatched input lengths. ```dart void transform(List real, List imag) { var n = real.length; if (n != imag.length) throw new RangeError("实部虚部长度不匹配"); if (n == 0) return; else if ((n & (n - 1)) == 0) transformRadix2(real, imag); else transformBluestein(real, imag); } ``` -------------------------------- ### Dart: getWaveDataXInterval - Waveform Data X-Axis Interval Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Calculates the time interval between samples for waveform data, based on the sampling frequency. Essential for time-domain analysis. ```APIDOC getWaveDataXInterval(double fs) -> double Calculates the time interval (sampling period) between data points in a waveform. Parameters: fs: The sampling frequency of the signal. Returns: The time interval in seconds. ``` -------------------------------- ### realFFT Function (Dart) Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/realFFT Provides the implementation and signature for the realFFT function in the flutter_signal_processing package. This function computes the Fast Fourier Transform for real-valued input data, returning a list of Complex numbers. ```APIDOC realFFT(List data) -> List Parameters: data: A list of double-precision floating-point numbers representing the real-valued input signal. Returns: A list of Complex numbers representing the FFT result. ``` ```dart List realFFT(List data) { var real = data.toList(); var imag = List.filled(data.length, 0); transform(real, imag); List res = []; for (int i = 0; i < real.length; i++) { res.add(Complex.ri(real[i], imag[i])); } return res; } ``` -------------------------------- ### Dart: getSpecDataXInterval - Spectral Data X-Axis Interval Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing-class Calculates the interval or resolution on the x-axis for spectral data, given the data and sampling frequency. Useful for interpreting FFT results. ```APIDOC getSpecDataXInterval(List data, double fs) -> double Calculates the frequency resolution (interval) for spectral data. Parameters: data: The spectral data (e.g., FFT output). fs: The sampling frequency of the original signal. Returns: The frequency interval (resolution) in Hz. ``` -------------------------------- ### Complex.div Method (Dart) Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/Complex/div Performs division of two complex numbers. This method is part of the Complex class in the flutter_signal_processing package. It handles division by zero and optimizes calculations based on the magnitude of the real and imaginary parts of the divisor. ```Dart Complex div(Complex b1) { var a = real; var b = imaginary; var c = b1.real; var d = b1.imaginary; var t, x; if (0 == d) { return Complex(real: a / c, imaginary: b / c); } if (c.abs() < d.abs()) { x = c / d; t = c * x + d; return Complex(real: (a * x + b) / t, imaginary: (b * x - a) / t); } else { x = d / c; t = d * x + c; return Complex(real: (a + b * x) / t, imaginary: (b - a * x) / t); } } ``` -------------------------------- ### isPowerOf2 Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing Checks if a given integer is a power of 2. This is a utility function for various signal processing algorithms. ```APIDOC isPowerOf2(int n) -> bool Parameters: n: The integer to check (int). Returns: True if n is a power of 2, false otherwise (bool). ``` -------------------------------- ### Inverse Fast Fourier Transform (inverseFft) Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/inverseFft Calculates the inverse Fast Fourier Transform (iFFT) of a list of complex numbers. It takes a list of Complex objects as input and returns a list of doubles representing the time-domain signal. The function internally uses a transform helper and scales the result. ```dart List inverseFft(List data) { List real = List.filled(data.length, 0); List imag = List.filled(data.length, 0); for (int i = 0; i < data.length; i++) { real[i] = data[i].real; imag[i] = data[i].imaginary; } transform(real, imag); final len = real.length; final scale = len.toDouble(); final r = List.filled(len, 0); r[0] = real[0] / scale; if (len <= 1) return r; for (int i = 1; i < len; ++i) { r[i] = real[len - i] / scale; } return r; } ``` -------------------------------- ### dataIntegralFreqOneComplex Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing Calculates the integral of complex frequency data within a specified frequency range. This is useful for processing FFT results. It takes complex frequency data, sampling frequency, and frequency bounds. ```APIDOC dataIntegralFreqOneComplex(List fx, double fs, double lowerFreq, double upperFreq) -> List Parameters: fx: The input complex frequency data (List of Complex objects, e.g., from FFT). fs: The sampling frequency of the original data (double). lowerFreq: The lower bound of the frequency range for integration (double). upperFreq: The upper bound of the frequency range for integration (double). Returns: A List of Complex values representing the integrated frequency components. ``` -------------------------------- ### isPowerOf2 Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/flutter_signal_processing Checks if a given integer is a power of 2. This is a utility function often used in signal processing algorithms like FFT. ```APIDOC isPowerOf2(int n) → bool - Determines if an integer is a power of 2. - Parameters: - n: The integer to check (int). - Returns: True if n is a power of 2, false otherwise. ``` -------------------------------- ### Implement dataIntegralFreqOne Function in Dart Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/dataIntegralFreqOne This Dart function `dataIntegralFreqOne` processes a list of double-precision floating-point numbers representing signal data. It calculates the integral of the signal within a specified frequency range using Fast Fourier Transform (FFT) and Inverse FFT. Dependencies include `realFFT`, `inverseFft`, and the `Complex` number class, along with the `math` library. ```dart List dataIntegralFreqOne( List data, double fs, double lowerFreq, double upperFreq) { var len = data.length; var fx = realFFT(data); // Stopwatch stopwatch = Stopwatch()..start(); var df = fs / len; var dw = 2 * math.pi * df; var w = List.filled(len, 0); for (var i = 0; i < len; i++) { if (i <= len / 2 - 1) { w[i] = i == 0 ? 0 : w[i - 1] + dw; } else { w[i] = i == len / 2 ? (-len * dw) / 2 : w[i - 1] + dw; } } var fy1 = List.filled(len, Complex()); for (var i = 0; i < len; i++) { if (i == 0) { fy1[i] = Complex.ri(0, 0); } else { fy1[i] = fx[i].div(Complex.ri(0, w[i])); } } var iL = (lowerFreq / df).floor(); var iH = (upperFreq / df).ceil(); var fy2 = List.filled(len, Complex()); for (var i = 0; i < len; i++) { if (i >= iL && i <= iH) { fy2[i] = Complex.ri(fy1[i].real, fy1[i].imaginary); } else if (i >= len - iH && i <= math.min(len - 1, len - iL)) { fy2[i] = fy1[i]; } else { fy2[i] = Complex.ri(0, 0); } } // print('dataIntegralFreqOne() executed in ${stopwatch.elapsed}'); var outData = inverseFft(fy2); return outData; } ``` -------------------------------- ### Calculate Spec Data X Interval Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/getSpecDataXInterval Calculates the interval for spectral data based on the sampling frequency and the length of the input data. This method is part of the VibDataProcessing class. ```dart static double getSpecDataXInterval(List data, double fs) { return fs / 2.56 / data.length; } ``` -------------------------------- ### dataIntegralFreqOneComplex Function Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/dataIntegralFreqOneComplex Implements the dataIntegralFreqOneComplex function in Dart for signal processing. This function integrates frequency components of a complex signal within a specified frequency range. It takes a list of complex numbers (fx), sampling frequency (fs), lower frequency bound (lowerFreq), and upper frequency bound (upperFreq) as input. It returns a list of complex numbers representing the integrated signal in the frequency domain, filtered between the specified frequencies. ```dart List dataIntegralFreqOneComplex( List fx, double fs, double lowerFreq, double upperFreq) { var len = fx.length; // Stopwatch stopwatch = Stopwatch()..start(); var df = fs / len; var dw = 2 * math.pi * df; var w = List.filled(len, 0); for (var i = 0; i < len; i++) { if (i <= len / 2 - 1) { w[i] = i == 0 ? 0 : w[i - 1] + dw; } else { w[i] = i == len / 2 ? (-len * dw) / 2 : w[i - 1] + dw; } } var fy1 = List.filled(len, Complex()); for (var i = 0; i < len; i++) { if (i == 0) { fy1[i] = Complex.ri(0, 0); } else { fy1[i] = fx[i].div(Complex.ri(0, w[i])); } } var iL = (lowerFreq / df).floor(); var iH = (upperFreq / df).ceil(); var fy2 = List.filled(len, Complex()); for (var i = 0; i < len; i++) { if (i >= iL && i <= iH) { fy2[i] = Complex.ri(fy1[i].real, fy1[i].imaginary); } else if (i >= len - iH && i <= math.min(len - 1, len - iL)) { fy2[i] = fy1[i]; } else { fy2[i] = Complex.ri(0, 0); } } // print('dataIntegralFreqOne() executed in ${stopwatch.elapsed}'); var outData = fy2; return outData; } ``` -------------------------------- ### realToComplex Function Implementation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/realToComplex Converts a list of real numbers (doubles) into a list of Complex numbers, where the imaginary part is set to zero. This function is part of the vibdata_processing library. ```APIDOC realToComplex Converts a list of real numbers to a list of Complex numbers. Signature: List realToComplex(List data) Parameters: - data: A List of double representing the real number input. Returns: A List of Complex objects, where each element corresponds to an input real number with an imaginary part of 0. Example: List realData = [1.0, 2.5, 3.0]; List complexData = realToComplex(realData); // complexData will be [Complex.ri(1.0, 0), Complex.ri(2.5, 0), Complex.ri(3.0, 0)] ``` ```dart List realToComplex(List data) { var fy1 = List.filled(data.length, Complex()); for (var i = 0; i < data.length; i++) { fy1[i] = Complex.ri(data[i], 0); } return fy1; } ``` -------------------------------- ### Implement transformBluestein function in Dart Source: https://pub.dev/documentation/flutter_signal_processing/latest/dsp/transformBluestein This Dart function `transformBluestein` computes the Discrete Fourier Transform (DFT) using Bluestein's algorithm. It takes lists of doubles for the real and imaginary parts of the input signal. It requires helper functions like `newArrayOfZeros` and `convolveComplex`, and utilizes the `math` library. An error is thrown if the input real and imaginary lists have different lengths ('实部虚部长度不匹配' - real and imaginary parts length mismatch). ```dart void transformBluestein(List real, List imag) { var n = real.length; if (n != imag.length) throw new RangeError("实部虚部长度不匹配"); var m = 1; while (m < n * 2 + 1) m *= 2; var cosTable = List.filled(n, 0); var sinTable = List.filled(n, 0); for (var i = 0; i < n; i++) { var j = (i * i) % (n * 2); cosTable[i] = math.cos((math.pi * j) / n); sinTable[i] = math.sin((math.pi * j) / n); } var areal = newArrayOfZeros(m); var aimag = newArrayOfZeros(m); for (var i = 0; i < n; i++) { areal[i] = real[i] * cosTable[i] + imag[i] * sinTable[i]; aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i]; } var breal = newArrayOfZeros(m); var bimag = newArrayOfZeros(m); breal[0] = cosTable[0]; bimag[0] = sinTable[0]; for (var i = 1; i < n; i++) { breal[i] = breal[m - i] = cosTable[i]; bimag[i] = bimag[m - i] = sinTable[i]; } var creal = List.filled(m, 0); var cimag = List.filled(m, 0); convolveComplex(areal, aimag, breal, bimag, creal, cimag); for (var i = 0; i < n; i++) { real[i] = creal[i] * cosTable[i] + cimag[i] * sinTable[i]; imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i]; } } ``` -------------------------------- ### Dart removeArrayMean static method implementation Source: https://pub.dev/documentation/flutter_signal_processing/latest/vibdata_processing/VibDataProcessing/removeArrayMean Provides the implementation for the static `removeArrayMean` method in Dart. This method calculates the average of a list of double values and returns a new list with the mean subtracted from each element. ```dart static List removeArrayMean(List data) { double total = 0; for (var element in data) { total += element; } var avg = total / data.length; return data.map((e) { return e - avg; }).toList(); } ```