How to Smooth a plot conserving some point?

3 ビュー (過去 30 日間)
DjangoTango
DjangoTango 2022 年 1 月 31 日
コメント済み: Star Strider 2022 年 1 月 31 日
I am searching to smooth in some way my plot. It shows the sequence of 1 big hill and 1 small hill. If I use smooth, smoothdata (with all the methods and the window) I don't find any solution.
I repeat that the aim is to have a smooth curve with the same peaks of the original smooth. Some little help, please?
Thank you

採用された回答

Star Strider
Star Strider 2022 年 1 月 31 日
Experiment with the interp1 function, using the 'pchip' method. It may be necessary to use linspace to increase the number of points to interpolate. (I cannot determine that without the actual data.)
  1 件のコメント
Star Strider
Star Strider 2022 年 1 月 31 日
This provides a smoother result, and includes all the original data, without significantly distorting the original waveform.
Experiment with something like this approach —
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/879640/data.txt');
L = numel(data); % Vector Length
t1 = linspace(0, L-1, L); % Independent Original Vector
t2 = linspace(0, L-1, 5*L); % Independent Interpolation Vector
data2 = interp1(t1, data, t2, 'pchip'); % Interpolate
figure
plot(t1, data, '.-')
hold on
plot(t2, data2, '-', 'LineWidth',1.5)
hold off
grid
legend('Original Data','Interpolated Data', 'Location','best')
xlim([2540 2585])
I chose the interpolation vector to have 5 times the length of the original vector. That can be easily changed, as can the interpolation method, depending on the desired result.
.

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

その他の回答 (1 件)

DjangoTango
DjangoTango 2022 年 1 月 31 日
Thank You @Star Strider I think that there is something wrong in my code. Can you give me some tip please?
Degree=data;
t=1:1:size(Degree,1);
plot(t,Degree)
hold on
xx=linspace(t(1),t(end),size(Degree,1));
yy=interp1(t,Degree,xx,'pchip');
plot(yy')
legend('orig','interp')

カテゴリ

Help Center および File ExchangeSmoothing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by