フィルターのクリア

ploting coordinate smoothly with given dataset

2 ビュー (過去 30 日間)
Jiung Shin
Jiung Shin 2020 年 12 月 8 日
コメント済み: Cris LaPierre 2020 年 12 月 8 日
I want to draw the position of the object using vector x and y each containing coordinate of x and y with change in time.
To make the movement smooth using least square fitting, I p=polyval(x,y,60) and it returns:
Warning: Polynomial is badly
conditioned. Add points with distinct X
values, reduce the degree of the
polynomial, or try centering and scaling
as described in HELP POLYFIT.
the dataset is given so I can't change it. Please help

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 12 月 8 日
編集済み: Cris LaPierre 2020 年 12 月 8 日
I think you meant to use polyfit instead of polyval.
However, an n of 60 is a bit ridiculous. I would strongly recommend picking a value that is more appropriate for your data. At an absolute minimum, n cannot be great than your number of points. It should actually be much less than your number of points. Otherwise, you risk overfitting.
  2 件のコメント
Jiung Shin
Jiung Shin 2020 年 12 月 8 日
in my data set, it is listed in order of time but the x coordinate goes back and forth and sometimes overlap so while plot(x,y) shows a rough circlular shape, the polyfit only shows function going in one direction.
If my purpose is to smooth the circular shape, which tool should I use?
Cris LaPierre
Cris LaPierre 2020 年 12 月 8 日
Unfortunately, I'm not aware of a good technique for smoothing data that is not a function (vertical line test).
I'm just googling here, but a couple options might be
% Circle points
x=10*cos(0:.07:6*pi);
y=10*sin(0:.07:6*pi);
% Add noise
x=x+rand(size(x))-.5;
y=y+rand(size(x))-.5;
plot(x,y,'.')
axis equal
xlim([-12 12])
ylim([-12 12])
% S-G filtering
windowWidth = 35;
polynomialOrder = 2;
smoothX = sgolayfilt(x, polynomialOrder, windowWidth);
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
hold on
plot(smoothX,smoothY,'or')
hold off
  • Use the smooth function (data likely has to be in order. Could use sort/sortrows for that)
smoothX1 = smooth(x);
smoothY1 = smooth(y);
hold on
plot(smoothX1,smoothY1,'*g')
hold off

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by