/octave-smoothing.m

https://github.com/johnlawrenceaspden/hobby-code · Objective C · 21 lines · 13 code · 8 blank · 0 comment · 1 complexity · 2068aa0175d597ee8368ef91184da22d MD5 · raw file

  1. # Octave doesn't have MATLAB's smooth function, but if you install octave-forge's signal toolbox
  2. # then it has a function to do Savitsky-Golay smoothing
  3. # $ sudo apt-get install octave-signal
  4. # square wave
  5. x = [zeros(1,15), 10*ones(1,10), zeros(1,15)];
  6. plot(x);
  7. # an order 5 butterworth filter
  8. [b, a] = butter (5, 1/3);
  9. butterworth=filtfilt (b, a, x);
  10. plot (sgolayfilt (x), "r;sgolayfilt;", ...
  11. filtfilt (ones (1,5)/5, 1, x), "g;5 sample average;", ...
  12. butterworth, "c;order 5 butterworth;", ...
  13. x, "+b;original data;");