Exemplo n.º 1
0
css::frequency css::frequency::as(const type aUnits) const
{
    static constexpr float hertz_in_kilohertz = 1000;

    switch (mUnits)
    {
    case hertz:
        switch (aUnits)
        {
        case hertz:
            return *this;
        case kilohertz:
            return frequency(mValue / hertz_in_kilohertz, aUnits);
        case inherit:
            break;
        }
        break;
    case kilohertz:
        switch (aUnits)
        {
        case hertz:
            return frequency(mValue * hertz_in_kilohertz, aUnits);
        case kilohertz:
            return *this;
        case inherit:
            break;
        }
        break;
    case inherit:
        break;
    }

    throw std::runtime_error("unable to convert to the specified units");
}
Exemplo n.º 2
0
 double CosinePoissonProcess::expected_number_of_events(
     const DateTime &t0, const DateTime &t1)const{
   double real_t0 = t0 - origin_;
   double real_t1 = t1 - origin_;
   double ans = lambda() * (real_t1 - real_t0);
   ans += (lambda()/frequency()) *
       (sin(frequency() * real_t1) - sin(frequency() * real_t0));
   return ans;
 }
Exemplo n.º 3
0
/// Play the A.B.C's with each single syllable letter replaced by the
/// corresponding Morse code. W is transmitted once for each syllable.
/// After Z, the remainder of the song is played as simple tones.
void txAlphabetSong(MorseToken) {
  uint32_t saveHz(getTxHz());
  int saveDitMicros(getDitMicros());
  const char* letters("ABCDEFGHIJKLMNOPQRSTUVWWWXY Z ");
  const char*
    notes("C42C42G42G42" "A52A52G44" "F42F42E42E42" "D41D41D41D41C44"
	  "G42G42F44"    "E42E42D44" "G41G41G42F44" "E42E42D44"
	  "C42C42G42G42" "A52A52G44" "F42F42E42E42" "D42D42C44");
  char* l(const_cast<char*>(letters));
  char* p(const_cast<char*>(notes));
  while (*p) {
    size_t steps[] = { 0, 2, 3, 5, 7, 8, 10 };
    size_t note(steps[p[0] - 'A'] + 12 * (p[1]-'0'));
    size_t frequency(noteHz[note] + 0.5);
    size_t duration(saveDitMicros * (p[2] - '0') * 2 / 3);
    char buffer[] = { '\0', ' ', '\0' };
    buffer[0] = l[0];
    if (l[1]) {
      setTxHz(frequency);
      setDitMicros(duration);
      txString(buffer);
      delayMicroseconds((14 * saveDitMicros + 1) -
			(saveDitMicros * durationDits(l[0])));
      ++l;
    } else {
      // This part goes much faster, but it doesn't convey much
      // information.
      playTone(frequency, duration);
    }
    p += 3;
  }
  setTxHz(saveHz);
  setDitMicros(saveDitMicros);
}
Exemplo n.º 4
0
int main(void)
{
	srand(time(NULL));
	int SIZE,counter; 
	int a[MAX];
	int b[MAX2]={0};
	printf("Input the size of the first input:");
	scanf("%d",&SIZE);
	while (check_error(SIZE)==0)
	{
		printf("Invalid input enter the size of the input again");
		scanf("%d",&SIZE);
	}
	initialize_array(a,SIZE);
	printf("Input array\n");
	print_array(a,SIZE);
	frequency(a,b,SIZE);
	printf("\nMode for the array is number %d",mode(b));
	printf("\nPrinting histogram\n");
	print_histogram(b);
	printf("Bonus part\n");
	printf("\nArray before sorting\n");
	print_array(a,SIZE);	
	printf("\nArray after sorting\n");
	sort_array(a,SIZE);
	print_array(a,SIZE);
	printf("\n");
}
QString CrossPowerSpectrum::frequencyTag() const {
  KstVectorPtr v = frequency();
  if (v) {
    return v->tagName();
  }
  return QString::null;
}
/*!
    \qmlproperty enumeration RecurrenceRule::frequency

    This property holds the frequency with which the item recurs, the value can be one of:
    \list
    \li RecurrenceRule.Invalid - (default).
    \li RecurrenceRule.Daily
    \li RecurrenceRule.Weekly
    \li RecurrenceRule.Monthly
    \li RecurrenceRule.Yearly
    \endlist
 */
