Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #2634
| Newsgroups | comp.graphics.apps.gnuplot |
|---|---|
| Date | 2014-11-07 06:38 -0800 |
| Message-ID | <63da4eac-2fda-4782-b6da-46b93921e95c@googlegroups.com> (permalink) |
| Subject | SMA (Simple Moving Average) inside gnuplot, ONLY AS LAST resort |
| From | Kalin Kozhuharov <me.kalin@gmail.com> |
Hello, I have been thinking whether to post this or not for some time, but I decided to do it. It is generally a bad practice to abuse tools for what they are not meant to be, so use that only in a pinch. It is almost always a better idea to compute SMA in something like Perl before feeding your data to gnuplot, trust me. I just switched to such implementation myself ;-) But if you like hacking and inline messy code, here is a bash script that will generate gnuplot code for SMA with 2 to 53 bins (due to alphabet limitations; may be extended). https://github.com/thinrope/fixed_sensor_visualization/blob/master/SMA_gen.sh I will probably leave it there for quite some time (I am not using it anymore), but just in case the revision link: https://github.com/thinrope/fixed_sensor_visualization/blob/bbd373c355648220b419d71facd743a536e3a341/SMA_gen.sh It generates a code like that (for 3-bin and 6-bin): sma_3_init(x) = (b3=b2=b1=x); sma_3_shift(x) = (b3=b2,b2=b1,b1=x); sma_3_samples(x) = $0 > 2 ? 3 : ($0+1); sma_3_RO(x) = (b3+b2+b1)/sma_3_samples($0); sma_3(x) = (sma_3_shift(x), sma_3_RO(x)); sma_6_init(x) = (e6=e5=e4=e3=e2=e1=x); sma_6_shift(x) = (e6=e5,e5=e4,e4=e3,e3=e2,e2=e1,e1=x); sma_6_samples(x) = $0 > 5 ? 6 : ($0+1); sma_6_RO(x) = (e6+e5+e4+e3+e2+e1)/sma_6_samples($0); sma_6(x) = (sma_6_shift(x), sma_6_RO(x)); Then you can use it like: plot e=sma_6_init(0) "some_file" u 1:2 w p, "" u 1:(sma_6($2)) w l I wrote this script while debugging 24-bin SMA for the code used to generate some radiation sensor time-charts (http://gamma.tar.bz/nGeigies/) and it was working for some time, but I finally moved away from it. Hope I don't stir the pot too much, be happy and consider using the right tools for the job :-) Kalin.
Back to comp.graphics.apps.gnuplot | Previous | Next — Next in thread | Find similar | Unroll thread
SMA (Simple Moving Average) inside gnuplot, ONLY AS LAST resort Kalin Kozhuharov <me.kalin@gmail.com> - 2014-11-07 06:38 -0800 Re: SMA (Simple Moving Average) inside gnuplot, ONLY AS LAST resort Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2014-11-07 16:04 +0100
csiph-web