cra*_*ict 9 matlab signal-processing curve-fitting

蓝色情节是原始情节(红色)的嘈杂情节.有没有办法将蓝色图近似为近红色图?
Jun*_*uxx 14
让我们定义一个波浪函数:
x = 0:.1:20;
y1 = 5*sin(x) + 2*x - x.^2 +.3*x.^3 - .2*(x-15).^4 - 10*x.^2.*cos(x./3+12).^3 + .5*(x-12).^4;
Run Code Online (Sandbox Code Playgroud)
并添加大量噪音:
r = randi(1000,1,201) - 500;
y2 = y1+r;
Run Code Online (Sandbox Code Playgroud)
现在制作一维高斯滤波器,对其进行标准化并将其与我们的函数进行卷积:
g = gausswin(20); % <-- this value determines the width of the smoothing window
g = g/sum(g);
y3 = conv(y2, g, 'same')
Run Code Online (Sandbox Code Playgroud)
我们来看看结果吧
figure;
hold on;
plot(y1, 'r', 'linewidth', 3);
plot(y2, 'b');
plot(y3, 'g', 'linewidth', 3);
Run Code Online (Sandbox Code Playgroud)
红色原始功能,蓝色嘈杂版本,绿色平滑,"恢复"功能.

bla*_*bla 11
另一种选择是使用'平滑'.我喜欢使用它,因为它是一个单行功能.使用@Junuxx先前答案的代码:
x = 0:.1:20;
y1 = 5*sin(x) + 2*x - x.^2 +.3*x.^3 - .2*(x-15).^4 - 10*x.^2.*cos(x./3+12).^3 + .5*(x-12).^4;
r = randi(1000,1,201) - 500;
y2 = y1+r;
Run Code Online (Sandbox Code Playgroud)
现在应用顺利:
ys = smooth(x,y2,0.25,'rloess');
plot(x,y2,x,ys)
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息:
doc smooth
Run Code Online (Sandbox Code Playgroud)