Documentation

光滑的

平滑的响应数据

描述

example

是的=平滑(y)平滑列矢量中的响应数据yusing a moving average filter.

前几个要素是的跟随。

yy(1)= y(1)yy(2)=(y(1) + y(2) + y(3))/3 yy(3)=(y(1) + y(1) + y(2) + y(3) + y(4) + y(5))/5 yy(4)=(y(2) + y(3) + y(4) + y(5) + y(6))/5 ..。
Because of the way光滑的处理端点,结果与返回的结果不同筛选function.

是的=平滑(y,跨度)将移动平均线的跨度设置为跨度

是的=平滑(y,方法)平滑数据yusing the method specified by方法和默认值跨度

example

是的=平滑(y,跨度,方法)sets the span of方法to跨度

是的=平滑(y,'sgolay',degree)将Savitzky-Golay方法与由多项式度指定degree

是的=平滑(y,跨度,'sgolay',degree)使用由跨度在Savitzky-Golay计算中。跨度must be odd anddegreemust be less than跨度

example

是的=平滑(x,y,___)指定自变量的值x。您可以将此语法与上一个语法中的任何参数一起使用。

gpuarrayyY=平滑(gpuarrayy,___)performs the operation on a GPU usinggpuArray数据。您可以使用gpuArrayresponse data with all previous syntaxes. This syntax requires Parallel Computing Toolbox™.

gpuarrayyY=平滑(gpuarrayx,gpuarrayy,___)performs the operation on a GPU usinggpuArray输入数据。该语法需要并行计算工具箱。

Note

UsinggpuArrayxyinputs with the光滑的仅当您使用默认方法时,建议函数,'moving'。将GPU数据与其他方法使用不提供任何性能优势。

例子

全部收缩

Smooth data by linear index and by each column separately, using a moving average filter. Plot and compare the results.

Load the data incount.dat。The 24-by-3 arraycountcontains traffic counts at three intersections for each hour of the day.

loadcount.dat

假设数据连续三天来自单个相交。然后,平滑所有数据将指示通过交叉路口的交通流量的整体周期。使用5小时跨度的移动平均过滤器同时平滑所有数据(按线性索引)。

c =平滑(count(:));C1 =重塑(C,24,3);

However, the data are in fact from three different intersections. Thus, smoothing columnwise gives a more meaningful picture of the traffic through each intersection in a day. Use the same moving average filter to smooth each column of the data separately.

C2 = zeros(24,3);fori = 1:3 c2(:,i)= smooth(count(:,i));end

绘制原始数据和通过线性索引和每列平滑的数据。然后,绘制两个平滑数据集之间的差异。这两种方法在端点附近给出了不同的结果。

subplot(3,1,1) plot(count,':');抓住情节(C1,“- - -”);标题('Smooth C1 (All Data)') subplot(3,1,2) plot(count,':');抓住情节(C2,“- - -”);标题('Smooth C2 (Each Column)')子图(3,1,3)图(C2 -C1,'o-') 标题(差异C2 -C1')

Plot and compare the results of data smoothed using theloessrloess方法。Then determine which method is less sensitive to outliers.

使用两个异常值创建嘈杂的数据。

x = (0:0.1:15)'; y = sin(x) + 0.5*(rand(size(x))-0.5); y([90,110]) = 3;

使用loessrloess方法。使用数据点总数的10%。

是的1 = smooth(x,y,0.1,'黄土');yy2 =平滑(x,y,0.1,'rloess');

绘制原始数据和平滑数据。异常值的影响力较小rloess

subplot(2,1,1) plot(x,y,'b.',x,yy1,'r-')(GCA,'YLim',[-1.5 3.5]) legend(“原始数据”,'Smoothed data using ''loess''',。。。'地点','NW')子图(2,1,2)图(x,y,'b.',x,yy2,'r-')(GCA,'YLim',[-1.5 3.5]) legend(“原始数据”,“使用'rloess''平滑数据',。。。'地点','NW')

Input Arguments

全部收缩

数据要平滑,指定为列向量。

如果your data containsNaNs and you do not specifyx, your data is treated as nonuniform and the smoothing method'lowess'用来。

Data Types:single|双倍的

计算平滑值的数据点数, specified as an integer or as a scalar value in the range (0,1) denoting a fraction of the total number of data points.

如果使用移动平均值或Savitzky-Golay方法,则计算平滑值的数据点必须是一个奇数整数。如果指定跨度作为偶数数字或作为导致偶数数据点的分数,跨度is automatically reduced by 1.

例子:7;0.6

平滑方法平滑响应数据,指定为以下方法之一。

Method

描述

'moving'(默认)

Moving average. A lowpass filter with filter coefficients equal to the reciprocal of the span.

'lowess'

使用加权线性最小二乘和一级多项式模型的局部回归。

'黄土'

Local regression using weighted linear least squares and a 2nd degree polynomial model.

'sgolay'

Savitzky-Golay filter. A generalized moving average with filter coefficients determined by an unweighted linear least-squares regression and a polynomial model of specified degree (default is 2). The method can accept nonuniform predictor data.

'rlowess'

强大的版本的'lowess'that assigns lower weight to outliers in the regression. The method assigns zero weight to data outside six mean absolute deviations.

'rloess'

强大的版本的'黄土'that assigns lower weight to outliers in the regression. The method assigns zero weight to data outside six mean absolute deviations.

Savitzky-Golay方法中使用的模型的多项式度,指定为标量值。degreemust be less than跨度

例子:3

响应数据的自变量y,指定为列向量。如果您不提供x, methods that requirexassumex = 1:长度(y)。Specifyxdata wheny不分类或均匀间隔。如果xis not uniform and you do not specify方法,使用。如果您指定需要的平滑方法xto be sorted, the function automatically sorts thex数据。

Data Types:single|双倍的

数据要平滑, specified as agpuArray列向量。

Data Types:single|双倍的

Input data for the response datagpuarrayy, specified as agpuArray列向量。如果您不提供gpuarrayx, methods that requiregpuarrayxassumegpuarrayx= 1:length(y)。Specifygpuarrayxdata when the data are not uniformly spaced or sorted. If thegpuarrayxdata is not uniform and you do not specify the smoothing method,'lowess'用来。如果您指定了需要的平滑方法gpuarrayxto be sorted, the function automatically sorts thegpuarrayx数据。

Data Types:single|双倍的

Output Arguments

全部收缩

平滑数据,返回为列向量。

Smoothed data, returned as agpuArray列向量。

提示

  • For more options for smoothing data, including the moving median and Gaussian methods, see光滑的data

  • 您可以使用平滑样条来使数据平滑拟合。有关更多信息,请参阅fit

Extended Capabilities

在R2006a之前引入