00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "mex.h"
00013
00014
00015 void convec( double *xr, double *xi, mwSize nx,
00016 double *yr, double *yi, mwSize ny,
00017 double *zr, double *zi)
00018 {
00019 mwSize i,j;
00020
00021 zr[0]=0.0;
00022 zi[0]=0.0;
00023
00024 for(i=0; i<nx; i++) {
00025 for(j=0; j<ny; j++) {
00026 *(zr+i+j) = *(zr+i+j) + *(xr+i) * *(yr+j) - *(xi+i) * *(yi+j);
00027 *(zi+i+j) = *(zi+i+j) + *(xr+i) * *(yi+j) + *(xi+i) * *(yr+j);
00028 }
00029 }
00030 }
00031
00032
00033 void mexFunction( int nlhs, mxArray *plhs[],
00034 int nrhs, const mxArray *prhs[] )
00035 {
00036 double *xr, *xi, *yr, *yi, *zr, *zi;
00037 mwSize rows, cols, nx, ny;
00038
00039
00040 if(nrhs != 2)
00041 mexErrMsgTxt("Two inputs required.");
00042 if(nlhs > 1)
00043 mexErrMsgTxt("Too many output arguments.");
00044
00045 if( mxGetM(prhs[0]) != 1 || mxGetM(prhs[1]) != 1 )
00046 mexErrMsgTxt("Both inputs must be row vectors.");
00047 rows = 1;
00048
00049 if( !mxIsComplex(prhs[0]) || !mxIsComplex(prhs[1]) )
00050 mexErrMsgTxt("Inputs must be complex.\n");
00051
00052
00053 nx = mxGetN(prhs[0]);
00054 ny = mxGetN(prhs[1]);
00055
00056
00057
00058 xr = mxGetPr(prhs[0]);
00059 xi = mxGetPi(prhs[0]);
00060 yr = mxGetPr(prhs[1]);
00061 yi = mxGetPi(prhs[1]);
00062
00063
00064 cols = nx + ny - 1;
00065 plhs[0] = mxCreateDoubleMatrix(rows, cols, mxCOMPLEX);
00066 zr = mxGetPr(plhs[0]);
00067 zi = mxGetPi(plhs[0]);
00068
00069
00070 convec(xr, xi, nx, yr, yi, ny, zr, zi);
00071
00072 return;
00073 }
00074
00075
00076
00077