SpectrumLib 1.0.1

dotnet add package SpectrumLib --version 1.0.1
NuGet\Install-Package SpectrumLib -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpectrumLib" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpectrumLib --version 1.0.1
#r "nuget: SpectrumLib, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SpectrumLib as a Cake Addin
#addin nuget:?package=SpectrumLib&version=1.0.1

// Install SpectrumLib as a Cake Tool
#tool nuget:?package=SpectrumLib&version=1.0.1

Mathematical library for calculating the signal spectrum

The main functionality is the calculation of raw spectrum values and the calculation of EEG spectrum values. Working with the library is possible in iterative mode (adding new data to the internal buffer, calculating spectrum values) and in one-time spectrum calculation mode for a given array. When working in the iterative mode, the spectrum is calculated with the frequency set during initialization.

Initialization

Main parameters

  1. Raw signal sampling frequency.
  2. Spectrum calculation frequency. int process_win_rate = 5;
  3. Spectrum calculation window length.

Optional parameters

  1. Upper bound of frequencies for spectrum calculation. Default value is sampling_rate / 2.
  2. Normalization of the EEG spectrum by the width of the wavebands. Disabled by default.
  3. Weight coefficients for alpha, beta, theta, gamma, delta waves. By default has 1.0 value.

Creation

int samplingRate = 250; // raw signal sampling frequency
int fftWindow = 1000; // spectrum calculation window length
int processWinRate = 5; // spectrum calculation frequency
SpectrumMath math = new SpectrumMath(samplingRate, fftWindow, processWinRate);

Optional initialization

  1. Additional spectrum settings:
int bordFrequency = 50; // upper bound of frequencies for spectrum calculation
bool normalizeSpectByBandwidth = true; // normalization of the EEG spectrum by the width of the wavebands
math.InitParams(bordFrequency, normalizeSpectByBandwidth);
  1. Waves coefficients:
double alphaCoef = 1.0;
double betaCoef  = 1.0;
double deltaCoef = 0.0;
double gammaCoef = 0.0;
double thetaCoef = 1.0;
math.SetWavesCoeffs(deltaCoef, thetaCoef, alphaCoef, betaCoef, gammaCoef);
  1. Setting the smoothing of the spectrum calculation by Henning (by default) or Hemming window:
math.SetHanningWinSpect(); // by Hanning (by default)

math.SetHammingWinSpect(); // by Hamming

Initializing a data array for transfer to the library

Array of double values with any length.

Types

RawSpectrumData

Structure containing the raw spectrum values (with boundary frequency taken into library).

Fields:

  • all_bins_nums - Integer value. Number of FFT bars. Contained only in the C++ interface.
  • all_bins_values - Double array. Raw FFT bars values.
  • total_raw_pow - Double value. Total raw spectrum power.
WavesSpectrumData

Structure containing the waves values.

Absolute frequency values (double type):

  • delta_raw
  • theta_raw
  • alpha_raw
  • beta_raw
  • gamma_raw

Relative (percent) values (double type):

  • delta_rel
  • theta_rel
  • alpha_rel
  • beta_rel
  • gamma_rel

FFT band resolution

The library automatically matches the optimal buffer length (degree 2) to calculate the FFT during initialization, depending on the specified window length. Receiving resolution for the FFT bands (number of FFT bands per 1 Hz):

double fftBinsFor1Hz = math.GetFFTBinsFor1Hz();

Spectrum calculation in iterative mode

  1. Adding and process data:
double[] samples = new double[SIGNAL_SAMPLES_COUNT];
math.PushData(samples);
// data processing into PushData method
  1. Getting the results:
var rawSpectrumData   = _math.ReadRawSpectrumInfoArr();
var wavesSpectrumData = _math.ReadWavesSpectrumInfoArr();
  1. Updating the number of new samples. Is necessary for correct calculation of elements in the array of obtained structures, if a large portion of data is added to the library all at once.
math.SetNewSampleSize();

Spectrum calculation for a single array

  1. Compute spectrum:
double[] samples = new double[SIGNAL_SAMPLES_COUNT];
math.ComputeSpectrum(samples);
  1. Getting the results:
RawSpectrumData data = math.ReadRawSpectrumInfo();
WavesSpectrumData waves = math.ReadWavesSpectrumInfo();

Finishing work with the library:

math.ClearData(tSpectMathPtr);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid is compatible. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 is compatible. 
Xamarin.iOS xamarinios was computed.  xamarinios10 is compatible. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • MonoAndroid 0.0

    • No dependencies.
  • UAP 10.0

    • No dependencies.
  • Xamarin.iOS 1.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 180 7/4/2023