matlab如何让plot更平滑,如何在MATLAB中平滑繪圖?

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

我在圖上畫了9000點

(完整的決議)

78018f6ea5cd7ee5803b93fad89e9ee6.jpe

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?

我不確定,但是快速傅里葉變換能有幫助嗎?

5 个解决方案

#1

17

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))

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.

這就減少了最高的20個頻率。要小心地把它們分開,否則逆變換就不再是實數了。您需要仔細選擇合適的平滑度的截止頻率。這是一種非常簡單的濾波(在頻域內進行濾波),所以如果失真是不可接受的,你可以嘗試輕輕地衰減高階頻率。

#2

30

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:

如果你有曲線擬合工具箱,你可以使用平滑函數。默認方法是移動平均大小5(方法可以更改)。一個例子:

% some noisy signal

Fs = 200; f = 5;

t = 0:1/Fs:1-1/Fs;

y = sin(2*pi*f*t) + 0.6*randn(size(t));

subplot(411)

plot(y), title('Noisy signal')

% smoothed signal

subplot(412)

plot( smooth(y, 5, 'moving') ), title('smooth')

ylim([-2 2])

If not, you can use use your own window function using the filter function from core MATLAB:

如果沒有,您可以使用從core MATLAB中使用的filter函數來使用您自己的窗口函數:

% equivalent to a moving average window

wndwSize = 5;

h = ones(1,wndwSize)/wndwSize;

subplot(413)

plot( filter(h, 1, y) ), title('filter + square window')

% Guassian

h = pdf('Normal',-floor(wndwSize/2):floor(wndwSize/2),0,1);

subplot(414)

plot( filter(h, 1, y) ), title('filter + Guassian window')

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9zcUhUTi5wbmc=

#3

5

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).

FFT不是一個壞主意,但它可能在這里過度了。跑步或移動的平均成績通常會導致糟糕的結果,除了遲交的作業(和白噪音)之外,其他任何事情都應該避免。

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.

我將使用Savitzky-Golay過濾(在Matlab sgolayfilt(…)中)。這將為您提供最佳的搜索結果——局部平滑,同時保持曲線的形狀。

-Paul

保羅

#4

3

Sometimes you should avoid using mobile average as it's not robust to outliers. Mobile median is preferable in those cases.

有時,您應該避免使用移動平均,因為它對異常值不健壯。在這些情況下,移動中位數更可取。

#5

1

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.

我首先嘗試在一些點上顯示運行平均值,比如5或10。這樣,在值上的單個差異只會對圖形產生一點影響。當然,這取決於你需要的圖形有多精確。

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值