// // Programmer: Craig Stuart Sapp // Creation Date: Sun Sep 30 23:06:34 PDT 2007 // Last Modified: Sun Sep 30 23:06:40 PDT 2007 // Last Modified: Sat Apr 12 21:00:21 PDT 2008 (added -a and -A options) // Filename: ...sig/examples/all/smoother.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/smoother.cpp // Syntax: C++; museinfo // // Description: Smoothes data with exponential smoothing filter. // #include "humdrum.h" #include #ifndef OLDCPP using namespace std; #endif /////////////////////////////////////////////////////////////////////////// // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processFileBasic (HumdrumFile& infile); void processFileSmoothAll(HumdrumFile& infile); void processFileDesmoothAll(HumdrumFile& infile); void fillDesmooth (Array& sequence, int spine, HumdrumFile& infile); void fillSmooth (Array& sequence, int spine, HumdrumFile& infile); // global variables Options options; // database for command-line arguments double sgain = 0.5; // used with -s option (smoothing amount) double allsmoothQ = 0; // used with -a option double allresidueQ = 0; // used with -A option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; // process the command-line options checkOptions(options, argc, argv); string filename; infile.clear(); // if no command-line arguments read data file from standard input int numinputs = options.getArgCount(); if (numinputs < 1) { infile.read(cin); } else { filename = options.getArg(1); infile.read(filename.c_str()); } if (allsmoothQ) { processFileSmoothAll(infile); } else if (allresidueQ) { processFileDesmoothAll(infile); } else { processFileBasic(infile); } } /////////////////////////////////////////////////////////////////////////// /////////////////////////////// // // processFileSmoothAll -- // void processFileSmoothAll(HumdrumFile& infile) { Array > spines; spines.setSize(infile.getMaxTracks()); int i; for (i=0; i pointers; pointers.setSize(spines.getSize()); pointers.allowGrowth(0); pointers.setAll(0); int jsize; int j; for (i=0; i& sequence, int spine, HumdrumFile& infile) { sequence.setSize(infile.getNumLines()); sequence.setSize(0); double value; int i; for (i=0; i smoothed; smoothed.setSize(thesize); double filterk = sgain; double oneminusk = 1.0 - filterk; // reverse filtering first smoothed[thesize-1] = sequence[thesize-1]; for (i=thesize-2; i>=0; i--) { smoothed[i] = filterk*sequence[i] + oneminusk*smoothed[i+1]; } // then forward filtering for (i=1; i sequence; sequence.setSize(infile.getNumLines()); sequence.setSize(0); double value; int i; for (i=0; i smoothed; smoothed.setSize(thesize); double filterk = sgain; double oneminusk = 1.0 - filterk; // reverse filtering first smoothed[thesize-1] = sequence[thesize-1]; for (i=thesize-2; i>=0; i--) { smoothed[i] = filterk*sequence[i] + oneminusk*smoothed[i+1]; } // then forward filtering for (i=1; i