void QDeclarativeOrganizerRecurrenceRule::setFrequency(Frequency freq)
{
    if (freq != frequency()) {
        m_rule.setFrequency(static_cast<QOrganizerRecurrenceRule::Frequency>(freq));
        emit recurrenceRuleChanged();
    }
}
Exemplo n.º 7
0
void FFmpegDecoderAudio::adjustBufferEndTps(const size_t buffer_size)
{
    int sample_size = nbChannels() * frequency();

    switch (sampleFormat())
    {
    case osg::AudioStream::SAMPLE_FORMAT_U8:
        sample_size *= 1;
        break;

    case osg::AudioStream::SAMPLE_FORMAT_S16:
        sample_size *= 2;
        break;

    case osg::AudioStream::SAMPLE_FORMAT_S24:
        sample_size *= 3;
        break;

    case osg::AudioStream::SAMPLE_FORMAT_S32:
        sample_size *= 4;
        break;

    case osg::AudioStream::SAMPLE_FORMAT_F32:
        sample_size *= 4;
        break;

    default:
        throw std::runtime_error("unsupported audio sample format");
    }

    m_clocks.audioAdjustBufferEndPts(double(buffer_size) / double(sample_size));
}
Exemplo n.º 8
0
 double Buckets::prob (size_t symbol, size_t position) const
 {
   if (!column_total_)
     return -1.0;
   
   return 1.0 * frequency (symbol, position) / column_total_;
 }
