Finding the first order derivative of a data series using the Savitzky-Golay filter.
18 ビュー (過去 30 日間)
古いコメントを表示
I am trying to rewrite some Python code into a Matlab script. The input data to this code in a 2-D array called 'spectra' with each row of 'spectra' corresponding to a different set of signal observations (i.e. a different spectrum) and with each column corresponding to the wavelengths at which the observations were made. For the purposes of this question, assume that the columns have unity spacing (i.e., the difference between successive wavelengths is '1').
I would like to smooth and differentiate the data using a Savtizky-Golay filter. To do this in Python, the code would include these lines:
# Read the signal values (first column is observation date)
y = (spectra.values[:,2:]).astype('float32'))
# Calculate first derivative applying a Savitzky-Golay filter
dy = savgol_filter(y, 25, polyorder = 5, deriv=1)
My understanding of the above is that, for each wavelength, the Savitzky Golay filter fits a fifth order polynomial to the signal values in a window encompassing 25 wavelengths (symmetric about the wavelength of interest). The filter then applies that polynomial to compute the first order derivative at that wavelength. You end up with a series of data points equal to the first order derivative at each wavelength.
My question is: How can I best achieve the same computation in Matlab? The sgolay function does not appear to have a derivative option.
0 件のコメント
採用された回答
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!