Example #1
0
// snapshot -> frequency domain
void
compute_spectrum (SpecBlock * sb)
{
	int i, j, half = sb->size / 2;


	// assume timebuf has windowed current snapshot

	fftwf_execute (sb->plan);

	if (sb->scale == SPEC_MAG)
	{
		for (i = 0, j = half; i < half; i++, j++)
		{
			sb->output[i] = (float) Cmag (CXBdata (sb->freqbuf, j));
			sb->output[j] = (float) Cmag (CXBdata (sb->freqbuf, i));
		}
	}
	else
	{				// SPEC_PWR
		for (i = 0, j = half; i < half; i++, j++)
		{
			sb->output[i] =
				(float) (10.0 *
				log10 (Csqrmag (CXBdata (sb->freqbuf, j)) + 1e-60));
			sb->output[j] =
				(float) (10.0 *
				log10 (Csqrmag (CXBdata (sb->freqbuf, i)) + 1e-60));
		}
	}
}
Example #2
0
static void
lmsr_adapt_i (LMSR lms)
{
  int i, j, k;
  REAL sum_sq, scl1, scl2;
  COMPLEX accum, error;

  scl1 = (REAL) (1.0 - rate * leak);

  for (i = 0; i < ssiz; i++)
    {

      dlay (dptr) = CXBdata (lms->signal, i);
      accum = cxzero;
      sum_sq = 0;

      for (j = 0; j < asiz; j+=2)
		{
			k = wrap (j);
			sum_sq += Csqrmag (dlay (k));
			accum.re += afil (j).re * dlay (k).re;
			accum.im += afil (j).im * dlay (k).im;

			k = wrap (j+1);
			sum_sq += Csqrmag (dlay (k));
			accum.re += afil (j+1).re * dlay (k).re;
			accum.im += afil (j+1).im * dlay (k).im;
		}

      error = Csub(cssig(i),accum);
	  cssig(i) = error;
//     ssig_i (i) = error.im;
//	  ssig (i) = error.re;

      scl2 = (REAL) (rate / (sum_sq + 1.19e-7));
      error = Cscl(error,scl2);
      for (j = 0; j < asiz; j+=2)
		{
			k = wrap (j);
			afil (j).re = afil (j).re * scl1 + error.re * dlay (k).re;
			afil (j).im = afil (j).im * scl1 + error.im * dlay (k).im;

			k = wrap (j+1);
			afil (j+1).re = afil (j+1).re * scl1 + error.re * dlay (k).re;
			afil (j+1).im = afil (j+1).im * scl1 + error.im * dlay (k).im;
		}

      dptr = bump (dptr);
    }
}