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
文章来源:https://www.toymoban.com/news/detail-817928.html
代码9:文章来源地址https://www.toymoban.com/news/detail-817928.html
% 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")
到了这里,关于MATLAB Fundamentals>>>Smoothing Data with Moving Average的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!