SpectrumFunc.hh 4.27 KB
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   SpectrumFunc.hh
 * Author: hacene
 *
 * Created on November 10, 2021, 4:54 PM
 */

#ifndef SPECTRUMFUNC_HH
#define SPECTRUMFUNC_HH

#include <c++/4.8.2/bits/stl_vector.h>
#include <c++/4.8.2/bits/stl_pair.h>
#include <c++/4.8.2/complex>
#include <c++/4.8.2/bits/stl_list.h>
#include <c++/4.8.2/bits/stl_bvector.h>


namespace AMDA {
    namespace Parameters {
        namespace StatisticFunctions {

            template <typename InputElemType>
            std::vector<double> fft(int N, std::vector<InputElemType> &xn) {
                /**
                 * 
                 * @param N number of points in the dft
                 * @param xn date vector 
                 */

                int len = xn.size();
                std::vector<double> output;
                output.resize(N);
                output << NotANumber();

                double Xr;
                double Xi;
                int counter;

                int k, n = 0;
                for (k = 0; k < N; k++) {
                    Xr = 0;
                    Xi = 0;
                    counter = 0;
                    for (n = 0; n < len; n++) {
                        if (!isNAN(xn[n])) {
                            Xr = Xr + (double) xn[n] * cos(2 * 3.141592 * k * n / N);
                            Xi = Xi + (double) xn[n] * sin(2 * 3.141592 * k * n / N);
                            counter += 1;
                        }
                    }
                    if (counter == 0)
                        break;
                    output[k] = std::sqrt(Xr * Xr + Xi * Xi);
                }
                return output;
            }

            template <typename InputElemType>
            std::vector<double> getUniformData(std::list<std::pair<double, InputElemType>>&mem, double sampling, double windowtime) {
                bool constantSampling = true;
                auto it_1 = mem.begin();
                it_1++;
                for (auto it = mem.begin(); it != mem.end(); it++) {
                    if (*it != mem.back()) {
                        InputElemType first = it->first;
                        InputElemType second = it_1->first;
                        it_1++;
                        if (second - first != sampling)
                            constantSampling = false;
                    }
                }

                std::vector<double> vals_;
                for (auto val : mem) {
                    vals_.push_back((double) val.second);
                }
                return vals_;
            }

            template <typename InputElemType>
            std::vector<double> computeFourierSpectrum(std::list<std::pair<double, InputElemType>>&mem, double sampling, double windowtime) {

                std::vector<double> result;


                if (mem.empty())
                    return result;
                
                return result;
            }

            /**
             * @class SpectrumFunc
             * @brief 
             * @details This class implements AbstractFunc.
             */
            template <typename InputElemType>
            class SpectrumFunc : public ClassicAbstractFunc<InputElemType, std::vector<double>>
            {
                public:

                /**
                 * @brief Constructor.
                 */
                SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec<InputElemType>& paramInput, double windowtime)
                        : ClassicAbstractFunc<InputElemType, std::vector<double>>(pProcess, pTimeIntervalList, paramInput, windowtime),
                        _min_sampling(paramInput.getMinSampling()),
                        _windowtime(windowtime) {
                }

                virtual ~SpectrumFunc() {
                }

                std::vector<double> compute() {
                    return computeFourierSpectrum(ClassicAbstractFunc<InputElemType, std::vector<double>>::_mem, _min_sampling, _windowtime);
                }
                private:
                double _min_sampling;
                double _windowtime;
            };


        }
    }
}

#endif /* SPECTRUMFUNC_HH */