I have a list of data points, {x, y}
, my data. When I plot them, the curve is jagged. I want to smooth the curve and preserve the two sharp corners. This is a plot of the raw data.
I have tried using low pass filters for a week, but the curve is still not very good.
data = Import["C:\\Users\\...\\Desktop\\my_data.dat"];
(*... denotes your name or so, pls import my data first *)
yy1 = Select[data, First @ # < 3.423 &];
(*get the data whose x < position of the first sharp *)
yy2 = Select[data, 3.423 < First @ # < 5.467 &];
(*get the data whose x between the two sharps *)
yy3 = Select[data, 5.467 < First @ # &];
(*get the data whose x > position of the second sharp *)
ListPlot @ Join[yy1, yy2, yy3]
My curve has lots of zigzags. The following is my low pass filter function.
smooth[data_, res_] := With[{
x = Map[First, data],
y = Map[Last, data],
len = Length@data},
Manipulate[
ListLinePlot @ (res = Thread[{x, LowpassFilter[y, ω, len]}]),
{{ω, 0.2}, 0, 0.5, 0.001}]]
Clear[rest1, rest2, rest3]
smooth[#, rest1] & @ yy1
smooth[#, rest2] & @ yy2
smooth[#, rest3] & @ yy3
After evaluating the above code, I can smooth the three parts of the zigzag curve separately. Then I combine them.
end = (restFinal = Join[rest1, rest2, rest3]) // ListLinePlot
As I said, the curve still doesn't look good enough. Some parts are changed inappropriately! What I want is something like this, which has been obtained by making a drawing :).
I just want to use some Mathematica plot tricks or some other approach that give me the smooth curve I am seeking.
MovingAverage
but that will change some features; for instance, the inversion points will not reach 0. $\endgroup$MovingAverage
just now, it do can make my curve smooth, but make my two inversion points away from zero. I just want to maintain the two inversion points as well as make the other part smooth. :) $\endgroup$