#! /usr/local/bin/pvtool

#define USAGE_MESSAGE "\
\tstripenv <pv input file> <pv output file> [<threshold scalar>]\n\
\n\
This program removes the spectral envelope of sorts from an fft file. This\n\
new file can have a new envelope superimposed on it. This utility is the\n\
complement of makeenv and applyenv can be used to recombine the components.\n\
Threshold is as defined for makeenv and the default value is 0.1\n"

#define DEFAULT_THRESHOLD_SCALAR 0.1

/*****************************************************************************/

int
pvaction (void)
{
  int i, j;
  float threshold_scalar, sc;

  if (parameter_count >= 1)
    {
      threshold_scalar = fparameter[0];
      printf ("Using threshold value %f.\n", threshold_scalar);
    }
  else
    threshold_scalar = DEFAULT_THRESHOLD_SCALAR;

  for (i = 0; i < OUTPUT_FRAMES; i++)
    {
      for (j = 0; j < bins; j++)
	{
	  OUTPUT_PHIDOT (i, j) = INPUT1_PHIDOT (i, j);
	  OUTPUT_MAG (i, j) =
	    spectral_envelope_independent_component
	    (1, i, j, threshold_scalar);
	}
    }
  return (0);
}
