コード例 #1
0
ファイル: DFT.cpp プロジェクト: LuaAV/LuaAV
void STFT::inverse(float * dst){
	//printf("STFT::inverse(float *)\n");
	if(Bin::MagFreq == mSpctFormat){
		//mem::copy(bins1(), mPhases, numBins()); // not correct, need to unwrap frequencies
		for(uint32_t i=1; i<numBins()-1; ++i) bins()[i] = mPhases[i];
	}	
	
	DFT::inverse(0);	// result goes into mBuf
	
	// undo zero-phase windowing rotation?
	if(mRotateForward) mem::rotateHalf(mBuf, sizeWin());
	
	// apply secondary window to smooth ends?
	if(mWindowInverse){
		arr::mulBartlett(mBuf, sizeWin());
	}

	if(overlapping()){	//inverse windows overlap?
	
		// scale inverse so overlap-add is normalized
		//arr::mul(mBuf, gen::val(mInvWinMul), sizeWin());
		slice(mBuf, sizeWin()) *= mInvWinMul;
	
		// shift old output left while adding new output
		arr::add(mBufInv, mBuf, mBufInv + sizeHop(), sizeWin() - sizeHop());
	}

	// copy remaining non-overlapped portion of new output
	uint32_t sizeOverlap = sizeWin() - sizeHop();
	mem::deepCopy(mBufInv + sizeOverlap, mBuf + sizeOverlap, sizeHop());

	// copy output if external buffer provided
	if(dst) mem::deepCopy(dst, mBufInv, sizeWin());	
}
コード例 #2
0
ファイル: main.c プロジェクト: hynynen/simulation
void generateBlockers(Blocker* blockers, unsigned count, 
		      int size_x, int size_y, gsl_rng* r){
  // count = amount of blockers that are generated.
  // This value changes every time this program is executed and is
  // determined by PPP function.

  for (unsigned j=0; j<count; ++j){
    //printf("Creating blocker, round: %u\n",j);
    /*We get a random value in [0,1). That value is multiplied
    with the size of our area. We have to take in account that
    blocker with radius 50cm cannot be closer to wall than 50cm.
    */
    double randomx = gsl_rng_uniform(r)*size_x;
    double randomy = gsl_rng_uniform(r)*size_y;

    if (randomx < 50){randomx = 50;}
    else if (randomx > (size_x-50)){ randomx = (size_x-50);}

    if (randomy < 50){randomy = 50;}
    else if (randomy > (size_y-50)){randomy = (size_y-50);}
    //Rounding and casting to integer.
    int x = (int)floor(randomx);
    int y = (int)floor(randomy);

    Blocker newBlocker = {x,y};
    if (overlapping(blockers,newBlocker, j)){
      //printf("Dropped\n");
      --j;
      continue;
    } else {
      blockers[j] = newBlocker;
    }
  }
}
コード例 #3
0
ファイル: DFT.cpp プロジェクト: PeterZhouSZ/Gamma
void STFT::inverse(float * dst){
	//printf("STFT::inverse(float *)\n");
	if(MAG_FREQ == mSpctFormat){
		// 2pi / hopRate: converts Hz to phase diff in radians
		double factor = M_2PI * unitsHop();

		// 2pi / overlap: expected phase diff of fundamental due to overlap
		double expdp1 = double(sizeHop())/sizeWin() * M_2PI;
		double fund = binFreq();

		for(unsigned k=1; k<numBins()-1; ++k){
			double t = bin(k)[1];		// freq
			t -= k*fund;				// freq to freq deviation
			t *= factor;				// freq deviation to phase diff
			t += k*expdp1;				// add expected phase diff due to overlap
			mAccums[k] += t;			// accumulate phase diff
			//bin(k)[1] = mAccums[k];		// copy accum phase for inverse xfm
			bufInvFrq()[2*k] = bin(k)[0];
			bufInvFrq()[2*k+1] = mAccums[k];
		}

		bufInvFrq()[0] = bin(0)[0];
		bufInvFrq()[2*(numBins()-1)] = bin(numBins()-1)[0];
	}

	DFT::inverse();	// result goes into bufInvPos()

	// undo zero-phase windowing rotation?
	if(mRotateForward) mem::rotateRight(sizeWin()/2, bufInvPos(), sizeDFT());

	// apply secondary window to smooth ends?
	if(mWindowInverse){
		arr::mulBartlett(bufInvPos(), sizeWin());
	}

	if(overlapping()){	//inverse windows overlap?

		// scale inverse so overlap-add is normalized
		for(unsigned i=0; i<sizeWin(); ++i){
			bufInvPos()[i] *= mInvWinMul;
		}

		// shift old output left while adding new output
		arr::add(mBufInv, bufInvPos(), mBufInv + sizeHop(), sizeWin() - sizeHop());
	}

	// copy remaining non-overlapped portion of new output
	unsigned sizeOverlap = sizeWin() - sizeHop();
	mem::deepCopy(mBufInv + sizeOverlap, bufInvPos() + sizeOverlap, sizeHop());

	// copy output if external buffer provided
	if(dst) mem::deepCopy(dst, mBufInv, sizeWin());	
}
コード例 #4
0
int main(void){
	int i, j, k, _case = 1;
	char c;

	for (i = 2; i < MAXN; i++)
		len[i] = min(len[i-1] + len[i-2], MAXSTR);

	for (i = 4, j = 3; i < MAXN && j < MAXSTR; i++)
		for (k = 0; k < len[i-2]; k++)
			if (j < MAXSTR)
				prefix[j++] = prefix[k];

	for (j = MAXSTR - len[24], k = 0; j < MAXSTR; j++, k++)
		suffix[0][j] = prefix[k];

	for (j = 0, k = len[23] - (MAXSTR - len[24]); k < len[23]; k++)
		suffix[0][j] = prefix[k];

	for (j = MAXSTR - len[23], k = 0; j < MAXSTR; j++, k++)
		suffix[1][j] = prefix[k];

	for (j = MAXSTR - len[23] - len[22], k = 0; k < len[22]; j++, k++)
		suffix[1][j] = prefix[k];

	for (j = MAXSTR - len[23] - len[22] - len[21], k = 0; k < len[21]; j++, k++)
		suffix[1][j] = prefix[k];

	for (j = 0, k = len[20] - (MAXSTR - len[23] - len[22] - len[21]); k < len[20]; k++)
		suffix[0][j] = prefix[k];

	while (scanf("%d\n", &N) != EOF){
		for (pLen = 0, c = getchar(); c == '0' || c == '1'; pLen++, c = getchar())
			pattern[pLen+1] = c == '1';
		pattern[pLen+1] = 2;

		buildAutomata();

		dp[0] = dp[1] = dp[2] = 0;

		if (pLen == 1)
			dp[2] = dp[pattern[1]] = 1;
		else if (pLen == 2 && pattern[1] == 1 && pattern[2] == 0)
			dp[2] = 1;

		for (i = 3; i <= N; i++)
			dp[i] = dp[i-1] + dp[i-2] + overlapping(i);

		printf("Case %d: %lld\n", _case++, dp[N]);
	}

	return 0;
}
コード例 #5
0
ファイル: DFT.cpp プロジェクト: LuaAV/LuaAV
void STFT::computeInvWinMul(){

	// compute sum of overlapping elements of forward window
	if(overlapping()){
		float sum = 0.f;
		for(uint32_t i=0; i<sizeWin(); i+=sizeHop()){
			sum += mFwdWin[i] * (mWindowInverse ? scl::bartlett(2*i/(float)sizeWin() - 1.f): 1.f);
		}
		mInvWinMul = 1/sum;
	}
	
	// if no overlap, then do not scale output
	else{
		mInvWinMul = 1;
	}

	//printf("mInvWinMul: %f\n", mInvWinMul);
}
コード例 #6
0
ファイル: overlapping.c プロジェクト: JumperWang/MTL
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
    double*		v		=	mxGetPr(prhs[0]);
    int			p		=   (int) mxGetScalar(prhs[1]);
    int			g		=   (int) mxGetScalar(prhs[2]);
    double		lambda1 =         mxGetScalar(prhs[3]);
    double		lambda2	=         mxGetScalar(prhs[4]);
	double*		w   	=	      mxGetPr(prhs[5]);
	double*		G   	=	      mxGetPr(prhs[6]);
	double*		Y   	=	      mxGetPr(prhs[7]);
	int			maxIter	=   (int) mxGetScalar(prhs[8]);
	int			flag	=   (int) mxGetScalar(prhs[9]);
	double		tol	=             mxGetScalar(prhs[10]);
    
	double *x;
    double *gap;
    double *penalty2;
    
	/* set up output arguments */
	plhs[0] = mxCreateDoubleMatrix(p,1,mxREAL);
	plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL);
	plhs[2] = mxCreateDoubleMatrix(1,5,mxREAL);
    
	x           = mxGetPr(plhs[0]);
    gap         = mxGetPr(plhs[1]);
    penalty2    = mxGetPr(plhs[2]);
    /*
     * On May 27, 2010, we add three other elements to penalty2: pp, gg, and iterNum
     * 
     * where pp is the number of non-zero elements and 
     *       gg is the number of non-zero groups after identifying groups
     *
     * and   iterNum is the number of iteration consumed for solving the dual problem
     */
    
    overlapping(x, gap, penalty2,
            v,  p, g, lambda1, lambda2,
            w, G, Y, maxIter, flag,tol);
}
コード例 #7
0
ファイル: DFT.cpp プロジェクト: ntomassetti/Noise-eFX
void STFT::inverse(float * dst){
	//printf("STFT::inverse(float *)\n");
	if(MAG_FREQ == mSpctFormat){
		// TODO:
		for(uint32_t i=1; i<numBins()-1; ++i) bin(i)[1] = mPhases[i];
	}	
	
	DFT::inverse(0);	// result goes into bufPos()
	
	// undo zero-phase windowing rotation?
	if(mRotateForward) mem::rotateHalf(bufPos(), sizeWin());

	// apply secondary window to smooth ends?
	if(mWindowInverse){
		arr::mulBartlett(bufPos(), sizeWin());
	}

	if(overlapping()){	//inverse windows overlap?
	
		// scale inverse so overlap-add is normalized
		//slice(mBuf, sizeWin()) *= mInvWinMul;
		for(unsigned i=0; i<sizeWin(); ++i){
			bufPos()[i] *= mInvWinMul;
		}
	
		// shift old output left while adding new output
		arr::add(mBufInv, bufPos(), mBufInv + sizeHop(), sizeWin() - sizeHop());
	}

	// copy remaining non-overlapped portion of new output
	uint32_t sizeOverlap = sizeWin() - sizeHop();
	mem::deepCopy(mBufInv + sizeOverlap, bufPos() + sizeOverlap, sizeHop());

	// copy output if external buffer provided
	if(dst) mem::deepCopy(dst, mBufInv, sizeWin());	
}