コード例 #1
0
ファイル: reassign_ti.c プロジェクト: guneshwor/ltfat
LTFAT_EXTERN void
LTFAT_NAME(filterbankphasegrad)(const LTFAT_COMPLEX* c [],
                                const LTFAT_COMPLEX* ch[],
                                const LTFAT_COMPLEX* cd[],
                                const ltfatInt          M,
                                const ltfatInt        N[],
                                const ltfatInt          L,
                                const LTFAT_REAL   minlvl,
                                LTFAT_REAL*        tgrad[],
                                LTFAT_REAL*        fgrad[],
                                LTFAT_REAL*           cs[])
{
#define FOREACHCOEF \
    for(ltfatInt m=0;m<M;++m){\
        for(ltfatInt ii=0;ii<N[m];++ii){

#define ARRAYEL(c) ((c)[m][ii])
#define ENDFOREACHCOEF }}

LTFAT_REAL minlvlAlt = LTFAT_COMPLEXH(cabs)(c[0][0]);

// Compute spectrogram from coefficients
// Keep max value
FOREACHCOEF
LTFAT_REAL en = LTFAT_COMPLEXH(cabs)(ARRAYEL(c))*LTFAT_COMPLEXH(cabs)(ARRAYEL(c));
ARRAYEL(cs) = en;
if(en>minlvlAlt)
    minlvlAlt = en;
ENDFOREACHCOEF

// Adjust minlvl 
minlvlAlt *= minlvl;

// Force spectrogram values less tha minLvlAlt to minlvlAlt
FOREACHCOEF
LTFAT_REAL csEl = ARRAYEL(cs);
if(csEl<minlvlAlt)
    ARRAYEL(cs) = minlvlAlt;
ENDFOREACHCOEF

// Instantaneous frequency
FOREACHCOEF
LTFAT_REAL tgradEl = LTFAT_COMPLEXH(creal)(
                         ARRAYEL(cd)*LTFAT_COMPLEXH(conj)(ARRAYEL(c))/ARRAYEL(cs)
                                          )/L*2;
ARRAYEL(tgrad) = fabs(tgradEl)<=2?tgradEl:0.0f;
ENDFOREACHCOEF


FOREACHCOEF
ARRAYEL(fgrad) = LTFAT_COMPLEXH(cimag)(
                        ARRAYEL(ch)*LTFAT_COMPLEXH(conj)(ARRAYEL(c))/ARRAYEL(cs)
                                      );
ENDFOREACHCOEF

#undef FOREACHCOEF
#undef ENDFOREACHCOEF
#undef ARRAYEL
}
コード例 #2
0
LTFAT_EXTERN void
LTFAT_NAME(pgauss_cmplx)(const ltfatInt L, const double w, const double c_t, const double c_f,
                         LTFAT_COMPLEX *g)
{

    ltfatInt lr,k,nk;
    double tmp,sqrtl, safe, gnorm;

    sqrtl=sqrt((double)L);
    safe=4;
    gnorm=0;

    /* Outside the interval [-safe,safe] then exp(-pi*x.^2) is numerically zero. */
    nk=(ltfatInt)ceil(safe/sqrt((double)L/sqrt(w)));

    for ( lr=0; lr<L; lr++)
    {
        //g[lr][0]=0.0;
        //g[lr][1]=0.0;
        g[lr] = (LTFAT_COMPLEX) 0.0;
        for (k=-nk; k<=nk; k++)
        {
            /* Use a tmp variable to calculate squaring */
            tmp = ((double)lr+c_t)/sqrtl-(double)k*sqrtl;
            tmp = exp(-PI*tmp*tmp/w);
            g[lr]+=tmp*LTFAT_COMPLEXH(cexp)(I*2*PI*c_f*((double)lr/L-(double)k));

        }
        double gReal = LTFAT_COMPLEXH(creal)(g[lr]);
        double gImag = LTFAT_COMPLEXH(cimag)(g[lr]);
        gnorm += (gReal*gReal+gImag*gImag);
    }

    /* Normalize it exactly. */
    gnorm=sqrt(gnorm);

    for ( lr=0; lr<L; lr++)
    {
        g[lr] /= gnorm;
    }
}