### Apply Filter to All Channels Example Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/fn.apply_filter_to_all_channels.html Demonstrates initializing filter configuration and applying it to raw EEG data. ```rust let raw_data = load_csv("eeg.csv", 256.0, Some(0), Some(5), true).expect("Failed to load CSV"); let config = FilterConfig::new(FilterType::Notch, 50.0, 30.0, 256.0, None) .expect("Failed to create filter configuration"); let filtered_data = apply_filter_to_all_channels(&raw_data, &config) .expect("Filtering channels failed"); ``` -------------------------------- ### Apply a low-pass filter to a sine wave signal Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/fn.apply_filter.html Demonstrates generating a synthetic sine wave and applying a low-pass filter configuration to it. ```rust // Generate a simple sine wave at 10 Hz for a duration of 1 second (sampling rate: 256 Hz) let sample_rate = 256.0; let freq = 10.0; let duration = 1.0; let num_samples = (duration * sample_rate) as usize; let input: Vec = (0..num_samples) .map(|i| (2.0 * std::f64::consts::PI * freq * i as f64 / sample_rate).sin()) .collect(); // Create a low-pass filter with cutoff at 15 Hz let config = FilterConfig::new(FilterType::LowPass, 15.0, 0.707, sample_rate, None) .expect("Failed to create filter configuration"); let output = apply_filter(&input, &config).expect("Filtering failed"); assert_eq!(output.len(), input.len()); ``` -------------------------------- ### Define PsdResult Struct Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/struct.PsdResult.html The structure definition for storing power spectral density data. ```rust pub struct PsdResult { pub frequencies: Vec, pub psd: Vec, pub sampling_rate: f64, } ``` -------------------------------- ### apply_window Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/index.html Applies a specified window function to a signal. ```APIDOC ## apply_window ### Description Applies a window function to the signal. ### Signature `pub fn apply_window(signal: &[f64], window_type: WindowType) -> Vec` ``` -------------------------------- ### load_csv Source: https://docs.rs/rustneuro/0.2.21/rustneuro/io/index.html Loads an EEG dataset from a CSV file. ```APIDOC ## load_csv ### Description Loads an EEG dataset from a CSV file. ### Signature `pub fn load_csv(path: &Path) -> Result` ``` -------------------------------- ### FilterConfig::new Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/struct.FilterConfig.html Creates a new instance of FilterConfig with the specified parameters. Validates that the sampling rate and Q factor are positive, the cutoff frequency is below the Nyquist limit, and that gain is provided for Peak filters. ```APIDOC ## FilterConfig::new ### Description Creates a new FilterConfig instance. This constructor validates input parameters to ensure they are within valid ranges for signal processing. ### Signature `pub fn new(filter_type: FilterType, cutoff: f64, q: f64, sample_rate: f64, gain: Option) -> Result` ### Parameters - **filter_type** (FilterType) - Required - The type of filter to configure. - **cutoff** (f64) - Required - The cutoff frequency for the filter. - **q** (f64) - Required - The Q factor of the filter. - **sample_rate** (f64) - Required - The sampling rate of the signal. - **gain** (Option) - Optional - The gain in dB, required for Peak filters. ### Errors - Returns an error if the sampling rate or Q factor are not positive. - Returns an error if the cutoff frequency is not below the Nyquist limit. - Returns an error if gain is not provided for Peak filters. ``` -------------------------------- ### compute_psd function signature Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/fn.compute_psd.html The function signature for computing power spectral density using Welch's method. ```rust pub fn compute_psd( signal: &[f64], sampling_rate: f64, segment_length: usize, overlap: f64, window_type: WindowType, ) -> Result ``` -------------------------------- ### Define ArtifactDetectionParams Struct Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/struct.ArtifactDetectionParams.html The structure definition for artifact detection configuration. ```rust pub struct ArtifactDetectionParams { pub amplitude_threshold: f64, pub gradient_threshold: Option, pub window_size: usize, pub min_artifact_duration: usize, } ``` -------------------------------- ### Define EventMarker Struct Source: https://docs.rs/rustneuro/0.2.21/rustneuro/data/struct.EventMarker.html The structure definition for EventMarker, containing a time field as a 64-bit float and a label as a String. ```rust pub struct EventMarker { pub time: f64, pub label: String, } ``` -------------------------------- ### ArtifactDetectionParams::new Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/struct.ArtifactDetectionParams.html Creates a new instance of ArtifactDetectionParams with validation. ```APIDOC ## ArtifactDetectionParams::new ### Description Creates new artifact detection parameters with validation. ### Signature `pub fn new(amplitude_threshold: f64, gradient_threshold: Option, window_size: usize, min_artifact_duration: usize) -> Result` ### Parameters - **amplitude_threshold** (f64) - Threshold for detecting amplitude artifacts (in microvolts) - **gradient_threshold** (Option) - Optional threshold for detecting gradient artifacts (in microvolts/sample) - **window_size** (usize) - Window size for moving averages (in samples) - **min_artifact_duration** (usize) - Minimum duration to consider as an artifact (in samples) ### Returns - **Result** - Validated artifact detection parameters or an error if parameters are invalid. ``` -------------------------------- ### Load EEG data from CSV Source: https://docs.rs/rustneuro/0.2.21/rustneuro/io/fn.load_csv.html Basic usage of load_csv to import data from a file with a specified sampling rate and header configuration. ```rust use rustneuro::io::load_csv; let data = load_csv("test.csv", 256.0, None, None, true) .expect("Failed to load CSV"); // Assuming the CSV has 8 channels if no time or event columns are provided. assert_eq!(data.channels.len(), 8); ``` -------------------------------- ### compute_psd_for_all_channels function signature Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/fn.compute_psd_for_all_channels.html The function signature for computing PSD across all EEG channels. ```rust pub fn compute_psd_for_all_channels( eeg_data: &EEGData, segment_length: usize, overlap: f64, window_type: WindowType, ) -> Result, EEGError> ``` -------------------------------- ### compute_psd Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/index.html Computes the power spectral density of a signal using Welch’s method. ```APIDOC ## compute_psd ### Description Computes the power spectral density of a signal using Welch’s method. ### Signature `pub fn compute_psd(signal: &[f64], fs: f64) -> PsdResult` ``` -------------------------------- ### pub fn apply_filter Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/fn.apply_filter.html Applies the specified filter to a single-channel input signal. ```APIDOC ## Function: apply_filter ### Description Applies the specified filter to a single-channel input signal. ### Signature `pub fn apply_filter(input: &[f64], config: &FilterConfig) -> Result, EEGError>` ### Parameters - **input** (&[f64]) - Required - Slice of f64 representing the raw signal. - **config** (&FilterConfig) - Required - Filter configuration parameters. ### Returns - **Result, EEGError>** - A vector of f64 containing the filtered signal or an EEGError if the operation fails. ### Example ```rust let sample_rate = 256.0; let freq = 10.0; let duration = 1.0; let num_samples = (duration * sample_rate) as usize; let input: Vec = (0..num_samples) .map(|i| (2.0 * std::f64::consts::PI * freq * i as f64 / sample_rate).sin()) .collect(); let config = FilterConfig::new(FilterType::LowPass, 15.0, 0.707, sample_rate, None) .expect("Failed to create filter configuration"); let output = apply_filter(&input, &config).expect("Filtering failed"); assert_eq!(output.len(), input.len()); ``` ``` -------------------------------- ### apply_filter Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/index.html Applies a specified filter to a single-channel input signal. ```APIDOC ## apply_filter ### Description Applies the specified filter to a single-channel input signal. ### Signature `pub fn apply_filter(signal: &[f64], config: &FilterConfig) -> Vec` ``` -------------------------------- ### detect_artifacts Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/index.html Detects artifacts in EEG data based on amplitude and gradient thresholds. ```APIDOC ## detect_artifacts ### Description Detects artifacts in EEG data based on amplitude and gradient thresholds. ### Signature `pub fn detect_artifacts(data: &[f64], params: &ArtifactDetectionParams) -> Vec` ``` -------------------------------- ### WindowType Enum Definition Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/enum.WindowType.html The definition of the WindowType enum, specifying the available windowing functions and their parameters. ```rust pub enum WindowType { Rectangular, Hann, Hamming, Blackman, Tukey(f64), } ``` -------------------------------- ### Define ArtifactSegment struct Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/struct.ArtifactSegment.html The core data structure representing a detected artifact segment. ```rust pub struct ArtifactSegment { pub channel_index: usize, pub channel_name: String, pub start_index: usize, pub end_index: usize, pub reason: String, } ``` -------------------------------- ### detect_artifacts function signature Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/fn.detect_artifacts.html The function signature for detecting artifacts in EEG data, requiring EEGData and ArtifactDetectionParams. ```rust pub fn detect_artifacts( eeg_data: &EEGData, params: &ArtifactDetectionParams, ) -> Result, EEGError> ``` -------------------------------- ### EEGBands Struct Definition Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/struct.EEGBands.html Defines the structure for storing power values in standard EEG frequency bands. ```rust pub struct EEGBands { pub delta: f64, pub theta: f64, pub alpha: f64, pub beta: f64, pub gamma: f64, } ``` -------------------------------- ### EEGData Struct Definition Source: https://docs.rs/rustneuro/0.2.21/rustneuro/data/struct.EEGData.html The structure definition for EEGData, containing fields for timestamps, channels, events, and sampling rate. ```rust pub struct EEGData { pub timestamps: Option>, pub channels: Vec, pub events: Option>, pub sampling_rate: f64, } ``` -------------------------------- ### get_power_at_frequency Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/struct.PsdResult.html Returns the power value at the specified frequency. ```APIDOC ### pub fn get_power_at_frequency(&self, freq: f64) -> f64 Returns the power at the specified frequency. ``` -------------------------------- ### apply_filter_to_all_channels Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/index.html Applies the filter specified by config to all channels in the provided EEGData. ```APIDOC ## apply_filter_to_all_channels ### Description Applies the filter specified by `config` to all channels in the provided EEGData, returning a new EEGData with filtered signals. ### Signature `pub fn apply_filter_to_all_channels(data: &EEGData, config: &FilterConfig) -> EEGData` ``` -------------------------------- ### compute_psd_for_all_channels Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/index.html Computes the power spectral density for all channels within an EEGData structure. ```APIDOC ## compute_psd_for_all_channels ### Description Computes the power spectral density for all channels in an EEGData struct. ### Signature `pub fn compute_psd_for_all_channels(data: &EEGData) -> Vec` ``` -------------------------------- ### compute_coherence Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/index.html Computes the coherence between two input signals. ```APIDOC ## compute_coherence ### Description Computes coherence between two signals. ### Signature `pub fn compute_coherence(signal_a: &[f64], signal_b: &[f64]) -> Vec` ``` -------------------------------- ### get_band_power Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/struct.PsdResult.html Calculates the total power within a specified frequency band. ```APIDOC ### pub fn get_band_power(&self, low_freq: f64, high_freq: f64) -> f64 Returns the total power in the specified frequency band. ``` -------------------------------- ### get_eeg_bands Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/struct.PsdResult.html Retrieves common EEG band powers from the PSD result. ```APIDOC ### pub fn get_eeg_bands(&self) -> EEGBands Returns common EEG band powers. ``` -------------------------------- ### remove_artifacts function signature Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/fn.remove_artifacts.html The function signature for removing artifacts from EEG data, requiring the input data, artifact segments, and an interpolation method. ```rust pub fn remove_artifacts( eeg_data: &EEGData, artifacts: &[ArtifactSegment], interpolation_method: InterpolationMethod, ) -> Result ``` -------------------------------- ### Define EEGChannel struct Source: https://docs.rs/rustneuro/0.2.21/rustneuro/data/struct.EEGChannel.html The structure definition for an EEG channel, containing the channel name and its associated time-series data. ```rust pub struct EEGChannel { pub name: String, pub data: Vec, } ``` -------------------------------- ### compute_coherence function signature Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/fn.compute_coherence.html The function signature for computing coherence between two signals, requiring sampling rate, segment length, overlap, and window type. ```rust pub fn compute_coherence( signal1: &[f64], signal2: &[f64], sampling_rate: f64, segment_length: usize, overlap: f64, window_type: WindowType, ) -> Result ``` -------------------------------- ### InterpolationMethod Enum Definition Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/enum.InterpolationMethod.html Defines the available methods for interpolating artifact segments in the rustneuro library. ```rust pub enum InterpolationMethod { Linear, Constant(f64), PreviousValue, Mean, } ``` -------------------------------- ### get_frequency_index Source: https://docs.rs/rustneuro/0.2.21/rustneuro/spectral/struct.PsdResult.html Returns the index corresponding to the closest frequency in the PSD result. ```APIDOC ### pub fn get_frequency_index(&self, freq: f64) -> usize Returns the index corresponding to the closest frequency. ``` -------------------------------- ### remove_artifacts Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/fn.remove_artifacts.html Removes artifacts from EEG data by replacing them with interpolated values. ```APIDOC ## Function: remove_artifacts ### Description Removes artifacts from EEG data by replacing them with interpolated values. ### Signature `pub fn remove_artifacts(eeg_data: &EEGData, artifacts: &[ArtifactSegment], interpolation_method: InterpolationMethod) -> Result` ### Parameters - **eeg_data** (&EEGData) - The EEG data to process - **artifacts** (&[ArtifactSegment]) - Detected artifact segments - **interpolation_method** (InterpolationMethod) - Method to use for interpolation ### Returns - **Result** - A new EEGData with artifacts removed/interpolated, or an error if interpolation fails. ``` -------------------------------- ### remove_artifacts Source: https://docs.rs/rustneuro/0.2.21/rustneuro/artifacts/index.html Removes artifacts from EEG data by replacing them with interpolated values. ```APIDOC ## remove_artifacts ### Description Removes artifacts from EEG data by replacing them with interpolated values. ### Signature `pub fn remove_artifacts(data: &mut [f64], segments: &[ArtifactSegment], method: InterpolationMethod)` ``` -------------------------------- ### Define EEGError Enum Source: https://docs.rs/rustneuro/0.2.21/rustneuro/errors/enum.EEGError.html The structure of the EEGError enum, which categorizes different types of errors encountered during processing. ```rust pub enum EEGError { Io(String), Csv(Error), Parse(String), Validation(String), Filter(String), } ``` -------------------------------- ### Define FilterType Enum Source: https://docs.rs/rustneuro/0.2.21/rustneuro/filter/enum.FilterType.html The FilterType enum structure used to specify the type of filter to be applied. ```rust pub enum FilterType { LowPass, HighPass, BandPass, Notch, BandStop, Peak, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.