4 //Adapted from Signal.hh in ilr (Simon)
6 #include "clitkCommon.h"
9 //include external library
15 #include "itkImageRegionConstIterator.h"
16 #include "itkPointSet.h"
17 // #include "itkBSplineScatteredDataPointSetToImageFilter.h"
26 //=====================================================================================
28 typedef double SignalValueType;
29 typedef vector< SignalValueType > SignalType;
30 typedef SignalType::iterator iterator;
31 typedef SignalType::const_iterator const_iterator;
32 //typedef vector< complex<double> > SIGNAL_FFT_TYPE;
34 typedef itk::Image<double,1> ImageType;
35 typedef itk::Vector<double,1> VectorType;
36 typedef itk::Image<VectorType,1> VectorImageType;
38 //=====================================================================================
39 //Constructors - Destructors
40 Signal(){SetSamplingPeriod(1.);}
41 Signal(double sp):m_SamplingPeriod(sp){;}
42 Signal(const string fileName){Read(fileName);}
43 Signal(unsigned int size, SignalValueType voidValue=0.)
45 m_Data.resize(size,voidValue);
48 Signal(const Signal & s);
52 //=====================================================================================
54 void Read(string fileName);
55 bool Read(string fileName, int col);
56 void ReadXDR(string fileName);
57 void Write(const string fileName);
59 //=====================================================================================
60 //Common vector properties for signals
61 unsigned int size() const {return m_Data.size();}
62 iterator begin(){return m_Data.begin();}
63 iterator end() {return m_Data.end();}
64 const_iterator begin() const {return m_Data.begin();}
65 const_iterator end() const {return m_Data.end();}
66 SignalValueType front() {return m_Data.front();}
67 SignalValueType back() {return m_Data.back();}
68 void push_back(SignalValueType value){return m_Data.push_back(value);}
69 void resize(unsigned int newSize){return m_Data.resize(newSize);}
70 void clear(){m_Data.clear();}
72 void print(ostream & os = cout, const int level = 0) const;
74 //=====================================================================================
76 SignalValueType& operator[](int index){return m_Data[index];}
77 const SignalValueType& operator[](int index) const {return m_Data[index];}
78 Signal & operator/=(Signal & d);
79 Signal & operator*=(Signal & d);
82 void CopyFrom(const Signal & s);
83 Signal Normalize(double newMin=0.,double newMax=1.);
84 vector<double> GetGlobalMinMax() const;
85 double GetGlobalMean() const;
86 Signal MovingAverageFilter ( unsigned int length);
87 Signal GaussLikeFilter ();
88 Signal NormalizeMeanStdDev(double newMean=0.5,double newStdDev=0.5);
89 //Signal HighPassFilter (double sampPeriod, double cutOffFrequency );
90 //Signal LowPassFilter (double sampPeriod, double cutOffFrequency );
91 //double MaxFreq(const Signal &sig,SIGNAL_FFT_TYPE & fft);
92 //void OneDForwardFourier(const Signal& input,SIGNAL_FFT_TYPE & fft);
93 //void OneDBackwardFourier(SIGNAL_FFT_TYPE & fft, Signal &output);
94 Signal DetectLocalExtrema(unsigned int width);
97 Signal MonPhaseDE(double ee, double ei);
98 double SSD(const Signal &sig2) const;
99 Signal LinearlyInterpolateScatteredValues();
100 // Signal ApproximateScatteredValuesWithBSplines (unsigned int splineOrder, unsigned int numberOfControlPoints);
101 Signal LimitSignalRange();
103 void AddValue(double v);
104 void ComputeAugmentedSpace(Signal & outputX, Signal & outputY, unsigned int delay) const;
106 void ResampleWithTimeWarpTo(clitk::Signal & output, bool lin=false) const ;
107 double GetValueAtNN(double t) const;
108 double GetValueAtLin(double t) const;
109 void Shift(int s, int length);
111 double GetTotalTimeDuration() const { return size()*GetSamplingPeriod(); }
112 double UnormalizedXcov(const Signal &, Signal &) const;
113 Signal Xcov(const Signal &, int &, double &, double &);
114 double UnormalizedCorrelation(const Signal &input2) const;
115 double Correlation(const Signal &input2) const;
117 // double Compare(Signal & sigRef);
118 // int DerivateSigne( const_iterator & it) const;
119 // void CenteredFiniteDifferences(Signal & result,int order,int* weights);
120 // void FirstDerivate(Signal & result,int order);
121 // void SecondDerivate(Signal & result,int order);
123 // void Crop(unsigned int posmin, unsigned int posmax);
124 // void LinearResample(const unsigned int newSize);
127 //=====================================================================================
128 // Get and Set function
129 double GetSamplingPeriod() const {return m_SamplingPeriod;}
130 void SetSamplingPeriod(double sp){m_SamplingPeriod=sp;}
132 //=====================================================================================
133 //Conversion for using itk filters
134 Signal ConvertImageToSignal(ImageType::Pointer image);
135 ImageType::Pointer ConvertSignalToImage( Signal);
136 Signal ConvertVectorImageToSignal (VectorImageType::Pointer m);
140 double m_SamplingPeriod;