void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, W, a, M, N, gl; // Get matrix dimensions. L=(int)mxGetScalar(prhs[2]); a=(int)mxGetScalar(prhs[3]); M=(int)mxGetScalar(prhs[4]); N=L/a; gl = mxGetM(prhs[1]); W = mxGetM(prhs[0])*mxGetN(prhs[0])/(M*N); plhs[0] = ltfatCreateMatrix(L, W,LTFAT_MX_CLASSID, mxCOMPLEX); const LTFAT_REAL _Complex* c_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); const LTFAT_REAL _Complex* g_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[1]); LTFAT_REAL _Complex* f_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); //#ifdef LTFAT_COMPLEXTYPE LTFAT_NAME(idgt_fb)((const LTFAT_REAL (*)[2])c_combined, (const LTFAT_REAL (*)[2])g_combined, L,gl,W,a,M, (LTFAT_REAL (*)[2]) f_combined); /* #else NOT CALLING idgt_fb_r: TO DO: Do it better. LTFAT_NAME(idgt_fb_r)((const LTFAT_REAL (*)[2])c_combined, g_combined, L,gl,W,a,M,(LTFAT_REAL (*)[2]) f_combined); #endif */ return; }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { int L, R, N, c, d, p, q; ltfatInt a,M,h_a,h_m; // Get matrix dimensions. L = mxGetM(prhs[0]); R = mxGetN(prhs[0]); a=(ltfatInt)mxGetScalar(prhs[1]); M=(ltfatInt)mxGetScalar(prhs[2]); N=L/a; c=gcd(a, M, &h_a, &h_m); p=a/c; q=M/c; d=N/q; plhs[0] = ltfatCreateMatrix(p*q*R, c*d,LTFAT_MX_CLASSID,mxCOMPLEX); LTFAT_COMPLEX* gf_combined = mxGetData(plhs[0]); const LTFAT_TYPE* g_combined = mxGetData(prhs[0]); LTFAT_NAME(wfac)(g_combined, L, R, a, M, gf_combined); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int a, M, N, L, W; double tol; const LTFAT_REAL *s, *tgrad, *fgrad; LTFAT_REAL *phase; // Get inputs s = (const LTFAT_REAL*) mxGetPr(prhs[0]); tgrad = (const LTFAT_REAL*) mxGetPr(prhs[1]); fgrad = (const LTFAT_REAL*) mxGetPr(prhs[2]); a = (int)mxGetScalar(prhs[3]); tol = mxGetScalar(prhs[4]); // Get matrix dimensions. M = mxGetM(prhs[0]); N = mxGetN(prhs[0]); L = N*a; W = 1; // Create output matrix and zero it. plhs[0] = ltfatCreateMatrix(M,N, LTFAT_MX_CLASSID, mxREAL); // Get pointer to output phase= (LTFAT_REAL*) mxGetPr(plhs[0]); LTFAT_NAME(heapint)(s,tgrad,fgrad, a, M, L, W,tol, phase); }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { int M, N, L, gl, W; // Get matrix dimensions. M= mxGetM(prhs[0]); N= ltfatGetN(prhs[0]); gl= mxGetNumberOfElements(prhs[1]); W = mxGetNumberOfElements(prhs[0])/(M*N); L=N*M; plhs[0] = ltfatCreateMatrix(L,W,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); const LTFAT_TYPE* c = (const LTFAT_TYPE*) mxGetData(prhs[0]); const LTFAT_TYPE* g = (const LTFAT_TYPE*) mxGetData(prhs[1]); LTFAT_TYPE* f = (LTFAT_TYPE*) mxGetData(plhs[0]); if(gl<L) { LTFAT_NAME(idwiltiii_fb)(c,g,L,gl,W,M,f); } else { LTFAT_NAME(idwiltiii_long)(c,g,L,W,M,f); } }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { int L; double w, c_t, c_f; double *g; L=(int)mxGetScalar(prhs[0]); w=(double)mxGetScalar(prhs[1]); c_t=(double)mxGetScalar(prhs[2]); c_f=(double)mxGetScalar(prhs[3]); if (c_f==0.0) { plhs[0] = mxCreateDoubleMatrix(L, 1, mxREAL); g = mxGetPr(plhs[0]); pgauss_d(L, w, c_t,(double*)g); } else { plhs[0] = ltfatCreateMatrix(L, 1, mxDOUBLE_CLASS, mxCOMPLEX); LTFAT_COMPLEX *gc = mxGetData(plhs[0]); pgauss_cmplx_d(L, w, c_t,c_f,gc); } return; }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { const mxArray* mxf = prhs[0]; const mxArray* mxg = prhs[1]; double* aDouble = (double*) mxGetData(prhs[2]); double* offsetDouble = (double*) mxGetData(prhs[3]); ltfatExtType ext = ltfatExtStringToEnum( mxArrayToString(prhs[4]) ); // input data length mwSize L = mxGetM(mxf); // number of channels mwSize W = mxGetN(mxf); // filter number mwSize M = mxGetNumberOfElements(mxg); // POINTER TO THE INPUT LTFAT_TYPE* fPtr = mxGetData(prhs[0]); // POINTER TO THE FILTERS const LTFAT_TYPE* gPtrs[M]; ltfat_int filtLen[M]; ltfat_int a[M]; ltfat_int offset[M]; // POINTER TO OUTPUTS LTFAT_TYPE* cPtrs[M]; // C99 feature plhs[0] = mxCreateCellMatrix(M, 1); for(mwIndex m=0; m<M; ++m) { a[m]= (ltfat_int) aDouble[m]; offset[m] = (ltfat_int) offsetDouble[m]; filtLen[m] = (ltfat_int) mxGetNumberOfElements(mxGetCell(mxg,m)); mwSize outLen = (mwSize) filterbank_td_size(L,a[m],filtLen[m], offset[m],ext); mxSetCell(plhs[0], m, ltfatCreateMatrix(outLen, W,LTFAT_MX_CLASSID, LTFAT_MX_COMPLEXITY)); cPtrs[m] = mxGetData(mxGetCell(plhs[0],m)); gPtrs[m] = mxGetData(mxGetCell(mxg, m)); } LTFAT_NAME(filterbank_td)(fPtr,gPtrs,L,filtLen,W,a,offset,M,cPtrs,ext); }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { mwSignedIndex L, R, a, M; // Get matrix dimensions. L=(mwSignedIndex)mxGetM(prhs[0]); R=(mwSignedIndex)mxGetN(prhs[0]); a=(mwSignedIndex)mxGetScalar(prhs[1]); M=(mwSignedIndex)mxGetScalar(prhs[2]); plhs[0] = ltfatCreateMatrix(L, R,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); LTFAT_TYPE* gd_combined = mxGetData(plhs[0]); const LTFAT_TYPE* g_combined = mxGetData(prhs[0]); LTFAT_NAME(gabtight_long)(g_combined, L, R, a, M, gd_combined); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { mwSize L = mxGetM(prhs[0]); mwSize W = mxGetN(prhs[0]); mwSize M = mxGetNumberOfElements(prhs[1]); const LTFAT_TYPE* fPtr = (const LTFAT_TYPE*) mxGetPr(prhs[0]); const double* indVecPtr = (const double*) mxGetPr(prhs[1]); plhs[0] = ltfatCreateMatrix(M,W,LTFAT_MX_CLASSID,mxCOMPLEX); LTFAT_REAL _Complex* cPtr = (LTFAT_REAL _Complex*) mxGetPr(plhs[0]); LTFAT_NAME(gga)(fPtr,indVecPtr,L,W,M,cPtr); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, R, a, M; L=(int)mxGetScalar(prhs[1]); a=(int)mxGetScalar(prhs[2]); M=(int)mxGetScalar(prhs[3]); R=mxGetM(prhs[0])*mxGetN(prhs[0])/L; plhs[0] = ltfatCreateMatrix(L,R,LTFAT_MX_CLASSID,mxCOMPLEX); const LTFAT_REAL _Complex* gf_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); LTFAT_REAL _Complex* g_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); LTFAT_NAME(iwfac)((const LTFAT_REAL (*)[2])gf_combined, L, R, a, M, (LTFAT_REAL (*)[2])g_combined); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { mwSize L = mxGetM(prhs[0]); mwSize W = mxGetN(prhs[0]); mwSize K = (mwSize) mxGetScalar(prhs[1]); double deltao = mxGetScalar(prhs[2]); double o = mxGetScalar(prhs[3]); const LTFAT_TYPE* fPtr = (const LTFAT_TYPE*) mxGetData(prhs[0]); plhs[0] = ltfatCreateMatrix(K,W,LTFAT_MX_CLASSID,mxCOMPLEX); LTFAT_REAL _Complex* cPtr = (LTFAT_REAL _Complex*) mxGetPr(plhs[0]); LTFAT_NAME(chzt)(fPtr,L,W,K,deltao,o,cPtr); //LTFAT_NAME(chzt_fact)(fPtr,L,W,K,deltao,o,cPtr); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, R, a, M; // Get matrix dimensions. L=(int)mxGetM(prhs[0]); R=(int)mxGetN(prhs[0]); a=(int)mxGetScalar(prhs[1]); M=(int)mxGetScalar(prhs[2]); plhs[0] = ltfatCreateMatrix(L, R,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); LTFAT_TYPE* gd_combined = (LTFAT_TYPE*) mxGetData(plhs[0]); const LTFAT_TYPE* g_combined = (const LTFAT_TYPE*) mxGetData(prhs[0]); LTFAT_NAME(gabtight_long)(g_combined, L, R, a, M, gd_combined); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { // UGLY, will go away as soon as ltfat backend is unified to a naming convenion // Other option is to use forwarder functions #undef LTFAT_NAME #ifdef LTFAT_SINGLE # define LTFAT_NAME(name) LTFAT_NAME_SINGLE(name) #else # define LTFAT_NAME(name) LTFAT_NAME_DOUBLE(name) #endif int L, R, a, M, N, c, d, p, q,h_a,h_m; // Get matrix dimensions. L = mxGetM(prhs[0]); R = mxGetN(prhs[0]); a=(int)mxGetScalar(prhs[1]); M=(int)mxGetScalar(prhs[2]); N=L/a; c=gcd(a, M,&h_a, &h_m); p=a/c; q=M/c; d=N/q; plhs[0] = ltfatCreateMatrix(p*q*R, c*d,LTFAT_MX_CLASSID,mxCOMPLEX); LTFAT_REAL _Complex* gf_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); #ifdef LTFAT_COMPLEXTYPE const LTFAT_REAL _Complex* g_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); LTFAT_NAME(wfac)((const LTFAT_REAL (*)[2])g_combined, L, R, a, M, (LTFAT_REAL (*)[2])gf_combined); #else const LTFAT_REAL* g_combined = (const LTFAT_REAL*) mxGetData(prhs[0]); LTFAT_NAME(wfac_r)(g_combined, L, R, a, M, (LTFAT_REAL (*)[2])gf_combined); #endif return; }
/* Calling convention: * cout=comp_col2diag(cin); */ void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L = mxGetM(prhs[0]); plhs[0] = ltfatCreateMatrix(L, L, LTFAT_MX_CLASSID, LTFAT_MX_COMPLEXITY); #ifdef NOCOMPLEXFMTCHANGE LTFAT_REAL* cout_r = (LTFAT_REAL*) mxGetPr(plhs[0]); LTFAT_REAL* cin_r = (LTFAT_REAL*) mxGetPr(prhs[0]); LTFAT_NAME(fwd_col2diag)(cin_r,L,cout_r); #ifdef LTFAT_COMPLEXTYPE // Treat the imaginary part LTFAT_REAL* cin_i= (LTFAT_REAL*) mxGetPi(prhs[0]); LTFAT_REAL* cout_i= (LTFAT_REAL*) mxGetPi(plhs[0]); LTFAT_NAME(fwd_col2diag)(cin_i, L,cout_i); #endif #else LTFAT_TYPE* cin_r= (LTFAT_TYPE*) mxGetData(prhs[0]); LTFAT_TYPE* cout_r= (LTFAT_TYPE*) mxGetData(plhs[0]); LTFAT_NAME(col2diag)(cin_r, L,cout_r); #endif }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { mwSignedIndex a, M, N, L; const LTFAT_REAL *s,*tgrad, *fgrad; LTFAT_REAL *sr; // Get matrix dimensions. M = mxGetM(prhs[0]); N = mxGetN(prhs[0]); a = (mwSignedIndex)mxGetScalar(prhs[3]); L = N*a; s = mxGetData(prhs[0]); tgrad = mxGetData(prhs[1]); fgrad = mxGetData(prhs[2]); plhs[0] = ltfatCreateMatrix(M,N, LTFAT_MX_CLASSID, mxREAL); sr = mxGetData(plhs[0]); LTFAT_NAME(gabreassign)(s,tgrad,fgrad,L,1,a,M,sr); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, W, a, M, N, M2; // Get matrix dimensions. L = mxGetM(prhs[0]); W = mxGetN(prhs[0]); a=(int)mxGetScalar(prhs[2]); M=(int)mxGetScalar(prhs[3]); N=L/a; M2 = (M/2)+1; plhs[0] = ltfatCreateMatrix(M2, N*W,LTFAT_MX_CLASSID,mxCOMPLEX); const LTFAT_REAL * f = (const LTFAT_REAL *) mxGetData(prhs[0]); const LTFAT_REAL * g = (const LTFAT_REAL *) mxGetData(prhs[1]); LTFAT_REAL _Complex* out_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); LTFAT_NAME(dgtreal_long)(f,g, L, W, a, M, (LTFAT_REAL (*)[2]) out_combined); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, W, a, M, N, gl; // Get matrix dimensions. L=(int)mxGetScalar(prhs[2]); a=(int)mxGetScalar(prhs[3]); M=(int)mxGetScalar(prhs[4]); N=L/a; W = mxGetN(prhs[0])/N; gl = mxGetM(prhs[1]); plhs[0] = ltfatCreateMatrix(L, W,LTFAT_MX_CLASSID,mxREAL); const LTFAT_COMPLEX* c_combined = (const LTFAT_COMPLEX*) mxGetData(prhs[0]); const LTFAT_REAL * gf = (const LTFAT_REAL *) mxGetData(prhs[1]); LTFAT_REAL* f_r = (LTFAT_REAL*) mxGetData(plhs[0]); LTFAT_NAME(idgtreal_fb)(c_combined,gf,L,gl,W,a,M,f_r); return; }
/* Calling convention: * cout=comp_col2diag(cin); */ void LTFAT_NAME(ltfatMexFnc)(int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { mwSize L = mxGetM(prhs[0]); plhs[0] = ltfatCreateMatrix(L, L, LTFAT_MX_CLASSID, LTFAT_MX_COMPLEXITY); #if defined(NOCOMPLEXFMTCHANGE) && !(MX_HAS_INTERLEAVED_COMPLEX) LTFAT_REAL* cout_r = mxGetData(plhs[0]); LTFAT_REAL* cin_r = mxGetData(prhs[0]); LTFAT_NAME(fwd_col2diag)(cin_r,L,cout_r); #ifdef LTFAT_COMPLEXTYPE // Treat the imaginary part LTFAT_REAL* cin_i= mxGetImagData(prhs[0]); LTFAT_REAL* cout_i= mxGetImagData(plhs[0]); LTFAT_NAME(fwd_col2diag)(cin_i, L,cout_i); #endif /* LTFAT_COMPLEXTYPE */ #else /* not NOCOMPLEXFMTCHANGE */ LTFAT_TYPE* cin_r= mxGetData(prhs[0]); LTFAT_TYPE* cout_r= mxGetData(plhs[0]); LTFAT_NAME(col2diag)(cin_r, L,cout_r); #endif /* NOCOMPLEXFMTCHANGE */ }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { ltfatInt a, M, L, Lg, lt1, lt2; double *lt; // Get matrix dimensions. Lg = mxGetM(prhs[0]); a=(ltfatInt)mxGetScalar(prhs[1]); M=(ltfatInt)mxGetScalar(prhs[2]); L=(ltfatInt)mxGetScalar(prhs[4]); // Read the values of lt and round them to integers. lt = mxGetPr(prhs[3]); lt1 = ltfat_round(lt[0]); lt2 = ltfat_round(lt[1]); plhs[0] = ltfatCreateMatrix(L, lt2,LTFAT_MX_CLASSID,mxCOMPLEX); const LTFAT_COMPLEX* g_combined = (const LTFAT_COMPLEX*) mxGetData(prhs[0]); LTFAT_COMPLEX* out_combined = (LTFAT_COMPLEX*) mxGetData(plhs[0]); LTFAT_NAME(nonsepwin2multi)(g_combined,L,Lg,a,M,lt1,lt2,out_combined); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, W, a, M, N; // Get matrix dimensions. L=(int)mxGetScalar(prhs[2]); a=(int)mxGetScalar(prhs[3]); M=(int)mxGetScalar(prhs[4]); N=L/a; W = mxGetN(prhs[0])/N; plhs[0] = ltfatCreateMatrix(L, W,LTFAT_MX_CLASSID,mxREAL); const LTFAT_REAL _Complex* c_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); const LTFAT_REAL _Complex* gf_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[1]); LTFAT_REAL* f_r = (LTFAT_REAL*) mxGetData(plhs[0]); LTFAT_NAME(idgtreal_fac)((const LTFAT_REAL (*)[2])c_combined, (const LTFAT_REAL (*)[2])gf_combined, L,W,a,M,f_r); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { static int atExitRegistered = 0; if(!atExitRegistered) { LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(fftrealAtExit)); atExitRegistered = 1; } mwSignedIndex L, W, L2; LTFAT_REAL *f, *cout_r, *cout_i; LTFAT_FFTW(iodim) dims[1], howmanydims[1]; LTFAT_FFTW(plan) p; L = mxGetM(prhs[0]); W = mxGetN(prhs[0]); L2 = (L/2)+1; // Get pointer to input. f= mxGetData(prhs[0]); plhs[0] = ltfatCreateMatrix(L2, W, LTFAT_MX_CLASSID, mxCOMPLEX); // Get pointer to output. cout_r = mxGetData(plhs[0]); cout_i = mxGetImagData(plhs[0]); // Create plan. Copy data from f to cout. dims[0].n = L; dims[0].is = 1; dims[0].os = 1; howmanydims[0].n = W; howmanydims[0].is = L; howmanydims[0].os = L2; // The calling prototype //fftw_plan fftw_plan_guru_split_dft_r2c( // int rank, const fftw_iodim *dims, // int howmany_rank, const fftw_iodim *howmany_dims, // double *in, double *ro, double *io, // unsigned flags); /* We are violating this here: You must create the plan before initializing the input, because FFTW_MEASURE overwrites the in/out arrays. (Technically, FFTW_ESTIMATE does not touch your arrays, but you should always create plans first just to be sure.) */ p = LTFAT_FFTW(plan_guru_split_dft_r2c)(1, dims, 1, howmanydims, f, cout_r, cout_i, FFTW_ESTIMATE); /* ... creating a new plan is quick once one exists for a given size ... so why not to store the old plan.. */ LTFAT_NAME(fftrealAtExit)(); LTFAT_NAME(p_old) = p; // Real FFT. LTFAT_FFTW(execute)(p); // LTFAT_FFTW(destroy_plan)(p); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[]) { const mxArray* mxs = prhs[0]; const mxArray* mxtgrad = prhs[1]; const mxArray* mxfgrad = prhs[2]; const mxArray* mxa = prhs[3]; const mxArray* mxcfreq = prhs[4]; ltfatInt M = mxGetNumberOfElements(mxs); const LTFAT_REAL* sPtr[M]; const LTFAT_REAL* tgradPtr[M]; const LTFAT_REAL* fgradPtr[M]; double aPtr[M]; double cfreqPtr[M]; LTFAT_REAL* srPtr[M]; ltfatInt N[M]; mxArray* mxsr = mxCreateCellMatrix(M, 1); plhs[0] = mxsr; const double* a = mxGetPr(mxa); const double* cfreq = mxGetPr(mxcfreq); memcpy(aPtr, a, M * sizeof * a); memcpy(cfreqPtr, cfreq, M * sizeof * cfreq); for (ltfatInt m = 0; m < M; m++) { N[m] = mxGetM(mxGetCell(mxs, m)); sPtr[m] = mxGetData(mxGetCell(mxs, m)); tgradPtr[m] = mxGetData(mxGetCell(mxtgrad, m)); fgradPtr[m] = mxGetData(mxGetCell(mxfgrad, m)); mxSetCell(mxsr, m, ltfatCreateMatrix(N[m], 1, LTFAT_MX_CLASSID, mxREAL)); srPtr[m] = mxGetData(mxGetCell(mxsr, m)); } // This function uses optional output arguments fbreassOptOut* optout = NULL; mxArray* repos; ltfatInt sumN = 0; if (nlhs > 1) { for (ltfatInt ii = 0; ii < M; ii++) { sumN += N[ii]; } repos = mxCreateCellMatrix(sumN, 1); plhs[1] = repos; optout = fbreassOptOut_init(sumN, 16 ); } // Adjust a ltfatInt acols = mxGetN(mxa); if (acols > 1) { for (ltfatInt m = 0; m < M; m++) { aPtr[m] /= a[M + m]; } } // Run it LTFAT_NAME(filterbankreassign)(sPtr, tgradPtr, fgradPtr, N, a, cfreqPtr, M, srPtr, REASS_DEFAULT, optout); // Process the optional output if (optout != NULL) { for (ltfatInt ii = 0; ii < sumN; ii++) { ltfatInt l = optout->reposl[ii]; // Create an array of a proper length. even an empty one mxArray* cEl = mxCreateDoubleMatrix( l , l > 0 ? 1 : 0, mxREAL); mxSetCell(repos, ii, cEl); double* cElPtr = mxGetPr(cEl); // Convert to double and +1 to Matlab indexes... for (ltfatInt jj = 0; jj < optout->reposl[ii]; jj++) { cElPtr[jj] = (double) (optout->repos[ii][jj] + 1.0); } } fbreassOptOut_destroy(optout); } }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { // Register exit function only once static int atExitFncRegistered = 0; if (!atExitFncRegistered) { LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(dctMexAtExitFnc)); atExitFncRegistered = 1; } LTFAT_REAL *c_r, *c_i=NULL; const LTFAT_REAL *f_r, *f_i=NULL; dct_kind kind = DCTI; // This is overwritten mwIndex L = mxGetM(prhs[0]); mwIndex W = mxGetN(prhs[0]); mwIndex type = (mwIndex) mxGetScalar(prhs[1]); // Copy inputs and get pointers if ( mxIsComplex(prhs[0])) { f_i = mxGetImagData(prhs[0]); plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxCOMPLEX); c_i = mxGetImagData(plhs[0]); } else { plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxREAL); } f_r = mxGetData(prhs[0]); c_r = mxGetData(plhs[0]); switch (type) { case 1: kind = DCTI; break; case 2: kind = DCTII; break; case 3: kind = DCTIII; break; case 4: kind = DCTIV; break; default: mexErrMsgTxt("Unknown type."); } LTFAT_FFTW(plan) p = LTFAT_NAME(dct_init)( L, W, c_r, kind); /* The old plan is freed after the new one is cretaed. According to the FFTW doc. creating new plan is quick as long as there already exists a plan for the same length. */ LTFAT_NAME(dctMexAtExitFnc)(); LTFAT_NAME(p_old) = p; LTFAT_NAME(dct_execute)(p, f_r, L, W, c_r, kind); if ( mxIsComplex(prhs[0])) { LTFAT_NAME(dct_execute)(p, f_i, L, W, c_i, kind); } return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { #ifdef LTFAT_DOUBLE if(p_old==0) { mexAtExit(fftrealAtExit); } #endif int L, W, L2; LTFAT_REAL *f, *cout_r, *cout_i; LTFAT_FFTW(iodim) dims[1], howmanydims[1]; LTFAT_FFTW(plan) p; L = mxGetM(prhs[0]); W = mxGetN(prhs[0]); L2 = (L/2)+1; // Get pointer to input. f= (LTFAT_REAL*) mxGetPr(prhs[0]); plhs[0] = ltfatCreateMatrix(L2, W, LTFAT_MX_CLASSID, mxCOMPLEX); // Get pointer to output. cout_r = (LTFAT_REAL*) mxGetPr(plhs[0]); cout_i = (LTFAT_REAL*) mxGetPi(plhs[0]); // Create plan. Copy data from f to cout. dims[0].n = L; dims[0].is = 1; dims[0].os = 1; howmanydims[0].n = W; howmanydims[0].is = L; howmanydims[0].os = L2; // The calling prototype //fftw_plan fftw_plan_guru_split_dft_r2c( // int rank, const fftw_iodim *dims, // int howmany_rank, const fftw_iodim *howmany_dims, // double *in, double *ro, double *io, // unsigned flags); /* We are violating this here: You must create the plan before initializing the input, because FFTW_MEASURE overwrites the in/out arrays. (Technically, FFTW_ESTIMATE does not touch your arrays, but you should always create plans first just to be sure.) */ p = LTFAT_FFTW(plan_guru_split_dft_r2c)(1, dims, 1, howmanydims, f, cout_r, cout_i, FFTW_ESTIMATE); /* FFTW documentation qote http://www.fftw.org/fftw3_doc/New_002darray-Execute-Functions.html#New_002darray-Execute-Functions: ... creating a new plan is quick once one exists for a given size ... so why not to store the old plan.. */ if(p_old!=0) { fftw_destroy_plan(*p_old); free(p_old); } p_old = malloc(sizeof(p)); memcpy(p_old,&p,sizeof(p)); // Real FFT. LTFAT_FFTW(execute)(p); // LTFAT_FFTW(destroy_plan)(p); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { static int atExitFncRegistered = 0; if(!atExitFncRegistered) { LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(fftblMexAtExitFnc)); atExitFncRegistered = 1; } const mxArray* mxc = prhs[0]; const mxArray* mxG = prhs[1]; double* foffDouble = mxGetData(prhs[2]); double* a = mxGetData(prhs[3]); double* realonlyDouble = mxGetData(prhs[4]); // number of channels mwSize W = mxGetN(mxGetCell(mxc,0)); // filter number mwSize M = mxGetNumberOfElements(mxG); // mwSize acols = mxGetN(prhs[3]); double afrac[M]; memcpy(afrac,a,M*sizeof(double)); if(acols>1) { for(mwIndex m=0; m<M; m++) { afrac[m] = afrac[m]/a[M+m]; } } // POINTER TO THE FILTERS const LTFAT_COMPLEX* GPtrs[M]; // input lengths mwSize inLen[M]; mwSignedIndex foff[M]; int realonly[M]; // POINTER TO INPUTS const LTFAT_COMPLEX* cPtrs[M]; // filter lengths mwSize Gl[M]; if(M!=LTFAT_NAME(oldM) || W!=LTFAT_NAME(oldW)) { LTFAT_NAME(fftblMexAtExitFnc)(); LTFAT_NAME(oldM) = M; LTFAT_NAME(oldW) = W; LTFAT_NAME(oldLc) = ltfat_calloc(M,sizeof(mwSize)); LTFAT_NAME(oldPlans) = ltfat_calloc(M,sizeof*LTFAT_NAME(oldPlans)); } // output data length mwSize L = (mwSize) floor(afrac[0]*mxGetM(mxGetCell(mxc, 0)) + 0.5); // over all channels for(mwIndex m =0; m<M; m++) { foff[m] = (mwSignedIndex) foffDouble[m]; realonly[m] = (realonlyDouble[m]>1e-3); cPtrs[m] = mxGetData(mxGetCell(mxc,m)); inLen[m] = (mwSize) mxGetM(mxGetCell(mxc, m)); GPtrs[m] = mxGetData(mxGetCell(mxG, m)); Gl[m] = (mwSize) mxGetNumberOfElements(mxGetCell(mxG, m)); if(LTFAT_NAME(oldLc)[m]!=inLen[m]) { LTFAT_NAME(oldLc)[m] = inLen[m]; LTFAT_NAME(upconv_fftbl_plan) ptmp = LTFAT_NAME(upconv_fftbl_init)(L, Gl[m], W, afrac[m]); if(LTFAT_NAME(oldPlans)[m]!=0) { LTFAT_NAME(upconv_fftbl_done)(LTFAT_NAME(oldPlans)[m]); } LTFAT_NAME(oldPlans)[m]=ptmp; } } plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxCOMPLEX); mxArray* mxF = plhs[0]; LTFAT_COMPLEX* FPtr = mxGetData(mxF); LTFAT_NAME(ifilterbank_fftbl_execute)( LTFAT_NAME(oldPlans), cPtrs, GPtrs, M, foff, realonly, FPtr); //LTFAT_NAME(ifilterbank_fftbl)( cPtrs, GPtrs,L,Gl,W,afrac, // M, foff, realonly, FPtr); }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { static int atExitFncRegistered = 0; if(!atExitFncRegistered) { LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(fftblMexAtExitFnc)); atExitFncRegistered = 1; } const mxArray* mxF = prhs[0]; const mxArray* mxG = prhs[1]; double* foffDouble = (double*) mxGetData(prhs[2]); double* a = (double*) mxGetData(prhs[3]); double* realonlyDouble = (double*) mxGetData(prhs[4]); // input data length mwSize L = mxGetM(mxF); // number of channels mwSize W = mxGetN(mxF); // filter number mwSize M = mxGetNumberOfElements(mxG); // mwSize acols = mxGetN(prhs[3]); double afrac[M]; memcpy(afrac,a,M*sizeof*a); if(acols>1) { for(mwIndex m=0; m<M; m++) { afrac[m] = afrac[m]/a[M+m]; } } // output lengths mwSize outLen[M]; // Frequency offsets mwSignedIndex foff[M]; // realonly int realonly[M]; // POINTER TO THE INPUT LTFAT_COMPLEX* FPtr = mxGetData(prhs[0]); // POINTER TO THE FILTERS const LTFAT_COMPLEX* GPtrs[M]; // filter lengths mwSize Gl[M]; // POINTER TO OUTPUTS LTFAT_COMPLEX* cPtrs[M]; // C99 feature plhs[0] = mxCreateCellMatrix(M, 1); if(M!=LTFAT_NAME(oldM) || W != LTFAT_NAME(oldW)) { LTFAT_NAME(fftblMexAtExitFnc)(); LTFAT_NAME(oldM) = M; LTFAT_NAME(oldW) = W; LTFAT_NAME(oldLc) = ltfat_calloc(M,sizeof(mwSize)); LTFAT_NAME(oldPlans) = ltfat_calloc(M,sizeof*LTFAT_NAME(oldPlans)); } for(mwIndex m=0; m<M; ++m) { foff[m] = (mwSignedIndex) foffDouble[m]; realonly[m] = (realonlyDouble[m]>1e-3); outLen[m] = (mwSize) floor( L/afrac[m] +0.5); GPtrs[m] = mxGetData(mxGetCell(mxG, m)); Gl[m] = mxGetNumberOfElements(mxGetCell(mxG, m)); mxSetCell(plhs[0], m, ltfatCreateMatrix(outLen[m], W, LTFAT_MX_CLASSID,mxCOMPLEX)); cPtrs[m] = mxGetData(mxGetCell(plhs[0],m)); if(LTFAT_NAME(oldLc)[m]!=outLen[m]) { LTFAT_NAME(oldLc)[m] = outLen[m]; LTFAT_NAME(convsub_fftbl_plan) ptmp = LTFAT_NAME(convsub_fftbl_init)( L, Gl[m], W, afrac[m], cPtrs[m]); if(LTFAT_NAME(oldPlans)[m]!=0) { LTFAT_NAME(convsub_fftbl_done)(LTFAT_NAME(oldPlans)[m]); } LTFAT_NAME(oldPlans)[m]=ptmp; } } LTFAT_NAME(filterbank_fftbl_execute)( LTFAT_NAME(oldPlans),FPtr, GPtrs, M, foff, realonly, cPtrs); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { #ifdef _DEBUG static int atExitFncRegistered = 0; if(!atExitFncRegistered) { LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(tdMexAtExitFnc)); atExitFncRegistered = 1; } #endif const mxArray* mxf = prhs[0]; const mxArray* mxg = prhs[1]; double* a = (double*) mxGetData(prhs[2]); double* offset = (double*) mxGetData(prhs[3]); char* ext = mxArrayToString(prhs[4]); // input data length mwSize L = mxGetM(mxf); // number of channels mwSize W = mxGetN(mxf); // filter number mwSize M = mxGetNumberOfElements(mxg); // filter lengths mwSize filtLen[M]; //mwSize* filtLen = mxMalloc(M*sizeof(mwSize)); for(unsigned int m=0;m<M;m++) { filtLen[m] = (mwSize) mxGetNumberOfElements(mxGetCell(mxg,m)); } // output lengths mwSize outLen[M]; //mwSize* outLen = mxMalloc(M*sizeof(mwSize)); if(!strcmp(ext,"per")) { for(unsigned int m = 0; m < M; m++) { outLen[m] = (mwSize) ceil( L/a[m] ); } } else if(!strcmp(ext,"valid")) { for(unsigned int m = 0; m < M; m++) { outLen[m] = (mwSize) ceil( (L-(filtLen[m]-1))/a[m] ); } } else { for(unsigned int m = 0; m < M; m++) { outLen[m] = (mwSize) ceil( (L + filtLen[m] - 1 + offset[m] )/a[m] ); } } // POINTER TO THE INPUT LTFAT_TYPE* fPtr = (LTFAT_TYPE*) mxGetData(prhs[0]); // POINTER TO THE FILTERS LTFAT_TYPE* gPtrs[M]; // LTFAT_TYPE** gPtrs = (LTFAT_TYPE**) mxMalloc(M*sizeof(LTFAT_TYPE*)); for(mwIndex m=0;m<M;m++) { gPtrs[m] = (LTFAT_TYPE*) mxGetPr(mxGetCell(mxg, m)); } // POINTER TO OUTPUTS LTFAT_TYPE* cPtrs[M]; // C99 feature //LTFAT_TYPE** cPtrs = (LTFAT_TYPE**) mxMalloc(M*sizeof(LTFAT_TYPE*)); plhs[0] = mxCreateCellMatrix(M, 1); for(mwIndex m=0;m<M;++m) { mxSetCell(plhs[0], m, ltfatCreateMatrix(outLen[m], W,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY)); cPtrs[m] = (LTFAT_TYPE*) mxGetData(mxGetCell(plhs[0],m)); memset(cPtrs[m],0,outLen[m]*W*sizeof(LTFAT_TYPE)); } // over all channels // #pragma omp parallel for private(m) for(mwIndex m =0; m<M; m++) { for(mwIndex w =0; w<W; w++) { // Obtain pointer to w-th column in input LTFAT_TYPE *fPtrCol = fPtr + w*L; // Obtaing pointer to w-th column in m-th element of output cell-array LTFAT_TYPE *cPtrCol = cPtrs[m] + w*outLen[m]; //conv_td_sub(fPtrCol,L,&cPtrCol,outLen[m],(const double**)&gPtrs[m],filtLen[m],1,a[m],skip[m],ltfatExtStringToEnum(ext),0); LTFAT_NAME(convsub_td)(fPtrCol,L,cPtrCol,outLen[m],gPtrs[m],filtLen[m],a[m],-offset[m],ltfatExtStringToEnum(ext)); } } }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { // Register exit function only once #ifdef LTFAT_DOUBLE if(p_old==0) { mexAtExit(fftrealAtExit); } #endif mwIndex L, W, N, type; LTFAT_REAL *f_r, *f_i; LTFAT_FFTW(iodim) dims[1], howmanydims[1]; LTFAT_FFTW(plan) p; LTFAT_FFTW(r2r_kind) kind[1]; L = mxGetM(prhs[0]); W = mxGetN(prhs[0]); N = 2*L; type = (mwIndex) mxGetScalar(prhs[1]); // Copy inputs and get pointers if( mxIsComplex(prhs[0])) { plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxCOMPLEX); f_i = (LTFAT_REAL*) mxGetPi(plhs[0]); memcpy(f_i,mxGetPi(prhs[0]),W*L*sizeof(LTFAT_REAL)); } else { plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxREAL); } f_r = (LTFAT_REAL*) mxGetPr(plhs[0]); memcpy(f_r,mxGetPr(prhs[0]),W*L*sizeof(LTFAT_REAL)); // Create plan. Copy data from f to cout. dims[0].n = L; dims[0].is = 1; dims[0].os = 1; howmanydims[0].n = W; howmanydims[0].is = L; howmanydims[0].os = L; LTFAT_REAL sqrt2 = (LTFAT_REAL) sqrt(2.0); LTFAT_REAL postScale = (LTFAT_REAL) 1.0/sqrt2; LTFAT_REAL scale = (LTFAT_REAL) sqrt2*(1.0/(double)N)*sqrt((double)L); // Re-allocate and prescale input if(type==1||type==3) { for(mwIndex ii=0; ii<W; ii++) { f_r[ii*L] *= sqrt2; } if(mxIsComplex(prhs[0])) { for(mwIndex ii=0; ii<W; ii++) { f_i[ii*L] *= sqrt2; } } } switch(type) { case 1: N -= 2; for(mwIndex ii=0; ii<W; ii++) { f_r[(ii+1)*L-1] *= sqrt2; } if(mxIsComplex(prhs[0])) { for(mwIndex ii=0; ii<W; ii++) { f_i[(ii+1)*L-1] *= sqrt2; } } scale = (LTFAT_REAL) sqrt2*(1.0/((double)N))*sqrt((double)L-1); kind[0] = FFTW_REDFT00; break; case 2: kind[0] = FFTW_REDFT10; break; case 3: kind[0] = FFTW_REDFT01; break; case 4: kind[0] = FFTW_REDFT11; break; default: mexErrMsgTxt("Unknown type."); } // The calling prototype //fftw_plan fftw_plan_guru_split_dft_r2c( // int rank, const fftw_iodim *dims, // int howmany_rank, const fftw_iodim *howmany_dims, // double *in, double *ro, double *io, // unsigned flags); p = LTFAT_FFTW(plan_guru_r2r)(1, dims, 1, howmanydims, f_r, f_r, kind, FFTW_OPTITYPE); /* FFTW documentation qote http://www.fftw.org/fftw3_doc/New_002darray-Execute-Functions.html#New_002darray-Execute-Functions: ... creating a new plan is quick once one exists for a given size ... so why not to store the old plan.. */ if(p_old!=0) { fftw_destroy_plan(*p_old); free(p_old); } p_old = malloc(sizeof(p)); memcpy(p_old,&p,sizeof(p)); // Real FFT. LTFAT_FFTW(execute)(p); // Do the normalization for(int ii=0; ii<L*W; ii++) { f_r[ii] *= scale; } if(type==1||type==2) { // Scale DC component for(int ii=0; ii<W; ii++) { f_r[ii*L] *= postScale; } } if(type==1) { // Scale AC component for(int ii=0; ii<W; ii++) { f_r[(ii+1)*L-1] *= postScale; } } // If the input is complex, process the imaginary part if(mxIsComplex(prhs[0])) { LTFAT_FFTW(execute_r2r)(p,f_i,f_i); // Do the normalization for(int ii=0; ii<L*W; ii++) { f_i[ii] *= scale; } if(type==1||type==2) { // Scale DC component for(int ii=0; ii<W; ii++) { f_i[ii*L] *= postScale; } } if(type==1) { // Scale AC component for(int ii=0; ii<W; ii++) { f_i[(ii+1)*L-1] *= postScale; } } } // LTFAT_FFTW(destroy_plan)(p); return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { // Register exit function only once static int atExitFncRegistered = 0; if(!atExitFncRegistered) { LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(dctMexAtExitFnc)); atExitFncRegistered = 1; } LTFAT_REAL *c_r, *c_i; const LTFAT_REAL *f_r, *f_i; dct_kind kind; mwIndex L = mxGetM(prhs[0]); mwIndex W = mxGetN(prhs[0]); mwIndex type = (mwIndex) mxGetScalar(prhs[1]); // Copy inputs and get pointers if( mxIsComplex(prhs[0])) { f_i = mxGetImagData(prhs[0]); plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxCOMPLEX); c_i = mxGetImagData(plhs[0]); } else { plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID, mxREAL); } f_r = mxGetData(prhs[0]); c_r = mxGetData(plhs[0]); switch(type) { case 1: kind = DSTI; break; case 2: kind = DSTII; break; case 3: kind = DSTIII; break; case 4: kind = DSTIV; break; default: mexErrMsgTxt("Unknown type."); } LTFAT_FFTW(plan) p = LTFAT_NAME(dst_init)( L, W, c_r, kind); LTFAT_NAME(dctMexAtExitFnc)(); LTFAT_NAME(p_old) = p; LTFAT_NAME(dst_execute)(p,f_r,L,W,c_r,kind); if( mxIsComplex(prhs[0])) { LTFAT_NAME(dst_execute)(p,f_i,L,W,c_i,kind); } return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { #ifdef LTFAT_DOUBLE if(p_old==0) { mexAtExit(ifftrealAtExit); } #endif mwSize ii, L, W, L2; LTFAT_FFTW(plan) p; LTFAT_REAL *f, s; LTFAT_REAL *fin_r, *fin_i; L2 = (mwSize) mxGetM(prhs[0]); W = (mwSize) mxGetN(prhs[0]); L = (mwSize) mxGetScalar(prhs[1]); if(L/2+1!=L2) mexErrMsgTxt("Invalid output length"); fin_r = (LTFAT_REAL*)mxGetPr(prhs[0]); fin_i = (LTFAT_REAL*)mxGetPi(prhs[0]); // Case when input is real if(!mxIsComplex(prhs[0])) { mxArray* tmpIn = ltfatCreateMatrix(L2, W, LTFAT_MX_CLASSID , mxCOMPLEX); LTFAT_REAL *fin_r_old = (LTFAT_REAL*)mxGetPr(prhs[0]); fin_r = (LTFAT_REAL*)mxGetPr(tmpIn); fin_i = (LTFAT_REAL*)mxGetPi(tmpIn); for(mwIndex jj=0;jj<L2*W;jj++) { fin_r[jj]= fin_r_old[jj]; fin_i[jj]= (LTFAT_REAL )0.0; } } // Create output and get pointer plhs[0] = ltfatCreateMatrix(L, W, LTFAT_MX_CLASSID , mxREAL); f= (LTFAT_REAL*) mxGetPr(plhs[0]); // This section is not being compiled. It contains a segmentation // faults. The idea is to pass Matlab's split memory layout directly // to FFTW LTFAT_FFTW(iodim) dims[1], howmanydims[1]; // Create plan. Copy data from cin to f. dims[0].n = L; dims[0].is = 1; dims[0].os = 1; howmanydims[0].n = W; howmanydims[0].is = L2; howmanydims[0].os = L; // The calling prototype // fftw_plan fftw_plan_guru_split_dft_c2r( // int rank, const fftw_iodim *dims, // int howmany_rank, const fftw_iodim *howmany_dims, // double *ri, double *ii, double *out, // unsigned flags); p = LTFAT_FFTW(plan_guru_split_dft_c2r)(1, dims, 1, howmanydims, fin_r,fin_i,f, FFTW_OPTITYPE); if(p_old!=0) { fftw_destroy_plan(*p_old); free(p_old); } p_old = malloc(sizeof(p)); memcpy(p_old,&p,sizeof(p)); // Real IFFT. LTFAT_FFTW(execute)(p); //LTFAT_FFTW(destroy_plan)(p); // Scale, because FFTW's normalization is different. s = (LTFAT_REAL) (1.0/((LTFAT_REAL)L)); for (ii=0; ii<L*W; ii++) { f[ii] *=s; } return; }
/* %COMP_IFILTERBANK_TD Synthesis filterbank % Usage: f=comp_ifilterbank_fft(c,g,a,Ls,offset,ext); % % Input parameters: % c : Cell array of length M, each element is N(m)*W matrix. % g : Filterbank filters - length M cell-array, each element is vector of length filtLen(m) % a : Upsampling factors - array of length M. % offset : Delay of the filters - scalar or array of length M. % Ls : Output length. % ext : Border exension technique. % % Output parameters: % f : Output Ls*W array. % */ void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { // printf("Filename: %s, Function name %s, %d \n.",__FILE__,__func__,mxIsDouble(prhs[0])); const mxArray* mxc = prhs[0]; const mxArray* mxg = prhs[1]; double* a = mxGetPr(prhs[2]); double* Lsdouble = mxGetPr(prhs[3]); unsigned int Ls = (unsigned int) *Lsdouble; double* offset = mxGetPr(prhs[4]); char* ext = mxArrayToString(prhs[5]); // number of channels unsigned int W = mxGetN(mxGetCell(mxc,0)); // filter number unsigned int M = mxGetNumberOfElements(mxg); // input data length unsigned int* Lc = mxMalloc(M*sizeof(unsigned int)); for(unsigned int m=0;m<M;m++) { Lc[m] = (unsigned int) mxGetM(mxGetCell(mxc,m)); } // filter lengths unsigned int* filtLen = mxMalloc(M*sizeof(unsigned int)); for(unsigned int m=0;m<M;m++) { filtLen[m] = (unsigned int) mxGetNumberOfElements(mxGetCell(mxg,m)); } // POINTER TO THE INPUT LTFAT_TYPE** cPtrs = (LTFAT_TYPE**) mxMalloc(M*sizeof(LTFAT_TYPE*)); for(unsigned int m=0;m<M;++m) { cPtrs[m] = (LTFAT_TYPE*) mxGetData(mxGetCell(mxc,m)); } // allocate output plhs[0] = ltfatCreateMatrix(Ls, W,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); // POINTER TO OUTPUT LTFAT_TYPE* fPtr = (LTFAT_TYPE*) mxGetData(plhs[0]); // Set to zeros memset(fPtr,0,Ls*W*sizeof(LTFAT_TYPE)); // POINTER TO THE FILTERS LTFAT_TYPE** gPtrs = (LTFAT_TYPE**) mxMalloc(M*sizeof(LTFAT_TYPE*)); for(unsigned int m=0;m<M;m++) { gPtrs[m] = (LTFAT_TYPE*) mxGetData(mxGetCell(mxg, m)); } // over all channels // #pragma omp parallel for private(m) for(unsigned int m =0; m<M; m++) { for(unsigned int w =0; w<W; w++) { // Obtain pointer to w-th column in input LTFAT_TYPE *fPtrCol = fPtr + w*Ls; // Obtaing pointer to w-th column in m-th element of output cell-array LTFAT_TYPE *cPtrCol = cPtrs[m] + w*Lc[m]; //(upconv_td)(const LTFAT_TYPE *in, int inLen, LTFAT_TYPE *out, const int outLen, const LTFAT_TYPE *filts, int fLen, int up, int skip, enum ltfatWavExtType ext) LTFAT_NAME(upconv_td)(cPtrCol,Lc[m],fPtrCol,Ls,gPtrs[m],filtLen[m],a[m],-offset[m],ltfatExtStringToEnum(ext)); } } }