Exemplo n.º 9
0
static void wave_read (GtsObject ** o, GtsFile * fp)
{
  (* GTS_OBJECT_CLASS (gfs_wave_class ())->parent_class->read) (o, fp);
  if (fp->type == GTS_ERROR)
    return;

  GfsWave * wave = GFS_WAVE (*o);
  if (fp->type == '{') {
    GtsFileVariable var[] = {
      {GTS_UINT,   "nk",      TRUE, &wave->nk},
      {GTS_UINT,   "ntheta",  TRUE, &wave->ntheta},
      {GTS_DOUBLE, "alpha_s", TRUE, &wave->alpha_s},
      {GTS_NONE}
    };
    gts_file_assign_variables (fp, var);
    if (fp->type == GTS_ERROR)
      return;
  }

  GfsDomain * domain = GFS_DOMAIN (wave);
  guint ik, ith;
  wave->F = gfs_matrix_new (wave->nk, wave->ntheta, sizeof (GfsVariable *));
  for (ik = 0; ik < wave->nk; ik++)
    for (ith = 0; ith < wave->ntheta; ith++) {
      gchar * name = g_strdup_printf ("F%d_%d", ik, ith);
      gchar * description = g_strdup_printf ("Action density for f = %g Hz and theta = %g degrees",
					     frequency (ik), theta (ith, wave->ntheta)*180./M_PI);
      wave->F[ik][ith] = gfs_domain_get_or_add_variable (domain, name, description);
      g_assert (wave->F[ik][ith]);
      g_free (name);
      g_free (description);
    }
}
Exemplo n.º 10
0
static void group_velocity (int ik, int ith, FttVector * u, guint ntheta, gdouble g)
{
  double cg = g/(4.*M_PI*frequency (ik));
  u->x = cg*cos (theta (ith, ntheta));
  u->y = cg*sin (theta (ith, ntheta));
  u->z = 0.;
}
Exemplo n.º 11
0
void BiquadDSPKernel::getFrequencyResponse(int nFrequencies,
                                           const float* frequencyHz,
                                           float* magResponse,
                                           float* phaseResponse)
{
    bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseResponse;
    ASSERT(isGood);
    if (!isGood)
        return;

    std::vector<float> frequency(nFrequencies);

    double nyquist = this->nyquist();

    // Convert from frequency in Hz to normalized frequency (0 -> 1),
    // with 1 equal to the Nyquist frequency.
    for (int k = 0; k < nFrequencies; ++k)
        frequency[k] = narrowPrecisionToFloat(frequencyHz[k] / nyquist);

    // We want to get the final values of the coefficients and compute
    // the response from that instead of some intermediate smoothed
    // set. Forcefully update the coefficients even if they are not
    // dirty.

    updateCoefficientsIfNecessary(false, true);

    m_biquad.getFrequencyResponse(nFrequencies, &frequency[0], magResponse, phaseResponse);
}
Exemplo n.º 12
0
int main() {
#if 1
  std::vector<std::string> text
      {{"in", "the", "late", "spring", "hemingway", "and", "pauline", "traveled",
       "to", "kansas", "city", "where", "their", "son", "patrick", "was",
       "born", "on", "June", "28", "1928", "pauline", "had", "a", "difficult",
       "delivery", "which", "hemingway", "fictionalized", "in", "a", "Farewell",
       "to", "arms", "after", "patrick", "birth", "pauline", "and", "hemingway",
       "traveled", "to", "wyoming", "massachusetts", "and", "new", "york", "in",
       "the", "winter", "he", "was", "in", "new", "york", "with", "bumby",
       "about", "to", "board", "a", "train", "to", "florida"}};
#else
std::vector<std::string> text
      {{"a", "a", "a", "a", "b", "b", "b", "b",
       "c", "c", "c", "d", "d", "e", "f", "f",
       "f", "f", "f", "f", "f", "f", "g", "g", "g",
       "g", "g", "g"}};
#endif
  auto result = frequency(text, 3);
  // print the statistics.
  for (auto it = result.begin(), ie = result.end(); it != ie; ++it) {
    std::cout << *it << std::endl;
  }
  return 0;
}
Exemplo n.º 13
0
    Rate ZeroInflationIndex::forecastFixing(const Date& fixingDate) const {
        // the term structure is relative to the fixing value at the base date.
        Date baseDate = zeroInflation_->baseDate();
        QL_REQUIRE(!needsForecast(baseDate),
                   name() << " index fixing at base date is not available");
        Real baseFixing = fixing(baseDate);
        Date effectiveFixingDate;
        if (interpolated()) {
            effectiveFixingDate = fixingDate;
        } else {
            // start of period is the convention
            // so it's easier to do linear interpolation on fixings
            effectiveFixingDate = inflationPeriod(fixingDate, frequency()).first;
        }

        // no observation lag because it is the fixing for the date
        // but if index is not interpolated then that fixing is constant
        // for each period, hence the t uses the effectiveFixingDate
        // However, it's slightly safe to get the zeroRate with the
        // fixingDate to avoid potential problems at the edges of periods
        Time t = zeroInflation_->dayCounter().yearFraction(baseDate, effectiveFixingDate);
        bool forceLinearInterpolation = false;
        Rate zero = zeroInflation_->zeroRate(fixingDate, Period(0,Days), forceLinearInterpolation);
        // Annual compounding is the convention for zero inflation rates (or quotes)
        return baseFixing * std::pow(1.0 + zero, t);
    }
Exemplo n.º 14
0
int main(void) {
	int i = 0;
	int static num[SIZE] = { 90, 85, 100, 50, 50, 85, 60, 70, 55, 55, 80, 95, 70, 60, 95,
		80, 100, 75, 70, 95, 90, 90, 70, 95, 50, 65, 85, 95, 100, 65};
	
	//printf("Enter array:\n");
	//while(1 && i < SIZE) {
	//	scanf("%d", &num[i]);
	//	if (num[i] == -1) {
	//		break;
	//	}
	//	i++;
	//}

	printf("%s\n", "Unsorted:");
	printArray(num, SIZE);
	insertionSort(num, SIZE);
	printf("%s\n", "Ascending Order:");
	printArray(num, SIZE);
	frequency(num, SIZE);
	grading(num, SIZE);
	printf("%8s %6.1lf\n", "Mean:", mean(num, SIZE));
	printf("%8s %4d\n", "Mode:", mode(num, SIZE));
	printf("%8s %6.1lf\n", "Median:", median(num, SIZE));

	return 0;
}
Exemplo n.º 15
0
    Real CPICashFlow::amount() const {
        Real I0 = baseFixing();
        Real I1;

        // what interpolation do we use? Index / flat / linear
        if (interpolation() == CPI::AsIndex ) {
            I1 = index()->fixing(fixingDate());
        } else {
            // work out what it should be
            //std::cout << fixingDate() << " and " << frequency() << std::endl;
            //std::pair<Date,Date> dd = inflationPeriod(fixingDate(), frequency());
            //std::cout << fixingDate() << " and " << dd.first << " " << dd.second << std::endl;
            // work out what it should be
            std::pair<Date,Date> dd = inflationPeriod(fixingDate(), frequency());
            Real indexStart = index()->fixing(dd.first);
            if (interpolation() == CPI::Linear) {
                Real indexEnd = index()->fixing(dd.second+Period(1,Days));
                // linear interpolation
                //std::cout << indexStart << " and " << indexEnd << std::endl;
                I1 = indexStart + (indexEnd - indexStart) * (fixingDate() - dd.first)
                / ( (dd.second+Period(1,Days)) - dd.first); // can't get to next period's value within current period
            } else {
                // no interpolation, i.e. flat = constant, so use start-of-period value
                I1 = indexStart;
            }

        }


        if (growthOnly())
            return notional() * (I1 / I0 - 1.0);
        else
            return notional() * (I1 / I0);
    }
Exemplo n.º 16
0
void BytecodeCounter::print() {
  tty->print_cr(
    "%d bytecodes executed in %.1fs (%.3fMHz)",
    counter_value(),
    elapsed_time(),
    frequency() / 1000000.0
  );
}
Exemplo n.º 17
0
void SINE_OSCILLATOR::set_parameter(int param, CONTROLLER_SOURCE::parameter_t v)
{
  switch (param) {
  case 1: 
    frequency(v);
    /* note: cache length of one period in seconds */
    if (v > 0)
      period_len_rep = 1.0 / frequency();
    else
      period_len_rep = 0;
    break;

  case 2: 
    phase_offset(static_cast<double>(v * M_PI));
    break;
  }
}
int main(void)
{
        string note = "A4";
        int f = frequency(note);

        // Print note to screen
        printf("%3s: %i\n", note, f);
}
Exemplo n.º 19
0
Arquivo: Strings.hpp Projeto: laoo/LSC
  void iterateSuitable( double aFreq, double aAcceptedCents, double aMeasure, double aTension, P p )
  {
    double cent = std::pow( 2, aAcceptedCents / 1200.0 );
    double maxFreq = aFreq * cent;
    double minFreq = aFreq / cent;
    double sqrtTension = sqrt( aTension );

    auto it = std::lower_bound( mElements.cbegin(), mElements.cend(), minFreq, [=]( Element const& e, double aF )
    {
      double f = frequency( aMeasure, aTension, e.gauge, e.density );
      return aF > f;
    } );

    struct EF
    {
      Element const* e;
      double c;
      double t;
      double g;
    };

    std::vector<EF> suitable;

    while ( it != mElements.cend() )
    {
      double f = frequency( aMeasure, aTension, it->gauge, it->density );
      if ( f > maxFreq )
        break;
      double c = 1200.0 * log( aFreq / f ) / log( 2.0 );
      double t = tension( aFreq, aMeasure, it->gauge, it->density );
      double g = gauge( aFreq, sqrtTension, aMeasure, it->density );
      suitable.push_back( { &*it, c, t, g } );
      ++it;
    }

    std::sort( suitable.begin(), suitable.end(), []( EF const& left, EF const& right )
    {
      return std::abs( left.c ) < std::abs( right.c );
    } );

    for ( auto jt = suitable.cbegin(); jt != suitable.cend(); ++jt )
    {
      p( jt->e->name, jt->e->producer, jt->e->material, jt->e->length, jt->c, jt->t, jt->g );
    }
  }
