how to smooth the data of array to get a smooth surface?
Show older comments
how i can remove outliers in data and get a smooth surface?1 Comment
William Rose
on 8 Mar 2023
@Abdullah, Please attach the data as a .mat file.
Answers (2)
William Rose
on 8 Mar 2023
0 votes
Check this out:
Or do a median filter, in which each point is replaced by the median of a pxp array centered on that point.
@Abdullah, an example of a median filter for a surface:
First, make a surface with some "noise":
A=repmat(-(-20:20).^2/400,31,1)+repmat([-(-15:15).^2/225]',1,41)+2+(rand(31,41)>.95)/5;
mesh(-20:20,-15:15,A) %display the surface
Filter it with a pxp median filter
p=5; p2=floor(p/2); [n,m]=size(A);
B=zeros(n,m); %allocate array for smoothed surface
for i=1+p2:n-p2
for j=1+p2:m-p2
B(i,j)=median(median(A(i-p2:i+p2,j-p2:j+p2)));
end
end
mesh(-20:20,-15:15,B) %display the surface
The edges are zeros in my simple code, because, if the filter gets any closer to the edges, it will extend beyond the bounds of the original array, which would cause an error. You could improve this by adapting the filter as needed, when it gets near the edge.
5 Comments
William Rose
on 8 Mar 2023
Simple median filter (same as the one in answer above), that stays clear of the edges. This leaves a rim of zeros around the edges:
for i=1+p2:n-p2
for j=1+p2:m-p2
B(i,j)=median(median(A(i-p2:i+p2,j-p2:j+p2)));
end
end
A filter that goes right up to the edges is below.
for i=1:n
for j=1:m
B(i,j)=median(median(A(max(i-p2,1):min(i+p2,n),max(j-p2,1):min(j+p2,m))));
end
end
Abdullah
on 8 Mar 2023
William Rose
on 8 Mar 2023
@Abdullah, the area in yellow is elevated relative to the smooth contour of the other parts of the surface. You are correct that this elevated region is likely to remain elevated even after filtering. Filtering could make this region smoother, but the region will still be elevated. The behavior of the surface in the yellow area does not appear to be random variation. It looks more like a deterministic difference in the response of the system, when the RPM and torque are in this range of values. Therefore I recommend investigating why the system repsonse is different in this region.
Abdullah
on 9 Mar 2023
William Rose
on 9 Mar 2023
@Abdullah, you;re welcome. Good luck with your work.
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

