Suppose there are two curves (described by two groups of data): curve 1 and curve 2. The two curves have more than two intersection points. A new curve 3 is obtained by keeping the upper part of the two curves. The problem is that there are several sharp corners at the intersection points on curve 3. How to smooth the curve by rounding off these corners using matlab?
How to round off a curve (remove sharp corners) in matlab
2.9k Views Asked by open0121 At
2
There are 2 best solutions below
4

Borrowing from Luis Mendo's post and your comments in his post, if you are given 2D data where each column is a single vector and you want to filter each of the columns separately, then use filter
instead. You'd specify the dimension to be 1
, as you want to filter along the rows. As such:
%// adjust as needed
n = 4;
smooth_curve = filter(ones(1,n)/n, 1, u, [], 1);
Apply a convolution with a lowpass filter?
A better idea, as noted by @Hoki, is to apply the filter twice: once forwards and once backwards, to make the smoothing operation symmetric. You can achieve that with
filtfilt
: