Main Content

signalTimeFeatureExtractor

Streamline signal time feature extraction

    Description

    Use signalTimeFeatureExtractor to extract time-domain features from a signal. You can use the extracted features to train a machine learning model or a deep learning network.

    Creation

    Description

    sFE = signalTimeFeatureExtractor creates a signalTimeFeatureExtractor object with default property values.

    example

    sFE = signalTimeFeatureExtractor(Name,Value) specifies nondefault property values of the signalTimeFeatureExtractor object. For example, signalTimeFeatureExtractor(FeatureFormat="table") sets the output format of the generated features to a table.

    Properties

    expand all

    Main Properties

    Number of samples in a frame, specified as a positive integer. The object divides the signal into frames of the specified length and extracts features for each frame. If you do not specify FrameSize, or if you specify FrameSize as empty, the object extracts features for the whole signal.

    Data Types: single | double

    Number of samples between the start of frames, specified as a positive integer. The frame rate determines the distance in samples between the starting points of frames. If you specify FrameRate, then you must also specify FrameSize. If you do not specify FrameRate or FrameOverlapLength, then FrameRate is assumed to be equal to FrameSize. You cannot specify FrameRate and FrameOverlapLength simultaneously.

    Data Types: single | double

    Number of overlapping samples between consecutive frames, specified as a positive integer. FrameOverlapLength must be less than or equal to the frame size. If you specify FrameOverlapLength, then you must also specify FrameSize. You cannot specify FrameOverlapLength and FrameRate simultaneously.

    Data Types: single | double

    Input sample rate, specified as a positive scalar in hertz.

    Data Types: single | double

    Format of generated features, specified as "matrix" or "table". The extract function returns features as one of these:

    • matrix — Matrix with columns corresponding to feature values.

    • table — Table with each table variable corresponding to a feature value.

    Data Types: char | string

    Rule to handle incomplete frames, specified as "drop" or "zeropad". This rule applies when the current frame size is less than the specified FrameSize property.

    • drop — Drop the incomplete frame and do not use it to compute features.

    • zeropad — Zero-pad the incomplete frame and use it to compute features.

    Data Types: char | string

    Features to Extract

    Option to extract the mean, specified as true or false. If you specify Mean as true, the object extracts the mean and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the root mean square (RMS), specified as true or false. If you specify RMS as true, the object extracts the RMS and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the standard deviation, specified as true or false. If you specify StandardDeviation as true, the object extracts the standard deviation and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the shape factor, specified as true or false. The shape factor is equal to the RMS value divided by the mean absolute value of the signal. If you specify ShapeFactor as true, the object extracts the shape factor and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the signal-to-noise ratio (SNR), specified as true or false. If you specify SNR as true, the object extracts the SNR and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the total harmonic distortion (THD), specified as true or false. If you specify THD as true, the object extracts the THD and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the signal to noise and distortion ratio (SINAD) in decibels, specified as true or false. If you specify Sinad as true, the object extracts the SINAD and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the peak value, specified as true or false. The peak value corresponds to the maximum absolute value of the signal. If you specify PeakValue as true, the object extracts the peak and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the crest factor, specified as true or false. The crest factor is equal to the peak value divided by the RMS. If you specify CrestFactor as true, the object extracts the crest factor and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the clearance factor, specified as true or false. The clearance factor is equal to the peak value divided by the squared mean of the square roots of the absolute amplitude. If you specify ClearanceFactor as true, the object extracts the clearance factor and appends the value to the features returned by the extract function.

    Data Types: logical

    Option to extract the impulse factor, specified as true or false. The impulse factor is equal to the peak value divided by the mean of the absolute amplitude. If you specify ImpulseFactor as true, the object extracts the impulse factor and appends the value to the features returned by the extract function.

    Data Types: logical

    Object Functions

    extractExtract time-domain or frequency-domain features
    generateMATLABFunctionCreate MATLAB function compatible with C/C++ code generation

    Examples

    collapse all

    Extract time-domain features from electromyographic (EMG) data for later use in a machine learning workflow to classify forearm motions. The files are available at this location: https://ssd.mathworks.com/supportfiles/SPT/data/MyoelectricData.zip.

    This example uses EMG signals collected from the forearms of 30 subjects [1]. The data set consists of 720 files. Each subject participated in four testing sessions, and performed six trials of different forearm motions per session. Download and unzip the files into your temporary directory.

    localfile = matlab.internal.examples.downloadSupportFile('SPT','data/MyoelectricData.zip');
    datasetFolder = fullfile(tempdir,'MyoelectricData');
    unzip(localfile,datasetFolder)

    Each file contains an eight-channel EMG signal that represents the activation of eight forearm muscles during a series of motions. The sample rate is 1000 Hz. Create a signalDatastore that points to the data set folder.

    fs = 1000;
    sds = signalDatastore(datasetFolder,IncludeSubfolders=true);

    For this example, analyze only the last (sixth) trial of each session. Use the endsWith function to find the indices that correspond to these files. Create a new datastore that contains this subset of signals.

    p = endsWith(sds.Files,'6d.mat');
    sdssub = subset(sds,p);
    data = readall(sdssub);

    Create a signalTimeFeatureExtractor object to extract the mean, root mean square (RMS), and peak values from the EMG signals. Call the extract function to extract the specified features. Plot the peak values for the second and eighth EMG channels.

    sFE = signalTimeFeatureExtractor(SampleRate=fs,Mean=true,RMS=true,PeakValue=true);
    
    M = [];
    F = [];
    
    for i = 1:length(sdssub.Files)
        M{i,1} = extract(sFE,data{i});
    end
    
    for k = 1:30
        peak2 = M{k,1}(:,3,2);
        peak8 = M{k,1}(:,3,8);
        F(k,1) = peak2;
        F(k,2) = peak8;
    end
    
    bar(F)
    xlabel('Subject')
    ylabel('EMG Peak values (mV)')
    legend(['Channel 2';'Channel 8'])

    Figure contains an axes object. The axes object contains 2 objects of type bar. These objects represent Channel 2, Channel 8.

    References

    [1] Chan, Adrian D.C., and Geoffrey C. Green. 2007. "Myoelectric Control Development Toolbox." Paper presented at 30th Conference of the Canadian Medical & Biological Engineering Society, Toronto, Canada, 2007.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Introduced in R2021a