void TimeFreqPeakConnectivity::InitMatrix (mrs_realvec &Matrix, unsigned char **traceback, mrs_natural rowIdx, mrs_natural colIdx)
{
	mrs_natural i,j,				
				numRows = Matrix.getRows (),
				numCols = Matrix.getCols ();
	mrs_natural iCol;

	Matrix.setval(0);
	
	traceback[rowIdx][colIdx]	= kFromLeft;

	// left of point of interest
	for (i = 0; i < numRows; i++)
	{
		for (j = 0; j < colIdx; j++)
		{
			Matrix(i,j)		= costInit;
			traceback[i][j]	= kFromLeft;
		}
	}
	//cout << Matrix << endl;
	//upper left corner
	for (i = 0; i < rowIdx; i++)
	{
		iCol	= MyMin (rowIdx - i + colIdx, numCols);
		for (j = colIdx; j < iCol; j++)
		{
			Matrix(i,j)		= costInit;
			traceback[i][j]	= kFromLeft;
		}
	}
	//cout << Matrix << endl;
	// lower left corner
	for (i = rowIdx + 1; i < numRows; i++)
	{
		iCol	= MyMin (i - rowIdx + colIdx, numCols);
		for (j = colIdx; j < iCol; j++)
		{
			Matrix(i,j)		= costInit;
			traceback[i][j]	= kFromLeft;
		}
	}
	//cout << Matrix << endl;
}
void PeakConvert2::ComputePeaker (mrs_realvec in, realvec& out)
{
#ifdef ORIGINAL_VERSION
  peaker_->updControl("mrs_real/peakStrength", 0.2);// to be set as a control [!]
#else
  peaker_->updControl("mrs_real/peakStrength",1e-1);
  peaker_->updControl("mrs_real/peakStrengthRelMax" ,1e-2);
  peaker_->updControl("mrs_real/peakStrengthAbs",1e-10 );
  peaker_->updControl("mrs_real/peakStrengthTreshLpParam" ,0.95);
  peaker_->updControl("mrs_real/peakStrengthRelThresh" , 1.);
#endif

  peaker_->updControl("mrs_real/peakSpacing", 2e-3);   // 0
  peaker_->updControl("mrs_natural/peakStart", downFrequency_);   // 0
  peaker_->updControl("mrs_natural/peakEnd", upFrequency_);  // size_
  peaker_->updControl("mrs_natural/inSamples", in.getCols());
  peaker_->updControl("mrs_natural/inObservations", in.getRows());
  peaker_->updControl("mrs_natural/onSamples", out.getCols());
  peaker_->updControl("mrs_natural/onObservations", out.getRows());

  peaker_->process(in, out);
}
void TimeFreqPeakConnectivity::CalcDp (mrs_realvec &Matrix, mrs_natural startr, mrs_natural startc, mrs_natural stopr, mrs_natural stopc)
{
	mrs_natural i,j,
		numRows = Matrix.getRows (),
		numCols = Matrix.getCols ();
	mrs_real prevCost[kNumDirections]	= {0,0,0};

	costMatrix_.stretch ( numRows, numCols);

	// initialize cost and traceback matrix
	// upper and lower left corner
	InitMatrix (costMatrix_, tracebackIdx_, startr, startc);
	costMatrix_(startr, startc)	= Matrix(startr, startc);

	// compute cost matrix
	for (j = startc+1; j <= stopc; j++)
	{
		mrs_natural rowLoopStart	= MyMax (0, startr - (j - startc)),
					rowLoopStop		= MyMin (numRows, startr + (j-startc) + 1);
		for (i = rowLoopStart; i < rowLoopStop; i++)
		{
			prevCost[kFromLeft]	= costMatrix_(i,j-1);
			prevCost[kFromUp]	= (i >= numRows-1) ? costInit : costMatrix_(i+1, j-1);			// the if isn't very nice here....
			prevCost[kFromDown]	= (i <= 0) ? costInit : costMatrix_(i-1, j-1);
			// assign cost
			costMatrix_(i,j)	= Matrix(i,j) + dtwFindMin (prevCost, tracebackIdx_[i][j]);
		}
	}

	// compute path
	i = stopr;
	for (j = stopc; j >= startc; j--)
	{
		path_[j-startc]	= i;
		i				-= (kFromLeft - tracebackIdx_[i][j]); // note: does work only for kFromUp, kFromLeft, kFromDown
	}
}
Beispiel #4
0
// used inside myProcess
mrs_real
HarmonicStrength::quadratic_interpolation(mrs_real best_bin,
    mrs_realvec& in, mrs_natural t)
{
  if ((best_bin == 0) || (best_bin == in.getRows()-1))
  {
    // don't try to interpolate using data that's
    // outside of the spectogram
    // TODO: find some convincing DSP thing to do in this case
    return in( (mrs_natural)best_bin, t);
  }
  // https://ccrma.stanford.edu/~jos/sasp/Quadratic_Interpolation_Spectral_Peaks.html
  // a = alpha, b = beta, g = gamma
  mrs_real a = in( (mrs_natural)best_bin - 1, t);
  mrs_real b = in( (mrs_natural)best_bin + 0, t);
  mrs_real g = in( (mrs_natural)best_bin + 1, t);

  mrs_real p = 0.5 * (a-g)/(a-2*b+g);
  // avoid some NaNs
  if ((p < -0.5) || (p > 0.5))
  {
    return b;
  }
  mrs_real yp = b - 0.25*(a-g)*p;
  // avoid all NaNs
  if (yp < b)
  {
    // I think this happens because the search window doesn't
    // encompass the entire spectrum, so the "highest" bin
    // might not actually be the highest one, if it was on the
    // edge of search window.
    // TODO: find some convincing DSP thing to do in this case
    return b;
  }
  return yp;
}