Filter/interpolation in a curve

Hi everybody,
I have the black curve in the figure that I would to trasform in the blu one in the .jpeg file.
I tryed to do that using a filter (I wrote this script):
windowSize = 20;
b1 = (1/windowSize)*ones(1,windowSize);
a1 = 1;
f1 = filter(b1,a1,Ygraph1);
But I obtained only the red curve in the figure.
Can someone help me on how to do that?
Thank you so much.
I attach the figure .fig

댓글 수: 4

John D'Errico
John D'Errico 2021년 2월 23일
You are looking to smooth out quite low frequency components, where a span of several hundred points is probably a more realistic windowsize.
What you got with the red curve seems not at all unrealistic, based on what you did.
Think of it like this: how many points does it take to span ONE of those low frequency oscillations? If your window size is not significantly larger than that, what do you expect?
Mathieu NOE
Mathieu NOE 2021년 2월 23일
hello
FYI, look at movmean
Star Strider
Star Strider 2021년 2월 23일
Experiment with changing ‘windowSize’.
Tobia Alessi
Tobia Alessi 2021년 2월 24일
Thank you everyone for the answer. I tryed to use the Signal Analyzer App to find the right smoothing factor and it run.
But now I'd like to know how to put this factor in my script.
Which value of windowSize, b1 and a1 I have to use to obtain a smoothing factor of 0.4?
Thanks in advance

댓글을 달려면 로그인하십시오.

답변 (1개)

Nipun
Nipun 2024년 5월 31일

0 개 추천

Hi Tobia,
I understand that you want to transform the black curve into the blue one using a smoother filter. Your current attempt with a moving average filter only achieved the red curve.
To achieve a smoother result like the blue curve, you can use a Savitzky-Golay filter:
% Load the data
load('your_data.mat'); % Adjust this line to load your data
% Apply Savitzky-Golay filter
windowSize = 51; % Adjust window size for smoother result
polyOrder = 3; % Polynomial order for Savitzky-Golay filter
smoothedData = sgolayfilt(Ygraph1, polyOrder, windowSize);
% Plot the result
plot(time, Ygraph1, 'k', time, smoothedData, 'b', 'LineWidth', 2);
xlabel('Tempo [s]');
ylabel('Velocità [mm/s]');
legend('Original Data', 'Smoothed Data');
title('Velocità di avanzamento pezzo');
This should give you a smoother curve like the blue one in your image. Refer to the following MathWorks documentation for more information on Savitzky-Golay filtering in MATLAB:
Hope this helps.
Regards, Nipun

질문:

2021년 2월 23일

답변:

2024년 5월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by