Exemplo n.º 20
0
//	bool Virtex6::suggestSubaddSize(int &x, int wIn){
//		
//		int chunkSize = 1 + (int)floor( (1./frequency() - (lut2_ + muxcyStoO_ + xorcyCintoO_)) / muxcyCINtoO_ );
//		x = chunkSize;		
//		if (x > 1) 
//			return true;
//		else {
//			x = 2;		
//			return false;
//		} 
//	};
//	
//	bool Virtex6::suggestSlackSubaddSize(int &x, int wIn, double slack){
//		
//		int chunkSize = 1 + (int)floor( (1./frequency() - slack - (lut2_ + muxcyStoO_ + xorcyCintoO_)) / muxcyCINtoO_ );
//		x = chunkSize;		
//		if (x > 1) 
//			return true;
//		else {
//			x = 2;		
//			return false;
//		} 
//	};
//	
	bool Virtex6::suggestSlackSubcomparatorSize(int& x, int wIn, double slack, bool constant)
	{
		bool succes = true;
		
		if (!constant){
			x = (lutInputs_/2)*(((1./frequency() - slack) - (lut2_ + muxcyStoO_))/muxcyCINtoO_ - 1)+1;
		}else{
			x = (lutInputs_/2)*(((1./frequency() - slack) - (lut2_ + muxcyStoO_))/muxcyCINtoO_ - 1)+1;
		}
		if (x<lutInputs_){ //capture possible negative values
			x = lutInputs_;
			succes = false;
		}
		
		if (x> wIn)//saturation 
			x = wIn;
		
		return succes;
	}
std::string ofxIntegratedWhistleDetector::Whistle::toString() const
{
	if (isNull())
		return std::string("Whistle: Null");

	return "Whistle: #" + ofToString(no()) +
		", Frequency (Hz): " + ofToString(frequency()) +
		", Certainty: " + ofToString(certainty()) +
		", Time (msecs): " + ofToString(msecsPerDuration());
}
testcases()
{
	int i,j;
	for (i = 0; i < 2; i++)
	{
		printf("\nTest case %d:\n", i + 1);
		frequency(t[i].arr);
	}
	
}
Exemplo n.º 23
0
CONTROLLER_SOURCE::parameter_t SINE_OSCILLATOR::get_parameter(int param) const
{
  switch (param) {
  case 1: 
    return frequency();
  case 2: 
    return phase_offset() / M_PI;
  }
  return(0.0);
}
Exemplo n.º 24
0
void SINE_OSCILLATOR::init(void)
{
  MESSAGE_ITEM otemp;
  otemp << "Sine oscillator created; frequency ";
  otemp.setprecision(3);
  otemp << frequency();
  otemp << " and initial phase of "; 
  otemp << phase_offset() << ".";
  ECA_LOG_MSG(ECA_LOGGER::user_objects, otemp.to_string());
}
Exemplo n.º 25
0
	bool Virtex6::suggestSubaddSize(int &x, int wIn){
		int chunkSize = 2 + (int)floor( (1./frequency() - (fdCtoQ_ + slice2sliceDelay_ + lut2_ + muxcyStoO_ + xorcyCintoO_ + ffd_)) / muxcyCINtoO_ );
		x = min(chunkSize, wIn);		
		if (x > 0) 
			return true;
		else {
			x = min(2,wIn);		
			return false;
		} 
	};
Exemplo n.º 26
0
	void Virtex6::delayForDSP(MultiplierBlock* multBlock, double currentCp, int& cycleDelay, double& cpDelay)
	{
		double targetPeriod, totalPeriod;
		
		targetPeriod = 1.0/frequency();
		totalPeriod = currentCp + DSPMultiplierDelay_;
		
		cycleDelay = floor(totalPeriod/targetPeriod);
		cpDelay = totalPeriod-targetPeriod*cycleDelay;
	}
