[Math] smoothing linear graph but keep the spikes

graphing-functionslinear algebralinear programming

how can I smooth a linear graph, but keep the spikes ?

the graph are speed points per second, so it goes up and down frequently (like sinus curve), but sometimes there are spikes, like the speed reaches a maximum for just one second and in the next two seconds it went down to zero.
when I try to smooth the graph with moving averages, I destroy this short spikes, and the graph really looks like a sinus curve.

What i need is this smooth curve, but when there is a max speed, the curve should show it, and also if there is a short acceleration or stop, I would still like to see this.

an idea I had, is to first identify the spikes.
then identify big differences within a short time mac 5s.
now I do moving average, when i came close to either a spike or big difference, I use this point instead of moving average.

but this fells not right, and also complicated.
probably there is a much better solution for it ?

and I guess this one is not working for my second graph, which is like a heartbeat graph. here I just want to display the heartbeat as a sinus like curve (data should be like that) but also keep the very short spikes.

(I'm not a mathematician, please try to explain possible answer that I can also understand them)

Update

here is an example. the blue one is of my first type and the green one is the second type.
http://i.stack.imgur.com/VQ4V4.jpg

Best Answer

The first think you need to decide on is what is a spike and what is not. Consider the following graphs, surely there are spikes on left-most one, but what about the right one? If these are spikes, then how would you smooth that graph without increasing the sampling frequency? If these are not spikes, then what about the graphs in the middle, where do you put the threshold?

spikes graph

If your data is not too big, then as a first approach I would recommend using Fourier transform - for example by cutting the high frequencies you make your graph less jagged and you should be able to keep the significant spikes. Of course, some especially thin spikes might get removed, but this is, among others, what "less jagged" means.

I hope this helps $\ddot\smile$