博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Savitzky-Golay smoothing
阅读量:2443 次
发布时间:2019-05-10

本文共 4783 字,大约阅读时间需要 15 分钟。

The SAVGOL function returns the coefficients of a Savitzky-Golay smoothing filter, which can then be applied using the CONVOL function. The Savitzky-Golay smoothing filter, also known as least squares or DISPO (digital smoothing polynomial), can be used to smooth a noisy signal.

The filter is defined as a weighted moving average with weighting given as a polynomial of a certain degree. The returned coefficients, when applied to a signal, perform a polynomial least-squares fit within the filter window. This polynomial is designed to preserve higher moments within the data and reduce the bias introduced by the filter. The filter can use any number of points for this weighted average.

This filter works especially well when the typical peaks of the signal are narrow. The heights and widths of the curves are generally preserved.

Tip: You can use this function in conjunction with the CONVOL function for smoothing and optionally for numeric differentiation.

This routine is written in the IDL language. Its source code can be found in the file savgol.pro in the lib subdirectory of the IDL distribution.

Syntax


Result = SAVGOL( NleftNrightOrderDegree [, /] )

Return Value


This function returns an array of floating-point numbers that are the coefficients of the smoothing filter.

Arguments


Nleft

An integer specifying the number of data points to the left of each point to include in the filter.

Nright

An integer specifying the number of data points to the right of each point to include in the filter.

Note: Larger values of Nleft and Nright produce a smoother result at the expense of flattening sharp peaks.

Order

An integer specifying the order of the derivative desired. For smoothing, use order 0. To find the smoothed first derivative of the signal, use order 1, for the second derivative, use order 2, etc.

Note: Order must be less than or equal to the value specified for Degree.

Note: For ORDER > 0, SAVGOL returns unnormalized coefficients. To use the SAVGOL coefficients with CONVOL, you should multiple the returned coefficients by FACTORIAL(ORDER)/(dxORDER), where dx is the sampling interval between data points. See the example below.

Degree

An integer specifying the degree of smoothing polynomial. Typical values are 2 to 4. Lower values for Degree will produce smoother results but may introduce bias, higher values for Degree will reduce the filter bias, but may “over fit” the data and give a noisier result.

Note: Degree must be less than the filter width (Nleft + Nright + 1).

Keywords


DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

Tip: The DOUBLE keyword is recommended for Degree greater than 9.

Examples


The following example creates a noisy 400-point vector with 4 Gaussian peaks of decreasing width. It then plots the original vector, the vector smoothed with a 33-point Boxcar smoother (the SMOOTH function), and the vector smoothed with 33-point wide Savitzky-Golay filter of degree 4. The bottom plot shows the second derivative of the signal (without noise) and the second derivative of the noisy data using the Savitzky-Golay filter of degree 4.

The code for this example is included in the file savgol_doc.pro in the examples/doc/language subdirectory of the IDL distribution. Run this example procedure by entering savgol_doc at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT savgol_doc.pro.

Savgol_doc
n = 401 ; number of points
np = 4  ; number of peaks
 
; Form the baseline:
y = (0.5, n)
 
; Sampling interval:
dt = 0.1
 
; Index the array:
x = dt*(n)
 
; Add each Gaussian peak:
i=0, np-1 DO
   c = dt*(i + 0.5) * (n)/np; Center of peak
   peak = 3 * (x-c) / (dt*(75. / 1.5 ^ i))
   ; Add Gaussian. Cutoff of -50 avoids underflow errors for
   ; tiny exponentials:
   y = y + ((-peak^2)>(-50))
 
 
; Add noise:
y1 = y + 0.10 * (-121147, n, /RAN1)
 
; Display the first plots and define the layout
p1 = (x, y1, NAME='Signal Noise', LAYOUT=[1,2,1], DIMENSIONS=[500,800])
 
p2 = (x, (y1, 33, /EDGE_TRUNCATE), /OVERPLOT, $
   COLOR=[255, 0, 0], NAME='Smooth (width 33)')
savgolFilter = (16, 16, 0, 4)
 
p3 = (x, (y1, savgolFilter, /EDGE_TRUNCATE), /OVERPLOT, $
   COLOR=[0, 0, 255], THICK=2, $
   NAME='Savitzky-Golay (width 33, 4th degree)')
l1 = (TARGET=[p1, p2, p3], POSITION=[387,784], $
   /, /AUTO_TEXT_COLOR)
 
 
p4 = (x, (x, (x, y)), YRANGE=[-4, 2], /CURRENT, LAYOUT=[1,2,2], $
   NAME='Second derivative')
 
order = 2
; Don't forget to normalize the coefficients.
savgolFilter = (16, 16, order, 4)*((order)/ $
  (dt^order))
 
p5 = (x, (y1, savgolFilter, /EDGE_TRUNCATE), /OVERPLOT, $
   COLOR=[0, 0, 255], THICK=2, $
   NAME='Savitzky-Golay(width 33, 4th degree, order 2)')
 
l2 = (TARGET=[p4, p5], POSITION=[426,384],$
   /, /AUTO_TEXT_COLOR)
 
 

转载地址:http://vtiqb.baihongyu.com/

你可能感兴趣的文章
apache 证书配置_Apache配置错误AH02572:无法配置至少一个证书和密钥
查看>>
web设置字体粗细css_Web上使用CSS的可变字体
查看>>
css 垂直对齐_CSS垂直对齐属性
查看>>
为您的网站提供动力的100种Jamstack工具,API和服务
查看>>
api restful_构建RESTful API的13种最佳实践
查看>>
wordpress用途_8个热门WordPress多用途主题及其炫酷功能
查看>>
用于Angular,React和Vue.js的Bootstrap UI库
查看>>
vue 分步引导组件_引导卡组件:完整介绍
查看>>
fa fa-user_如何通过短信通过2FA保护Laravel应用
查看>>
使用MongoDB Stitch在10分钟内构建一个Slack应用
查看>>
next主题seo优化_SEO可见性的5个最佳WordPress主题
查看>>
揭穿3个常见的WordPress神话
查看>>
bootstrap步骤_通过8个简单步骤进行Bootstrap和WordPress主题集成
查看>>
struts2 css失效_CSS体系结构和可维护CSS的三大Struts
查看>>
您可能不知道WooCommerce可以做的10件事
查看>>
php使用nginx建网站_如何使用预建网站来刷新网站的外观
查看>>
wordpress快速建站_您的WordPress主题灵活还是快速?
查看>>
bootstrap布局技巧_加快Bootstrap网站的3个技巧
查看>>
bootstrap网格_Bootstrap网格:掌握最有用的Flexbox属性
查看>>
symfony 控制器_重新引入Symfony控制台-适用于未开始使用的CLI PHP!
查看>>