Diff of /mex/comp_filterbank.c [164e09] .. [a5c381]  Maximize  Restore

Switch to unified view

a/mex/comp_filterbank.c b/mex/comp_filterbank.c
1
#include "mex.h"
1
#include "mex.h"
2
#include "fftw3.h"
2
3
3
void comp_filterbank_td(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
4
void comp_filterbank_td(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
4
void comp_filterbank_fft(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
5
void comp_filterbank_fft(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
5
void comp_filterbank_fftbl(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
6
void comp_filterbank_fftbl(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
6
7
...
...
8
//  comp_filterbank(f,g,a);
9
//  comp_filterbank(f,g,a);
9
10
10
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
11
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
11
{
12
{
12
   const mxArray* mxf = prhs[0];
13
   const mxArray* mxf = prhs[0];
14
   mxArray* mxF = NULL;
13
   const mxArray* mxg = prhs[1];
15
   const mxArray* mxg = prhs[1];
14
   const mxArray* mxa = prhs[2];
16
   const mxArray* mxa = prhs[2];
15
17
16
   // input data length
18
   // input data length
17
   const mwSize L = mxGetM(mxf);
19
   const mwSize L = mxGetM(mxf);
...
...
62
          continue;
64
          continue;
63
      }
65
      }
64
66
65
      if(mxGetField(gEl,0,"H")!=NULL)
67
      if(mxGetField(gEl,0,"H")!=NULL)
66
      {
68
      {
67
          if(acols==1&&L==mxGetNumberOfElement(mxGetField(gEl,0,"H")))
69
          if(acols==1&&L==mxGetNumberOfElements(mxGetField(gEl,0,"H")))
68
          {
70
          {
69
             fftArgsIdx[fftCount++] = m;
71
             fftArgsIdx[fftCount++] = m;
70
             continue;
72
             continue;
71
          }
73
          }
72
          else
74
          else
...
...
123
          mxSetCell((mxArray*)prhs_td[1],m,NULL);
125
          mxSetCell((mxArray*)prhs_td[1],m,NULL);
124
      }
126
      }
125
    }
127
    }
126
128
127
129
130
    if(fftCount>0 || fftblCount>0)
131
    {
132
        // Need to do FFT of mxf
133
        mwIndex ndim = mxGetNumberOfDimensions(mxf);
134
        const mwSize* dims = mxGetDimensions(mxf);
135
        mxClassID classid = mxDOUBLE_CLASS;
136
        if(mxIsSingle(mxf))
137
            classid = mxSINGLE_CLASS;
138
139
        mxF = mxCreateNumericArray(ndim,dims,classid,mxCOMPLEX);
140
141
142
        fftw_iodim fftw_dims[1];
143
        fftw_iodim howmanydims[1];
144
        fftw_plan p;
145
        fftw_dims[0].n = L;
146
        fftw_dims[0].is = 1;
147
        fftw_dims[0].os = 1;
148
149
        howmanydims[0].n = W;
150
        howmanydims[0].is = L;
151
        howmanydims[0].os = L;
152
153
        if(mxIsDouble(mxf))
154
        {
155
        p = fftw_plan_guru_split_dft(
156
          1, fftw_dims,
157
          1, howmanydims,
158
          mxGetPr(mxF), mxGetPi(mxF), mxGetPr(mxF), mxGetPi(mxF),
159
          FFTW_ESTIMATE);
160
          memcpy(mxGetPr(mxF),mxGetPr(mxf),L*W*sizeof(double));
161
          if(mxIsComplex(mxf))
162
            memcpy(mxGetPi(mxF),mxGetPi(mxf),L*W*sizeof(double));
163
        }
164
        else if(mxIsSingle(mxf))
165
        {
166
          p = fftwf_plan_guru_split_dft(
167
          1, dims,
168
          1, howmanydims,
169
          (float*)mxGetPr(mxF), (float*)mxGetPi(mxF),
170
          (float*) mxGetPr(mxF), (float*)mxGetPi(mxF),
171
          FFTW_ESTIMATE);
172
          memcpy(mxGetPr(mxF),mxGetPr(mxf),L*W*sizeof(float));
173
          if(mxIsComplex(mxf))
174
            memcpy(mxGetPi(mxF),mxGetPi(mxf),L*W*sizeof(float));
175
        }
176
177
        fftw_execute(p);
178
        fftw_destroy_plan(p);
179
180
    }
181
128
    if(fftCount>0)
182
    if(fftCount>0)
129
    {
183
    {
184
        mxArray* plhs_fft[1];
185
        const mxArray* prhs_fft[3];
186
        prhs_fft[0] = mxF;
187
        prhs_fft[1] = mxCreateCellMatrix(fftCount,1);
188
        prhs_fft[2] = mxCreateDoubleMatrix(fftCount,1,mxREAL);
189
        double* aPtr = (double*)mxGetPr(prhs_fft[2]);
190
191
        for(mwIndex m=0;m<fftCount;m++)
192
        {
193
           mxArray * gEl = mxGetCell(mxg, fftArgsIdx[m]);
194
           mxSetCell((mxArray*)prhs_fft[1],m,mxGetField(gEl,0,"H"));
195
           // This has overhead
196
           //mxSetCell((mxArray*)prhs_td[1],m,mxDuplicateArray(mxGetField(gEl,0,"h")));
197
           aPtr[m] = a[fftArgsIdx[m]];
198
        }
199
200
        comp_filterbank_fft(1,plhs_fft,3, prhs_fft);
201
202
        for(mwIndex m=0;m<fftCount;m++)
203
        {
204
          mxSetCell(plhs[0],fftArgsIdx[m],mxGetCell(plhs_fft[0],m));
205
          mxSetCell(plhs_fft[0],m,NULL);
206
          mxSetCell((mxArray*)prhs_fft[1],m,NULL);
207
        }
208
209
    }
210
211
    if(fftblCount>0)
212
    {
213
        mxArray* plhs_fftbl[1];
214
        const mxArray* prhs_fftbl[5];
215
        prhs_fftbl[0] = mxF;
216
        prhs_fftbl[1] = mxCreateCellMatrix(fftblCount,1);
217
        prhs_fftbl[2] = mxCreateDoubleMatrix(fftblCount,1,mxREAL);
218
        prhs_fftbl[3] = mxCreateDoubleMatrix(fftblCount,2,mxREAL);
219
        prhs_fftbl[4] = mxCreateDoubleMatrix(fftblCount,1,mxREAL);
220
        double* foffPtr = (double*)mxGetPr(prhs_fftbl[2]);
221
        double* aPtr = (double*)mxGetPr(prhs_fftbl[3]);
222
        double* realonlyPtr = (double*)mxGetPr(prhs_fftbl[3]);
223
224
        for(mwIndex m=0;m<fftCount;m++)
225
        {
226
           mxArray * gEl = mxGetCell(mxg, fftblArgsIdx[m]);
227
           mxSetCell((mxArray*)prhs_fftbl[1],m,mxGetField(gEl,0,"H"));
228
           foffPtr[m] = mxGetScalar(mxGetField(gEl,0,"foff"));
229
           aPtr[m] = a[fftblArgsIdx[m]];
230
231
           if(acols>1)
232
              aPtr[m+fftblCount] = a[fftblArgsIdx[m]+M];
233
           else
234
              aPtr[m+fftblCount] = 1;
235
236
           realonlyPtr[m] = mxGetScalar(mxGetField(gEl,0,"realonly"));
237
        }
238
239
        comp_filterbank_fftbl(1,plhs_fftbl,5, prhs_fftbl);
240
241
        for(mwIndex m=0;m<fftblCount;m++)
242
        {
243
          mxSetCell(plhs[0],fftblArgsIdx[m],mxGetCell(plhs_fftbl[0],m));
244
          mxSetCell(plhs_fftbl[0],m,NULL);
245
          mxSetCell((mxArray*)prhs_fftbl[1],m,NULL);
246
        }
130
247
131
    }
248
    }
132
249
133
250
134
}
251
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks