[77a22a]: / mex / comp_ifwt_all.c  Maximize  Restore  History

Download this file

143 lines (119 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "mex.h"
#include "config.h"
#include "ltfat.h"
#include "ltfat-mex-helper.h"
#include "wavelets.h"
/*
Calling convention:
0 1 2 3 4 5 6
f = comp_ifwt_all(c, filts, J, a, Ls, flags, ext)
*/
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double ** in; int* inLen; int inChan;
double * out; int outLen;
double ** filts; int fLen;
double *a;
int ext = 0;
int J;
int noOfFilts = 2;
J = (int) mxGetScalar(prhs[2]);
// prepare input poiner arrays
int inCellElements = mxGetNumberOfElements(prhs[0]);
inChan = mxGetN(mxGetCell(prhs[0], 0));
in = (double **) mxMalloc(inCellElements*inChan*sizeof(double *));
inLen = (int *) mxMalloc(inCellElements*sizeof(int));
for(int ii=0;ii<inCellElements;ii++)
{
inLen[ii] = mxGetM(mxGetCell(prhs[0], ii));
}
for(int ch=0;ch<inChan;ch++)
{
for(int ii=0;ii<inCellElements;ii++)
{
in[ii+ch*inCellElements] = mxGetPr(mxGetCell(prhs[0], ii)) + ch*inLen[ii];
}
}
noOfFilts = mxGetNumberOfElements(prhs[1]);
filts = (double **) mxMalloc(noOfFilts*sizeof(double *));
fLen = mxGetNumberOfElements(mxGetCell(prhs[1], 0));
for(int ii=0;ii<noOfFilts;ii++)
filts[ii] = mxGetPr(mxGetCell(prhs[1], ii));
a = mxGetPr(prhs[3]);
int aLen = mxGetNumberOfElements(prhs[3]);
// reading ext string
int extStrLen = mxGetN(prhs[6]);
char* extStr = (char*) mxMalloc(extStrLen);
mxGetString(prhs[6],extStr,extStrLen+1);
// reading flags string
int flagsStrLen = mxGetN(prhs[5]);
char* flagsStr = (char*) mxMalloc(flagsStrLen);
mxGetString(prhs[5],flagsStr,flagsStrLen+1);
// desired output signal length
outLen = mxGetScalar(prhs[4]);
plhs[0] = mxCreateDoubleMatrix(outLen, inChan, mxREAL);
out = mxGetPr(plhs[0]);
bool doNonexp = false;
if(!strcmp(extStr,"zpd"))
ext = 0;
else if(!strcmp(extStr,"sym"))
ext = 1;
else if(!strcmp(extStr,"symw"))
ext = 2;
else if(!strcmp(extStr,"asym"))
ext = 3;
else if(!strcmp(extStr,"asymw"))
ext = 4;
else if(!strcmp(extStr,"ppd"))
ext = 5;
else if(!strcmp(extStr,"sp0"))
ext = 6;
else
doNonexp = true;
/* "per" for nonexpansive */
/* if(!isPow2((int)a[0]))
{
mexErrMsgTxt("Upsampling factors not equal to power of two not supported yet.");
}
*/
int up = a[0];
if(!strcmp(flagsStr,"dec"))
{
if(doNonexp)
{
for(int ch=0;ch<inChan;ch++)
{
dyadic_idwt_per(&in[ch*inCellElements], inLen, out+ch*outLen, outLen, filts, fLen, noOfFilts, up,J);
}
}
else
{
for(int ch=0;ch<inChan;ch++)
{
dyadic_idwt_exp(&in[ch*inCellElements], inLen, out+ch*outLen, outLen, filts, fLen, noOfFilts, up, J);
}
}
}
else if(!strcmp(flagsStr,"undec"))
{
if(doNonexp)
{
for(int ch=0;ch<inChan;ch++)
{
undec_idwt_per(&in[ch*inCellElements], inLen[0], out+ch*outLen, outLen, filts, fLen, noOfFilts, up, J);
}
}
else
{
for(int ch=0;ch<inChan;ch++)
{
undec_idwt_exp(&in[ch*inCellElements], inLen, out+ch*outLen, outLen, filts, fLen, noOfFilts, up, J);
}
}
}
mxFree(filts);
mxFree(in);
mxFree(extStr);
mxFree(flagsStr);
}