ideas to smooth a sharpe corner of a graph?

146 ビュー (過去 30 日間)
Mona Mahboob Kanafi
Mona Mahboob Kanafi 2015 年 5 月 21 日
コメント済み: shmng 2016 年 12 月 21 日
I'm trying to smooth a sharpe corner of a graph similar to what I've shown in the image below:
Can anyone give me some ideas how to handle this case? Should I use specific filters? interpolation techniques? etc,...
If it helps, my original case is 2D and for simplification I've drawn a 1D case above. Thanks

採用された回答

Adam
Adam 2015 年 5 月 21 日
Something like a mean smoothing filter should do the job if you convolve it with your graph function.
You can specify to only do so at the sample within a certain distance of a corner assuming you can identify the corner location.
  1 件のコメント
Mona Mahboob Kanafi
Mona Mahboob Kanafi 2015 年 5 月 22 日
Thanks Adam!

サインインしてコメントする。

その他の回答 (3 件)

Thomas Koelen
Thomas Koelen 2015 年 5 月 22 日
編集済み: Thomas Koelen 2015 年 5 月 22 日
Maybe construct splines?
example:
x=1:10;
y=rand(1,10);
cs = csapi(x,y);
fnplt(cs,2);

Image Analyst
Image Analyst 2015 年 5 月 22 日
One way is to use conv() to smooth/blur the signal:
windowWidth = 9; % Some odd number.
kernel = ones(1, windowWidth) / windowWidth;
smoothedSignal = conv(signal, kernel, 'same');
That is basically fitting the output element to the mean of elements in the sliding window. If you want it to follow the signal less closely, you can use a wider window.
Or you can use a Savitzky-Golay filter, done by sgolayfilt() in the Signal Processing Toolbox. I'm attaching a demo for you Mona. This is similar to conv() in that it does a fit in a sliding window, but you can specify some order of polynomial to fit to data in the window. For example, you can fit a quadratic or cubic function to the data in the window and assign the middle element to the fitted value. So with this filter, it's still a local filter but you have more control over how much you want to smooth or follow the original signal.

Mona Mahboob Kanafi
Mona Mahboob Kanafi 2015 年 5 月 25 日
Thanks a lot for all your ideas, I really appreciate them. I finally used curve fitting in MATLAB using pchip interpolation in 1D and then extending the case in 2D by using the fittedmodel from cftool. Smoothing splines didn't work in my case as it results in an overshoot in the graph corner.
  1 件のコメント
shmng
shmng 2016 年 12 月 21 日
Hallo Mona, Could you please share the command to achieve this. I am not able to reteive as per your solution. How can we edit 2D settings in cftool. I am also looking for similar solution to smoothen the curve at sharp edges.
Any help shall be thankful.
Regards, Shwetha

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by