/*---------------------------------------------------------------------------* * IT++ * *---------------------------------------------------------------------------* * Copyright (c) 1995-2004 by Tony Ottosson, Thomas Eriksson, Pål Frenger, * * Tobias Ringström, and Jonas Samuelsson. * * * * Permission to use, copy, modify, and distribute this software and its * * documentation under the terms of the GNU General Public License is hereby * * granted. No representations are made about the suitability of this * * software for any purpose. It is provided "as is" without expressed or * * implied warranty. See the GNU General Public License for more details. * *---------------------------------------------------------------------------*/ /*! \file \brief Implementation of deterministic sources. \author Tobias Ringström and Tony Ottosson 1.6 2004/11/01 09:44:21 */ #include //#ifdef _MSC_VER //# include //# define getpid _getpid //#else //# include //#endif #include "base/binary.h" #include "base/matfunc.h" #include "base/scalfunc.h" #include "base/source.h" namespace itpp { #ifndef DOXYGEN_SHOULD_SKIP_THIS #ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 #endif #ifndef M_PI_4 #define M_PI_4 0.78539816339744830962 #endif #endif //DOXYGEN_SHOULD_SKIP_THIS /////////////////////////////////////////////// // Sine_Source /////////////////////////////////////////////// Sine_Source::Sine_Source(double freq, double mean, double ampl, double inphase) { A = ampl; m = mean; theta = inphase; dtheta = 2.0 * pi * freq; } double Sine_Source::sample() { double samp = m + A * sin(theta); theta += dtheta; if (theta >= 2.0 * pi) theta -= 2.0 * pi; return samp; } vec Sine_Source::operator()(int n) { vec v(n); for (int i=0; i= 1.0) theta -= 1.0; return samp; } vec Square_Source::operator()(int n) { vec v(n); for (int i=0; i= 0.75) theta -= 1.0; return samp; } vec Triangle_Source::operator()(int n) { vec v(n); for (int i=0; i= 0.5) theta -= 1.0; return samp; } vec Sawtooth_Source::operator()(int n) { vec v(n); for (int i=0; i= 1.0) { samp = A; pos -= 1.0; } else { samp = 0.0; pos += dtheta; } return samp; } vec Impulse_Source::operator()(int n) { vec v(n); for (int i=0; i=0; i--) { mean += pat(i); var += pat(i) * pat(i); } mean /= pat.size(); var /= pat.size(); var -= mean*mean; } double Pattern_Source::sample() { double samp = pat(pos); if (pos >= pat.size()-1) pos = 0; else pos++; return samp; } vec Pattern_Source::operator()(int n) { vec v(n); for (int i=0; i