Hauptinhalt

mssgolay

Smooth signal with peaks using least-squares polynomial

    Description

    mssgolay(X,Intensities) smooths raw noisy signal data, Intensities, using a least-squares digital polynomial filter (Savitzky and Golay filters) and plots the result. The default span or frame is 15 samples.

    Use mssgolay with data from any separation technique that produces signal data, such as spectroscopy, NMR, electrophoresis, chromatography, or mass spectrometry.

    Yout = mssgolay(X,Intensities) stores the smoothed data as Yout. This syntax does not plot the data.

    example

    Yout = mssgolay(X,Intensities,Name=Value) specifies options using one or more name-value arguments in addition to the arguments in the previous syntaxes.

    example

    Examples

    collapse all

    This example shows how to smooth mass spectrometry data using least-squares polynomial approach.

    Load a MAT-file, included with Bioinformatics Toolbox™, that contains mass spectrometry data including MZ_lo_res , a vector of m/z values for a set of spectra, and Y_lo_res , a matrix of intensity values for a set of mass spectra that share the same m/z charge.

    load sample_lo_res

    Apply least-squares polynomial smoothing to the data.

    YS = mssgolay(MZ_lo_res,Y_lo_res);

    Plot the third sample/spectrogram in Y_lo_res , and its smoothed signal.

    mssgolay(MZ_lo_res,Y_lo_res,ShowPlot=3);

    Figure contains an axes object. The axes object with title Signal ID: 3, xlabel Separation Units, ylabel Relative Intensity contains 2 objects of type line. These objects represent Original signal, Smoothed signal.

    Input Arguments

    collapse all

    Separation-unit values for a set of signals with peaks, specified as a vector with the number of elements equal to the number of rows in the matrix Intensities. The separation unit can quantify wavelength, frequency, distance, time, or m/z depending on the instrument that generates the signal data.

    Data Types: double

    Intensity values for a set of peaks that share the same separation-unit range, specified as a matrix. Each row of the matrix corresponds to a separation-unit value, and each column corresponds to either a set of signals with peaks or a retention time. The number of rows equals the number of elements in vector X.

    Data Types: double

    Name-Value Arguments

    collapse all

    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: ShowPlot=3

    Frame size for the smoothing function, specified as a positive number. Higher values smooth the signal more with an increase in computation time.

    • If the Span value is greater than 1, the window is the size of Span in samples independent of the X vector.

    • If the Span value is less than 1, the window size is a fraction of the number of points in the input data, X. For example, if Span is 0.05, the window size is equal to 5% of the number of points in X.

    Data Types: double

    Degree of the polynomial fitted to the points in the moving frame, specified as a positive integer smaller than the Span value.

    Data Types: double

    Indicator to plot the smoothed and original data, specified as:

    • true— Plot the smoothed data over the first signal specified in the Intensities argument of the original data.

    • false—Do not plot the data.

    • Positive integer N— Plot the smoothed data over the Nth signal specified in the Intensities argument of the original data.

    The default value for plotting depends on the output argument, Yout:

    • For a syntax without an output argument, the default value is false.

    • For a syntax with an output argument, the default value is true.

    Data Types: double | logical

    Output Arguments

    collapse all

    Smoothed data, returned as a matrix.

    Tips

    • The original algorithm by Savitzky and Golay assumes the input vector, X, has uniformly spaced separation units, while mssgolay also allows one that is not uniformly spaced. Therefore, the sliding frame for smoothing is centered using the closest samples in terms of the X value and not in terms of the X index.

    • When the input vector, X, does not have repeated values or NaN values, the algorithm is approximately twice as fast.

    • When the input vector, X, is evenly spaced, the least-squares fitting is performed once so that the signal is filtered with the same coefficients, and the speed of the algorithm increases considerably.

    • If the input vector, X, is evenly spaced and the Span value is even, span is incremented by 1 to include both edge samples in the frame.

    Version History

    Introduced before R2006a