MATLAB Fundamentals>>>Smoothing Data with Moving Average

MATLAB Fundamentals>Common Data Analysis Techniques>Smoothing Data> (2/5) Smoothing Data with Moving Average


例1:

Smoothing method:Moving mean

Moving window:Centered 2

代码2:

% Smooth input data
ySm = smoothdata(y,"movmean",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例2:

Smoothing method:Moving mean

Smoothing factor:0.25

代码2:

% Smooth input data
ySm = smoothdata(y,"movmean","SmoothingFactor",0.25,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例3:

Smoothing method:Moving median

Moving window:Centered 2

代码3:

% Smooth input data
ySm = smoothdata(y,"movmedian",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例4:

Smoothing method:Gaussian filter

Moving window:Centered 2

代码4:

% Smooth input data
ySm = smoothdata(y,"gaussian",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例5:

Smoothing method:Local linear regression(lowess)

Moving window:Centered 2

代码5:

% Smooth input data
ySm = smoothdata(y,"lowess",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例6:

Smoothing method:Local quadratic regression(loess)

Moving window:Centered 2

代码6:

% Smooth input data
ySm = smoothdata(y,"loess",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例7:

Smoothing method:Robust Lowess

Moving window:Centered 2

代码7:

% Smooth input data
ySm = smoothdata(y,"rlowess",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例8:

Smoothing method:Roubst Loess

Moving window:Centered 2

代码8:

% Smooth input data
ySm = smoothdata(y,"rloess",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")

例9:

Smoothing method:Savitzky-Golay polynomial filter

polynomial degree:2

Moving window:Centered 2

代码9:

% Smooth input data
ySm = smoothdata(y,"sgolay",2,"SamplePoints",x);

% Display results
figure
plot(x,y,"SeriesIndex",6,"DisplayName","Input data")
hold on
plot(x,ySm,"SeriesIndex",1,"LineWidth",1.5, ...
    "DisplayName","Smoothed data")
hold off
legend
xlabel("x")
  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值