name: Spectrum : public AlgorithmBase
synopsis:

>     g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_algo.a

>     #include <Spectrum.h>

>     Spectrum();
>     Spectrum(const Spectrum& arg);
>     boolean eq(const Spectrum& arg);
>     boolean setAlgorithm(ALGORITHM algorithm);
>     boolean setFtOrder(long order);

quick start:

>     VectorFloat input;
>     VectorFloat output;
>     Spectrum spec;
>     input.assign(L"1.0, 2,0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0");
>     spec.compute(output, input);

description:
The Spectrum class is used to calculate the spectrum of given data. The input data can be sampled data, linear prediction coefficients, linear reflection coefficients or correlation coefficients. The output spectrum can be complex or magnitude spectrum. The table below is provided for reference purposes:
dependencies:

- AlgorithmBase
- FourierTransform
- MemoryManager
- Prediction
- Correlation
- Reflection

public constants:

- define the class name:

      static const String CLASS_NAME = L"Spectrum";

- define the algorithm choices:

      enum ALGORITHM { FOURIER = 0, MAXIMUM_ENTROPY, DEF_ALGORITHM = FOURIER };

- define the implementation choices:

      enum IMPLEMENTATION { MAGNITUDE = 0, COMPLEX, DEF_IMPLEMENTATION = MAGNITUDE };

- define the static NameMap objects:

      static const NameMap ALGO_MAP = L"FOURIER, MAXIMUM_ENTROPY";

      static const NameMap IMPL_MAP = L"MAGNITUDE, COMPLEX";

- define maximum entropy spectrum scale:

      static const Float MAGNITUDE_SCALE = 10;

      static const ComplexFloat COMPLEX_SCALE = -20;

- define i/o related constants:

      static const String DEF_PARAM = L"";

      static const String PARAM_ALGORITHM = L"algorithm";

      static const String PARAM_IMPLEMENTATION = L"implementation";

      static const String PARAM_DYN_RANGE = L"dynamic_range";

      static const String PARAM_FT = L"ft";

- default arguments to methods:

      static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::SIGNAL;

error codes:

- error code indicating Spectrum class general error:

      static const long ERR = 71600;

protected data:

- algorithm name:

      ALGORITHM algorithm_d;

- implementation name:

      IMPLEMENTATION implementation_d;

- parameters related to the alogorithm specification:

      Float dyn_range_d;

- a FourierTransform object:

      FourierTransform ft_d;

- static memory manager:

      static MemoryManager mgr_d;

required public methods:

- static methods:

      static const String& name();

      static boolean diagnose(Integral::DEBUG debug_level);

- debug methods: setDebug method is inherited from the base class

      boolean debug(const unichar* message) const;

- destructor/constructor(s):

      ~Spectrum();

      Spectrum(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, float dyn_range = Prediction::DEF_DYN_RANGE);

      Spectrum(const Spectrum& arg);

- assign methods: boolean assign(const Spectrum& arg);
- operator= methods:

      Spectrum& operator= (const Spectrum& arg);

- i/o methods:

      long sofSize() const;

      boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);

      boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;

      boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

- equality methods:

      boolean eq(const Spectrum& arg) const;

- memory management methods:

      static void* operator new(size_t size);

      static void* operator new[](size_t size);

      static void operator delete(void* ptr);

      static void operator delete[](void* ptr);

      static boolean setGrowSize(long grow_size);

      boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);

class-specific public methods:

- set methods:

      boolean setAlgorithm(ALGORITHM algorithm);

      boolean setImplementation(IMPLEMENTATION implementation);

      boolean setDynRange(float dyn_range);

      boolean setFtAlgorithm(FourierTransform::ALGORITHM algorithm);

      boolean setFtImplementation(FourierTransform::IMPLEMENTATION implementation);

      boolean setFtOrder(long order);

      boolean set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, float dyn_range = Prediction::DEF_DYN_RANGE, FourierTransform::ALGORITHM ft_algorithm = FourierTransform::DEF_ALGORITHM, FourierTransform::IMPLEMENTATION ft_implementation = FourierTransform::DEF_IMPLEMENTATION, long order = FourierTransform::DEF_ORDER);

