如何平滑 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您有曲线拟合工具箱,则可以使用
平滑
功能。默认方法是大小为 5 的移动平均线(可以更改方法)。示例:如果没有,您可以使用您自己的窗口函数,使用
来自核心 MATLAB 的过滤器
函数:If you have the Curve Fitting Toolbox, you can use the
smooth
function. The default method is a moving average of size 5 (method can be changed). An example:If not, you can use use your own window function using the
filter
function from core MATLAB:一种简单(临时)的方法是在每个点与其相邻点取加权平均值(可通过 alpha 调整):
或其某种变体。是的,为了更复杂,您可以首先对数据进行傅里叶变换,然后切断高频。类似于:
这会删除最高 20 个频率。小心地将它们对称地切掉,否则逆变换不再真实。您需要仔细选择截止频率以获得正确的平滑级别。这是一种非常简单的滤波(频域中的箱式滤波),因此如果失真不可接受,您可以尝试轻轻地衰减高阶频率。
A simple (ad hoc) way is to just take a weighted average (tunable by
alpha
) at each point with its neighbors:or some variation thereof. Yes, to be more sophisticated you can Fourier transform your data first, then cut off the high frequencies. Something like:
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.
FFT 并不是一个坏主意,但它在这里可能有点过分了。跑步或移动平均线的结果通常很差,除了迟交的作业(和白噪音)之外,应该避免使用跑步或移动平均线。
我会使用 Savitzky-Golay 过滤(在 Matlab sgolayfilt(...) 中)。这将为您提供所需的最佳结果 - 在保持曲线形状的同时进行一些局部平滑。
——保罗
FFT isn't a bad idea, but it's probably overkill here. Running or moving averages give generally poor results and should be avoided for anything besides late homework (and white noise).
I'd use Savitzky-Golay filtering (in Matlab sgolayfilt(...)). This will give you the best results for what you are looking for - some local smoothing while maintaining the shape of the curve.
-Paul
有时您应该避免使用移动平均值,因为它对异常值不稳健。在这些情况下,移动中位数是更好的选择。
Sometimes you should avoid using mobile average as it's not robust to outliers. Mobile median is preferable in those cases.
我首先尝试显示多个点(如 5 或 10)的运行平均值。这样,值中的单个差异只会对图表产生很小的影响。当然,这取决于您需要图表的准确性。
I'd first try to display the running average over a number of points, like 5 or 10. This way, a single discrepancy in the values only have a little impact on the graph. Of course, it depends on how accurate you need the graph to be.