How do I filter my data points without using smoothdata?

1 Ansicht (letzte 30 Tage)
Thomas Nell
Thomas Nell am 11 Dez. 2018
Bearbeitet: Image Analyst am 12 Dez. 2018
I have 2 variables, t and y, which are both vectors. What I want to do is smooth the data so that, for example, if t is a 10x1 vector, it becomes a 5x1 vector comprising an average of the data points around it. How do I go about this without using the smoothdata function?
Thank you very much and kind regards,
Tom
  2 Kommentare
Bob Thompson
Bob Thompson am 11 Dez. 2018
I'm sure there's a better way, but you could do this manually using a for loop and interpolation.
t2 = linspace(t(1),t(end),5);
for i = 1:5;
y2(i) = interp1(t,y,t2(i));
end
Chad Greene
Chad Greene am 11 Dez. 2018
Note: Interpolation without smoothing or lowpass filtering first could result in aliasing.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Chad Greene
Chad Greene am 11 Dez. 2018
What about movmean to smooth the data, then interp1 to pick out the 5 points you want?
  2 Kommentare
Thomas Nell
Thomas Nell am 12 Dez. 2018
Is movmean part of the signal processing toolbox??? I'm not allowed to use any functions from there
Image Analyst
Image Analyst am 12 Dez. 2018
No, it's part of base MATLAB. If you get help on any function, it will tell you what toolbox it's in, if any.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 12 Dez. 2018
Bearbeitet: Image Analyst am 12 Dez. 2018
You could use conv() to smooth y.
windowWidth = 5;
kernel = ones(1, windowWidth) / windowWidth;
smoothedY = conv(y, kernel, 'valid'); % conv() is in base MATLAB.
Do NOT smooth t, for obvious reasons.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by