2

Imagine I have a data set which gives me the following ListLinePlot

enter image description here

Is it possible to define a function over the data set that removes the "spikes" observed in the data and smoothens the plot, for a given threshold?

sam wolfe
  • 4,663
  • 7
  • 37
  • Please look at examples from the GaussianFilter docs pages under Applications. – Syed Nov 07 '22 at 17:08
  • 1
    see also moving average. – Nasser Nov 07 '22 at 17:13
  • 4
    Is there a known reason why there are spikes? I ask because it doesn't appear that there's just one odd point involved but leading up to the spike and trailing the spike there are many points that seem to imply that a spike is a real thing. Providing sample data would be helpful but the appropriateness of any "solution" will depend on why the phenomenon exists. – JimB Nov 07 '22 at 17:14
  • @JimB The function looks like a Fourier transform of some signal. – yarchik Nov 07 '22 at 20:30
  • @yarchik I believe you. My point in my comment is that the goodness of a smoothing is not an intrinsic property of the data. Subject matter and the objective can supply that information as opposed to a "I'll know it when I see it" approach. Data is (are?) good but not completely sufficient. – JimB Nov 07 '22 at 22:33
  • Can you please share the raw data? – IntroductionToProbability Nov 09 '22 at 10:49
  • related https://mathematica.stackexchange.com/questions/88112/how-to-smooth-the-noise and https://reference.wolfram.com/language/guide/DataTransformsAndSmoothing.html – IntroductionToProbability Nov 09 '22 at 10:53
  • Related to my first comment: Are the spikes the issue or the troughs the issue? Again, that would depend on what process is generating the data which should be described. – JimB Mar 28 '24 at 04:33

2 Answers2

3
data = 
 Table[Evaluate @ Re @ FourierSeries[t^5, t, 4], {t, -3. Pi, 3. Pi, 6. Pi/128}];

Using GaussianFilter

ListLinePlot[Table[GaussianFilter[data, n], {n, {0, 6, 12, 24}}],
 PlotLegends -> {"data", 6, 12, 24},
 PlotRange -> All]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168
1
data = 
 Table[Evaluate@Re@FourierSeries[t^5, t, 4], {t, -3.  π, 3.  π, 6.  π/128}];

Grabbing the @eldo's data and using LowpassFilter:

smoothedData = LowpassFilter[data, 0.3];

ListLinePlot[{data, smoothedData}, PlotLegends -> {"Original Data", "Smoothed Data"}, PlotRange -> All]

enter image description here

E. Chan-López
  • 23,117
  • 3
  • 21
  • 44