Main Content

filter

Apply filter to tireData object data channels

Since R2024a

    Description

    obj=filter(obj,Name=Value) applies a filter specified by one or more name-value arguments to the tireData object specified by obj. The function applies a zero-phase digital filter unless you specify a moving mean to filter the data using the name-value argument k. Signal Processing Toolbox™ is required for zero-phase digital filter calculations. For more information, see filtfilt (Signal Processing Toolbox).

    Note

    Data channels with NaN values are not filtered.

    example

    Examples

    collapse all

    Use the filter function to remove noise from tire measurement data. Set combinations of these name-value arguments to specify the filter design:

    • k — Moving mean, where k is the window length for local k-point mean values

    • ddigitalFilter object

    • b, a — Transfer function coefficients

    • F, Fs — Cutoff frequency and optional sampling frequency for a low-pass filter

    Unless you specify a moving mean, this example requires the Signal Processing Toolbox.

    Import and View Tire Measurement Data

    Import tire measurement data into a tireData object, td.

    td = tireData("example_data.tdx");

    Multiple Fz conditions are included in the data. Use the split function to separate the data by tire data channel Fz, resulting in four tireData objects.

    td = split(td,"Fz");

    Use the plot function to view the normal force versus the elapsed time using the normal force to assign colors and legend values.

    plot(td,DataVariableNames=["et","Fz"],ColorBy="Fz");

    Figure contains an axes object. The axes object with title Normal force [N] vs Elapsed time [s], xlabel Elapsed time [s], ylabel Normal force [N] contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent 2140, 4270, 5160, 6460.

    Specify Moving Mean

    Use a moving mean to filter the data channel Fz. Set k=10.

    tdFilter = filter(td,channels="Fz",k=10);

    Plot the resulting tireData objects in tdFilter to visualize the modified data set.

    plot(tdFilter,DataVariableNames=["et","Fz"],ColorBy="Fz");

    Figure contains an axes object. The axes object with title Normal force [N] vs Elapsed time [s], xlabel Elapsed time [s], ylabel Normal force [N] contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent 2140, 4270, 5160, 6460.

    Specify digitalFilter Object

    Use the designfilt (Signal Processing Toolbox) function to create the digitalFilter object for a second-order IIR low-pass filter with HalfPowerFrequency=0.1.

    d = designfilt("lowpassiir",FilterOrder=2,HalfPowerFrequency=0.1);

    Filter the data channel Fz using the digitalFilter object d.

    tdFilter = filter(td,channels="Fz",d=d);

    Plot the resulting tireData objects in tdFilter to visualize the modified data set.

    plot(tdFilter,DataVariableNames=["et","Fz"],ColorBy="Fz")

    Figure contains an axes object. The axes object with title Normal force [N] vs Elapsed time [s], xlabel Elapsed time [s], ylabel Normal force [N] contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent 2140, 4270, 5160, 6460.

    Specify Transfer Function Coefficients

    Generate the b and a transfer coefficients using the butter (Signal Processing Toolbox) function.

    You can use additional filter design functions can be used to generate the transfer function coefficients. For more information, see FIR Filter Design (Signal Processing Toolbox).

    [b,a] = butter(2,0.1,"low");

    Use the generated transfer coefficients to filter the data channel Fz.

    tdFilter = filter(td,channels="Fz",b=b,a=a);

    Plot the resulting tireData objects in tdFilter to visualize the modified data set.

    plot(tdFilter,DataVariableNames=["et","Fz"],ColorBy="Fz")

    Figure contains an axes object. The axes object with title Normal force [N] vs Elapsed time [s], xlabel Elapsed time [s], ylabel Normal force [N] contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent 2140, 4270, 5160, 6460.

    Specify Cutoff Frequency

    Set the cutoff frequency (Hz) to F=2 to use a low pass filter to filter the data channel Fz.

    tdFilter = filter(td,channels="Fz",F=2);

    Plot the resulting tireData objects in tdFilter to visualize the modified data set.

    plot(tdFilter,DataVariableNames=["et","Fz"],ColorBy="Fz")

    Figure contains an axes object. The axes object with title Normal force [N] vs Elapsed time [s], xlabel Elapsed time [s], ylabel Normal force [N] contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent 2140, 4270, 5160, 6460.

    The cutoff frequency name-value argument uses the data channel et to calculate the sampling frequency. If et is empty or invalid for calculating the sampling frequency, additionally provide the sampling frequency Fs.

    tdFilter = filter(td,channels="Fz",F=2,Fs=32);

    Plot the resulting tireData objects in tdFilter to visualize the modified data set.

    plot(tdFilter,DataVariableNames=["et","Fz"],ColorBy="Fz")

    Figure contains an axes object. The axes object with title Normal force [N] vs Elapsed time [s], xlabel Elapsed time [s], ylabel Normal force [N] contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent 2140, 4270, 5160, 6460.

    Input Arguments

    collapse all

    Tire data, specified a tireData object or an array of tireData objects.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: tdFilter = filter(td,channels="Fz",k=10);

    Tire data channels to filter, specified as a vector of string scalars. String values must be a property of the tireData object. See tireData Properties.

    Note

    If you do not specify channels, then the filter function filters all non-time channels.

    Example: channels=["Fx", "Fy"]

    Data Types: string

    Window length for movmean, specified as a real positive scalar. The movmean function is invoked by the filter function when k is specified and returns the k-point mean values. For more information, see movmean.

    Example: k=10

    Data Types: double

    Digital filter, specified as a digitalFilter object. Use designfilt to generate a digital filter based on frequency-response specifications. For more information, see designfilt (Signal Processing Toolbox).

    Transfer function coefficients, specified as vectors.

    Example: b=[0.0201 0.0402 0.0201] and a=[1 -1.5610 0.6414]

    Data Types: double

    Cutoff frequency, specified as a scalar, in Hz.

    Note

    If the tireData channel et is empty or invalid for calculating the sampling frequency, then you must provide the sampling frequency Fs.

    Data Types: double

    Sampling frequency, specified as a scalar, in Hz.

    Note

    You must provide F when specifying Fs, and you must specify Fs if the tireData channel et is empty or invalid for calculating the sampling frequency. If Fs is provided and does not match et, then the filter function uses the value of Fs for the filter design.

    Data Types: double

    Output Arguments

    collapse all

    Filtered tire data, returned as a tireData object or vector of tireData objects.

    Version History

    Introduced in R2024a

    See Also

    | (Signal Processing Toolbox) |