如何在MATLAB中平滑绘图? [英] How to smoothen a plot in MATLAB?

查看:251
本文介绍了如何在MATLAB中平滑绘图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在图形上绘制了9000个点:

I have some 9000 points that are plotted on a graph:

[全分辨率]

实际上,情节并不像我想要的那样顺利. 有什么方法可以使图形平滑到所需程度?

Actually, the plot is not as smooth as I wanted it to be. Is there some way I can smoothen the graph to a required degree?

还是某种形式的阈值处理,以便我可以选择性地平滑那些过于颠簸的部分?

Or some form of thresholding so that I can selectively smoothen out the parts that is too bumpy?

我不确定,但是可以

I am not sure but can fast-fourier-transform help?

推荐答案

一种简单的(临时)方法是在每个点及其邻居处获取加权平均值(可通过alpha调整):

A simple (ad hoc) way is to just take a weighted average (tunable by alpha) at each point with its neighbors:

data(2:n-1) = alpha*data(2:n-1) + (1-alpha)*0.5*(data(1:n-2)+data(3:n))

或其一些变体.是的,要变得更加复杂,您可以先进行傅立叶变换,然后切断高频.像这样:

or some variation thereof. Yes, to be more sophisticated you can Fourier transform your data first, then cut off the high frequencies. Something like:

f = fft(data)
f(n/2+1-20:n/2+20) = zeros(40,1)
smoothed = real(ifft(f))

这会切出最高的20个频率.小心地将它们对称地切掉,否则逆变换将不再是真实的.您需要仔细选择截止频率以实现正确的平滑度.这是一种非常简单的滤波(频域中的盒式滤波),因此,如果失真不可接受,您可以尝试轻轻地衰减高阶频率.

This cuts out the highest 20 frequencies. Be careful to cut them out symmetrically otherwise the inverse transform is no longer real. You need to carefully choose the cutoff frequency for the right level of smoothing. This is a very simple kind of filtering (box filtering in frequency domain), so you can try gently attenuating high order frequencies if the distortion is unacceptable.

这篇关于如何在MATLAB中平滑绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