- get methods:

      ALGORITHM getAlgorithm() const;

      IMPLEMENTATION getImplementation() const;

      float getDynRange() const

      FourierTransform::ALGORITHM getFtAlgorithm() const;

      FourierTransform::IMPLEMENTATION getImplementation() const;

      long getFtOrder() const

      boolean get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, float& dyn_range, FourierTransform::ALGORITHM& ft_algorithm, FourierTransform::IMPLEMENTATION& ft_implementation, long& order) const;

- computational methods:

      boolean compute(VectorFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE coef_type = DEF_COEF_TYPE, long index = DEF_CHANNEL_INDEX);

      boolean compute(VectorComplexFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE coef_type = DEF_COEF_TYPE, long index = DEF_CHANNEL_INDEX);

- AlgorithmBase interface contract methods:

      boolean assign(const AlgorithmBase& arg);

      boolean eq(const AlgorithmBase& arg) const;

      const String& className() const;

      boolean apply(Vector<AlgorithmData>& output, const Vector<CircularBuffer<AlgorithmData>>& input);

      boolean setParser(SofParser* parser);

private methods:

- common i/o methods:

      boolean readDataCommon(Sof& sof, const String& pname, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeDataCommon(Sof& sof, const String& pname = DEF_PARAM) const;

- algorithm-specific computational methods: FOURIER/MAGNITUDE

      boolean computeFourierMag(VectorFloat& output, const VectorFloat& input);

- algorithm-specific computational methods: FOURIER/COMPLEX

      boolean computeFourierComplex(VectorComplexFloat& output, const VectorFloat& input);

- algorithm-specific computational methods: MAXIMUM_ENTROPY/MAGNITUDE

      boolean computeReflectionMag(VectorFloat& output, const VectorFloat& input, double range = Prediction::DEF_DYNAMIC_RANGE);

      boolean computePredictionMag(VectorFloat& output, const VectorFloat& input);

      boolean computeCorrelationMag(VectorFloat& output, const VectorFloat& input, double range = Prediction::DEF_DYNAMIC_RANGE);

- algorithm-specific computational methods: MAXIMUM_ENTROPY/COMPLEX

      boolean computeReflectionComplex(VectorComplexFloat& output, const VectorFloat& input, double range = Prediction::DEF_DYNAMIC_RANGE);

      boolean computePredictionComplex(VectorComplexFloat& output, const VectorFloat& input);

      boolean computeCorrelationComplex(VectorComplexFloat& output, const VectorFloat& input, double range = Prediction::DEF_DYNAMIC_RANGE);

examples:

- This example shows how to compute the spectrum of the sampled data:

      // isip include files
      //
      #include <Spectrum.h>

      // main program starts here
      //
      int main(int argc, const char **argv) {

        // declare a Spectrum object and an output vector
        //
        Spectrum spectrum;
        VectorFloat output;

        // generate 30 ms sine wave of frequency 1000Hz
        //
        long sample_freq = 8000;
        long num_samples  = 240;

        // set the input vector
        //
        VectorFloat input(num_samples);
        double step = Integral::TWO_PI * 1000.0 / (double)sample_freq;
        input.ramp(0, step);
        input.sin();

        // set algorithm and implementation
        //
        spectrum.setAlgorithm(Spectrum::FOURIER);
        spectrum.setImplementation(Spectrum::MAGNITUDE);

        // set the algorithm, implementation and order of the underlying
        // FourierTransform object
        //
        spectrum.setFtAlgorithm(FourierTransform::FFT);
        spectrum.setFtImplementation(FourierTransform::SPLIT_RADIX);
        spectrum.setFtOrder((long)256);

        // compute the spectrum of input data
        //
        spectrum.compute(output, input);

        input.debug(L"input");
        spectrum.debug(L"spectrum");
        output.debug(L"output");

        // exit gracefully
        //
        Integral::exit();
      }

notes:

- none