Filter Recommendation for Smoothing a Specific Signal

조회 수: 3 (최근 30일)
Raj
Raj 2023년 6월 10일
답변: Simon Chan 2023년 6월 10일
Dear Community,
I have data like the following:
x = [0,0,1,1.98999999999978,2.99000000000069,3.98000000000047,14.0500000000002,15.0599999999995,15.8700000000008,15.8700000000008,16.9399999999996,17.8900000000003,18.8800000000001,29.7900000000000,30.8299999999999,31.8700000000008,32.8699999999999,32.8699999999999,33.8299999999999,34.8599999999997,35.8199999999997,46.0400000000000,46.7600000000002,47.8100000000004,48.8000000000002,48.8000000000002,49.7600000000002,50.7500000000009,62.0400000000000,62.7900000000009,63.7900000000000,64.8000000000002,65.8000000000002,65.8000000000002,66.7800000000007,67.7900000000000,78.0900000000002,78.8999999999996,79.9000000000006,80.9000000000006,81.8999999999996,81.8999999999996,82.8899999999994,83.8900000000003,94.0900000000002,94.5500000000002,95.6400000000003,96.5500000000002,96.5500000000002,97.5500000000002,98.5700000000006,109.560000000000,110.510000000000,111.500000000000,111.500000000000,112.500000000001,113.500000000000,113.500000000000,114.520000000000,126.090000000000,126.090000000000,127.050000000000,127.050000000000,128.050000000000,128.050000000000,129.050000000000,130.040000000000,141.540000000000,142.570000000000,142.570000000000,143.530000000000,144.120000000000,144.120000000000,145.310000000000,157.330000000000,158.320000000001,159.320000000000,160.070000000000,160.610000000000,160.610000000000,161.660000000000];
y = [0,0,0.464601238374681,0.929755484255206,1.39546164308871,1.86171861902337,2.79588063231313,3.73223273143554,4.20122730982987,5.14084800633951,6.08263671695609,7.02658457720498,8.44653533211063,9.39584215120541,10.3472769347812,11.3008307275720,12.7351149203275,13.6939269261834,14.6548264413097,16.1000700040090,16.5828518024014,18.0342831256240,18.5191184145376,19.4903194207480,20.4635533783748,20.9509298520746,21.9271960550294,22.9054722725899,23.8857492968480,24.3766352288654,25.8522688397480,25.8522688397480,26.3451347901984,26.8384928487593,27.8266806453806,28.3215080581393,28.8168229284115,29.3126240906732,29.8089103782565,30.3056806233516,30.8029336570103,30.8029336570103,31.3006683091478,31.7988834085470,31.7988834085470,32.2975777828593,32.2975777828593,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,31.7988834085470,31.3006683091478,30.3056806233516,29.3126240906732,27.8266806453806,26.8384928487593,24.8680179010629,22.9054722725899,21.4388111269700,19.0044642269341,17.5499595010577,15.1360561892542,11.3008307275720,8.92092218717511,6.08263671695609,3.26378347149450,1.86171861902337,1.39546164308871,1.39546164308871,1.39546164308871];
plot(x, y);
The actual visualization of the data is as on the left of the image below. However, I want to smooth the data like the one on the right.
Any suggestions/thoughts?
Thank you.

채택된 답변

Simon Chan
Simon Chan 2023년 6월 10일
One possible way is to use function smoothdata.
Since the data on variable x has duplicated data and the step size is not equal. The duplicated data on the second position is firstly added by 0.001. Then interpolate the data with a equal step size and finally apply function smoothdata to get the result.
x = [0,0,1,1.98999999999978,2.99000000000069,3.98000000000047,14.0500000000002,15.0599999999995,15.8700000000008,15.8700000000008,16.9399999999996,17.8900000000003,18.8800000000001,29.7900000000000,30.8299999999999,31.8700000000008,32.8699999999999,32.8699999999999,33.8299999999999,34.8599999999997,35.8199999999997,46.0400000000000,46.7600000000002,47.8100000000004,48.8000000000002,48.8000000000002,49.7600000000002,50.7500000000009,62.0400000000000,62.7900000000009,63.7900000000000,64.8000000000002,65.8000000000002,65.8000000000002,66.7800000000007,67.7900000000000,78.0900000000002,78.8999999999996,79.9000000000006,80.9000000000006,81.8999999999996,81.8999999999996,82.8899999999994,83.8900000000003,94.0900000000002,94.5500000000002,95.6400000000003,96.5500000000002,96.5500000000002,97.5500000000002,98.5700000000006,109.560000000000,110.510000000000,111.500000000000,111.500000000000,112.500000000001,113.500000000000,113.500000000000,114.520000000000,126.090000000000,126.090000000000,127.050000000000,127.050000000000,128.050000000000,128.050000000000,129.050000000000,130.040000000000,141.540000000000,142.570000000000,142.570000000000,143.530000000000,144.120000000000,144.120000000000,145.310000000000,157.330000000000,158.320000000001,159.320000000000,160.070000000000,160.610000000000,160.610000000000,161.660000000000];
v = [0,0,0.464601238374681,0.929755484255206,1.39546164308871,1.86171861902337,2.79588063231313,3.73223273143554,4.20122730982987,5.14084800633951,6.08263671695609,7.02658457720498,8.44653533211063,9.39584215120541,10.3472769347812,11.3008307275720,12.7351149203275,13.6939269261834,14.6548264413097,16.1000700040090,16.5828518024014,18.0342831256240,18.5191184145376,19.4903194207480,20.4635533783748,20.9509298520746,21.9271960550294,22.9054722725899,23.8857492968480,24.3766352288654,25.8522688397480,25.8522688397480,26.3451347901984,26.8384928487593,27.8266806453806,28.3215080581393,28.8168229284115,29.3126240906732,29.8089103782565,30.3056806233516,30.8029336570103,30.8029336570103,31.3006683091478,31.7988834085470,31.7988834085470,32.2975777828593,32.2975777828593,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,32.7967502586087,31.7988834085470,31.3006683091478,30.3056806233516,29.3126240906732,27.8266806453806,26.8384928487593,24.8680179010629,22.9054722725899,21.4388111269700,19.0044642269341,17.5499595010577,15.1360561892542,11.3008307275720,8.92092218717511,6.08263671695609,3.26378347149450,1.86171861902337,1.39546164308871,1.39546164308871,1.39546164308871];
idx=x==circshift(x,1); % Index for second position of the duplicated x value
x(idx)=x(idx)+0.001; % Add a tiny value 0.001 to the second duplicated value
xq=0:0.1:ceil(x(end)); % Fine step size of 0.1
vq = interp1(x,v,xq,'linear'); % Do interpolation
plot(x,v);
hold on;
plot(xq,smoothdata(vq,'rloess')); % Smooth data using function smoothdata

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by