Skip to content
Snippets Groups Projects
AutoCorrEstimator.h 2.64 KiB
Newer Older
Stephen Smith's avatar
Stephen Smith committed
/*  AutoCorrEstimator.h

    Mark Woolrich, FMRIB Image Analysis Group

    Copyright (C) 1999-2000 University of Oxford  */

/*  CCOPYRIGHT  */

Mark Woolrich's avatar
Mark Woolrich committed
#if !defined(__AutoCorrEstimator_h)
#define __AutoCorrEstimator_h

#include <iostream>
#include <fstream>
Stephen Smith's avatar
Stephen Smith committed
#define WANT_STREAM
#define WANT_MATH

#include "miscmaths/miscmaths.h"
#include "newimage/newimageall.h"
Stephen Smith's avatar
Stephen Smith committed

using namespace NEWMAT;
David Flitney's avatar
David Flitney committed
using namespace MISCMATHS;
using namespace NEWIMAGE;
Mark Woolrich's avatar
Mark Woolrich committed

namespace FILM {
     
Stephen Smith's avatar
Stephen Smith committed
  class AutoCorrEstimator
    {
    public:
      AutoCorrEstimator(const Matrix& pxdata) : 
        sizeTS(pxdata.Nrows()),
	numTS(pxdata.Ncols()),
Stephen Smith's avatar
Stephen Smith committed
	xdata(pxdata),
	acEst(pxdata.Nrows(), pxdata.Ncols()),
Stephen Smith's avatar
Stephen Smith committed
	vrow(),
	xrow(),
	dummy(),
	realifft(), 
Mark Woolrich's avatar
Mark Woolrich committed
	dm_mn(),
Stephen Smith's avatar
Stephen Smith committed
	zeropad(0)
	{ 
	  zeropad = MISCMATHS::nextpow2(pxdata.Nrows());
Stephen Smith's avatar
Stephen Smith committed
	  vrow.ReSize(zeropad);
	  xrow.ReSize(zeropad);
	  dummy.ReSize(zeropad);
	  realifft.ReSize(zeropad);
Mark Woolrich's avatar
Mark Woolrich committed
	  countLargeE.ReSize(zeropad);
	  countLargeE = 0;
Mark Woolrich's avatar
Mark Woolrich committed
	  acEst = 0;
	  acEst.Row(1) = 1;
Stephen Smith's avatar
Stephen Smith committed
	}

Mark Woolrich's avatar
Mark Woolrich committed
      void calcRaw(int lag = 0);
      void spatiallySmooth(const string& usanfname, const ColumnVector& epivol, int masksize, const string& epifname, int usanthresh, int lag=0);
Stephen Smith's avatar
Stephen Smith committed
      void applyConstraints();
      void filter(const ColumnVector& filterFFT);
      Matrix fitAutoRegressiveModel();
Stephen Smith's avatar
Stephen Smith committed
      void pava();
      //void preWhiten(VolumeSeries& in, VolumeSeries& ret);
Mark Woolrich's avatar
Mark Woolrich committed
      void preWhiten(ColumnVector& in, ColumnVector& ret, int i, Matrix& dmret, bool highfreqremovalonly=false);
Stephen Smith's avatar
Stephen Smith committed
      void setDesignMatrix(const Matrix& dm);
      int establishUsanThresh(const ColumnVector& epivol);
Stephen Smith's avatar
Stephen Smith committed

      void getMeanEstimate(ColumnVector& ret);

      Matrix& getEstimates() { return acEst; }
      Matrix& getE() { return E; }
Mark Woolrich's avatar
Mark Woolrich committed
      ColumnVector& getCountLargeE(){ return countLargeE; }

      int getZeroPad() { return zeropad; }
      void tukey(int M);
      void multitaper(int M);
Mark Woolrich's avatar
Mark Woolrich committed
      int pacf(const ColumnVector& x, int minorder, int maxorder, ColumnVector& betas);
Stephen Smith's avatar
Stephen Smith committed

    private:
      const int sizeTS;
      const int numTS;
Stephen Smith's avatar
Stephen Smith committed
      AutoCorrEstimator();
      const AutoCorrEstimator& operator=(AutoCorrEstimator&);
      AutoCorrEstimator(AutoCorrEstimator&);
Mark Woolrich's avatar
Mark Woolrich committed
      void getSlepians(int M, int sizeTS, Matrix& slepians);
Stephen Smith's avatar
Stephen Smith committed

      const Matrix& xdata;
      Matrix acEst;
Mark Woolrich's avatar
Mark Woolrich committed
      ColumnVector countLargeE;
Stephen Smith's avatar
Stephen Smith committed

      Matrix dminFFTReal;
      Matrix dminFFTImag;
Stephen Smith's avatar
Stephen Smith committed

      ColumnVector vrow;
      ColumnVector xrow;     

      ColumnVector dm_fft_real, dm_fft_imag;
      ColumnVector x_fft_real, ac_fft_real;
      ColumnVector x_fft_im, ac_fft_im;
     
      ColumnVector dummy;
      ColumnVector realifft;
Mark Woolrich's avatar
Mark Woolrich committed
      ColumnVector dm_mn;
Stephen Smith's avatar
Stephen Smith committed