Exemplo n.º 27
0
void CDisplay::setFrequency(int value)
{
    QString frequency("%1");
    frequency = frequency.arg(value);
    frequency = frequency.insert(frequency.length()-6,".");
    if (radio == 0)
        frequency1 = frequency;
    else
        frequency2 = frequency;
    repaint();
}
Exemplo n.º 28
0
	bool Virtex6::suggestSlackSubaddSize(int &x, int wIn, double slack){
		int chunkSize =  1 + (int)floor( (1./frequency() - slack - (lut2_ + muxcyStoO_ + xorcyCintoO_)) / muxcyCINtoO_ );
		x = chunkSize;	
		x = min(chunkSize, wIn);	
		if (x > 0) 
			return true;
		else {
			x = min(2,wIn);		
			return false;
		} 
	};
Exemplo n.º 29
0
bool DVBProvider::tune( void ) {
	struct dvb_frontend_parameters param;	

	printf( "[DVBProvider] Tune started begin: chan=%d, freq=%d\n", _chan, frequency(_chan) );

	memset( &param, 0, sizeof(dvb_frontend_parameters) );
	param.frequency                    = frequency( _chan );
	param.inversion                    = _spectral_inversion;
	param.u.ofdm.bandwidth             = BANDWIDTH_6_MHZ;	//	TODO: Parametrice!?!?!
	param.u.ofdm.code_rate_HP          = FEC_3_4;
	param.u.ofdm.code_rate_LP          = FEC_AUTO;
	param.u.ofdm.constellation         = QAM_AUTO;
	param.u.ofdm.transmission_mode     = TRANSMISSION_MODE_AUTO;
	param.u.ofdm.guard_interval        = GUARD_INTERVAL_AUTO;
	param.u.ofdm.hierarchy_information = HIERARCHY_NONE;

	//	Cancel check status
	_checkStatusTimer.cancel();

	if (ioctl( _frontendFD, FE_SET_FRONTEND, &param ) == -1) {
		printf( "[DVBProvider] Setting frontend parameters failed\n" );
		return false;
	}

	//	Check if can lock ...
	for (int i = 0; i < 10; i++) {
		boost::this_thread::sleep( boost::posix_time::milliseconds(100) );
		
		if (isTunerLocked(_chan)) {
			//	Setup timer to check status
			_checkStatusTimer.expires_from_now( boost::posix_time::milliseconds(500) );
			_checkStatusTimer.async_wait( boost::bind( &DVBProvider::onCheckStatus, this, _1, _chan) );

			printf( "[DVBProvider] Tune started end: chan=%d, freq=%d\n", _chan, param.frequency );
			return true;
		}
	}

	printf( "[DVBProvider] Frontend failed!\n" );
	return false;
}
Exemplo n.º 30
0
    Rate YoYInflationTermStructure::yoyRate(const Date &d, const Period& instObsLag,
                                              bool forceLinearInterpolation,
                                              bool extrapolate) const {

        Period useLag = instObsLag;
        if (instObsLag == Period(-1,Days)) {
            useLag = observationLag();
        }

        Rate yoyRate;
        if (forceLinearInterpolation) {
            std::pair<Date,Date> dd = inflationPeriod(d-useLag, frequency());
            dd.second = dd.second + Period(1,Days);
            Real dp = dd.second - dd.first;
            Real dt = (d-useLag) - dd.first;
            // if we are interpolating we only check the exact point
            // this prevents falling off the end at curve maturity
            InflationTermStructure::checkRange(d, extrapolate);
            Time t1 = timeFromReference(dd.first);
            Time t2 = timeFromReference(dd.second);
            Rate y1 = yoyRateImpl(t1);
            Rate y2 = yoyRateImpl(t2);
            yoyRate = y1 + (y2-y1) * (dt/dp);
        } else {
            if (indexIsInterpolated()) {
                InflationTermStructure::checkRange(d-useLag, extrapolate);
                Time t = timeFromReference(d-useLag);
                yoyRate = yoyRateImpl(t);
            } else {
                std::pair<Date,Date> dd = inflationPeriod(d-useLag, frequency());
                InflationTermStructure::checkRange(dd.first, extrapolate);
                Time t = timeFromReference(dd.first);
                yoyRate = yoyRateImpl(t);
            }
        }

        if (hasSeasonality()) {
            yoyRate = seasonality()->correctYoYRate(d-useLag, yoyRate, *this);
        }
        return yoyRate;
    }