Пример #1
0
/* Demo 2 */
void GenerateAndTest2(FLOATING frequency)
{
  int	index;

  FLOATING	magnitudeSquared;
  FLOATING	magnitude;
  FLOATING	real;
  FLOATING	imag;

  printf("Freq=%7.1f   ", frequency);
  Generate(frequency);

  /* Process the samples. */
  for (index = 0; index < N; index++)
  {
    ProcessSample(testData[index]);
  }

  /* Do the "standard Goertzel" processing. */
  GetRealImag(&real, &imag);

  magnitudeSquared = real*real + imag*imag;
  printf("rel mag^2=%16.5f   ", magnitudeSquared);
  magnitude = sqrt(magnitudeSquared);
  printf("rel mag=%12.5f\n", magnitude);

  ResetGoertzel();
}
Пример #2
0
static void setUpConstants()
{
  int i;
  for( i = 0; i < MAX_BINS; i++) {
    ks[i] = (int)(0.5 + (NS[i]*FREQUENCIES[i]/SAMPLING_RATE));
    est_freqs[i] = (float)((int)(0.5 + (((float)ks[i])*SAMPLING_RATE/NS[i])));
  }
  ResetGoertzel();
}
Пример #3
0
/* Call this each time a frequency is tested, to precompute the constants. */
static void InitGoertzel(const int i)
{
  FLOATING	floatN;
  FLOATING	omega;
  int k;

  floatN = (FLOATING) NS[i];
  k = (int) (ks[i]);
  omega = (2.0 * PI * k) / floatN;
  sine = sin(omega);
  cosine = cos(omega);
  coeff = 2.0 * cosine;

  ResetGoertzel();
}
Пример #4
0
float Goertzel::detect()
{
  float	magnitude;

  /* Process the samples. */
  for (int index = 0; index < _N; index++)
  {
    ProcessSample(testData[index]);
  }

  /* Do the "standard Goertzel" processing. */
  magnitude = sqrt(Q1*Q1 + Q2*Q2 - coeff*Q1*Q2);

  ResetGoertzel();
  return magnitude;
}
Пример #5
0
void Goertzel::ChangeParameters(float TARGET_FREQUENCY, float N, float SAMPLING_FREQUENCY)
{
  _SAMPLING_FREQUENCY=SAMPLING_FREQUENCY;	//on 16mhz, ~8928.57142857143, on 8mhz ~44444
  _TARGET_FREQUENCY=TARGET_FREQUENCY; //should be integer of SAMPLING_RATE/N
  if(N>MAXN){
     _N=MAXN;
  }else{
    _N=N;
  }
  
  float omega = (2.0 * PI * _TARGET_FREQUENCY) / _SAMPLING_FREQUENCY;

  coeff = 2.0 * cos(omega);

  ResetGoertzel();	
}
Пример #6
0
/* Call this once, to precompute the constants. */
void InitGoertzel(void)
{
  int	k;
  FLOATING	floatN;
  FLOATING	omega;

  floatN = (FLOATING) N;
  k = (int) (0.5 + ((floatN * TARGET_FREQUENCY) / SAMPLING_RATE));
  omega = (2.0 * PI * k) / floatN;
  sine = sin(omega);
  cosine = cos(omega);
  coeff = 2.0 * cosine;

  printf("For SAMPLING_RATE = %f", SAMPLING_RATE);
  printf(" N = %d", N);
  printf(" and FREQUENCY = %f,\n", TARGET_FREQUENCY);
  printf("k = %d and coeff = %f\n\n", k, coeff);

  ResetGoertzel();
}
Пример #7
0
/* Test the given data */
static FLOATING Test(int i, const SAMPLE *input)
{
  int	index;

  FLOATING	magnitudeSquared;
  FLOATING	magnitude;
  FLOATING	real;
  FLOATING	imag;

  /* Process the samples. */
  for (index = 0; index < NS[i]; index++)
  {
    ProcessSample(input[index]);  // instead of processing the testData, process the actual sound file so long as the constants agree (no need to generate)
  }

  /* Do the "standard Goertzel" processing. */
  real = (Q1 - Q2 * cosine);
  imag = (Q2 * sine);
  magnitudeSquared = real*real + imag*imag;
  magnitude = sqrt(magnitudeSquared);
  return magnitude;
  ResetGoertzel();
}
Пример #8
0
/* Demo 1 */
void GenerateAndTest(FLOATING frequency)
{
  int	index;

  FLOATING	magnitudeSquared;
  FLOATING	magnitude;
  FLOATING	real;
  FLOATING	imag;

  printf("For test frequency %f:\n", frequency);
  Generate(frequency);

  /* Process the samples */
  for (index = 0; index < N; index++)
  {
    ProcessSample(testData[index]);
  }

  /* Do the "basic Goertzel" processing. */
  GetRealImag(&real, &imag);

  printf("real = %f imag = %f\n", real, imag);

  magnitudeSquared = real*real + imag*imag;
  printf("Relative magnitude squared = %f\n", magnitudeSquared);
  magnitude = sqrt(magnitudeSquared);
  printf("Relative magnitude = %f\n", magnitude);

  /* Do the "optimized Goertzel" processing */
  magnitudeSquared = GetMagnitudeSquared();
  printf("Relative magnitude squared = %f\n", magnitudeSquared);
  magnitude = sqrt(magnitudeSquared);
  printf("Relative magnitude = %f\n\n", magnitude);

  ResetGoertzel();
}