📄 slotextraction.c
字号:
/* ============================================================================
Property of Freescale
Freescale Confidential Proprietary
Freescale Copyright (C) 2006 All rights reserved
----------------------------------------------------------------------------
$RCSfile: SlotExtraction.c.rca $
Tag $Name: $
$Revision: 1.2 $
$Date: Mon Oct 30 13:38:11 2006 $
Target Processor: Matlab
============================================================================ */
#include <stdlib.h>
#include <math.h>
#include "mex.h"
#include "SBX_FPULSPK_SlotExtraction.c"
#undef _ENTERPRISE_C_
#include "prototype.c"
// Input Arguments (not all might be used)
#define X1_IN prhs[0]
#define X2_IN prhs[1]
#define X3_IN prhs[2]
#define X4_IN prhs[3]
#define X5_IN prhs[4]
// Output Arguments (not all might be used)
#define Y1_OUT plhs[0]
#define Y2_OUT plhs[1]
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
/* Matlab input interface (not all might be used) */
short int *X3;
unsigned short int *X4;
signed char *X5;
unsigned short int X6;
unsigned char X7;
//Matlab output interface (not all might be used)
short int *Y1,*Y2;
/* Matlab input dimensions (not all might be used) */
unsigned long mx1,nx1;
unsigned long mx2,nx2;
unsigned long mx3,nx3;
unsigned long mx4,nx4;
unsigned long mx5,nx5;
/* Matlab output dimensions (not all might be used) */
unsigned long my1,ny1;
unsigned long my2,ny2;
// Others
int i,j;
signed long int status;
double *temp1,*temp2,*temp3,*temp4,*temp5,*temp6,*temp7;
double *temp8,*temp9,*temp10,*temp11,*temp12;
/* Check for proper number of arguments */
if (nlhs != 2)
{
mexErrMsgTxt("Error: 2 output arguments required.");
}
if (nrhs != 5)
{
mexErrMsgTxt("Error: 5 input arguments required.");
}
/* Check the input format */
if ( (!mxIsDouble(X1_IN) || mxIsComplex(X1_IN)))
{
mexErrMsgTxt("Error: Input 1 data must be real of class 'double'.");
}
if ( (!mxIsDouble(X2_IN) || mxIsComplex(X2_IN)))
{
mexErrMsgTxt("Error: Input 2 data must be real of class 'double'.");
}
if ( (!mxIsDouble(X3_IN) || !mxIsComplex(X3_IN)))
{
mexErrMsgTxt("Error: Input 3 data must be complex of class 'double'.");
}
if ( (!mxIsDouble(X4_IN) || mxIsComplex(X4_IN)))
{
mexErrMsgTxt("Error: Input 4 data must be real of class 'double'.");
}
if ( (!mxIsDouble(X5_IN) || mxIsComplex(X5_IN)))
{
mexErrMsgTxt("Error: Input 5 data must be real of class 'double'.");
}
/* get input dimensions (not all might be used) */
mx1=mxGetM(X1_IN); nx1=mxGetN(X1_IN);
mx2=mxGetM(X2_IN); nx2=mxGetN(X2_IN);
mx3=mxGetM(X3_IN); nx3=mxGetN(X3_IN);
mx4=mxGetM(X4_IN); nx4=mxGetN(X4_IN);
mx5=mxGetM(X5_IN); nx5=mxGetN(X5_IN);
/* collect data : X3*/
X3 = mxMalloc(sizeof(short int*)*mx3*nx3*2);
temp1 = (double *)mxGetPr(X3_IN);
temp2 = (double *)mxGetPi(X3_IN);
temp11 = mxMalloc(sizeof(double)*mx3*nx3);
temp12 = mxMalloc(sizeof(double)*mx3*nx3);
// temp11 and temp12 are temp1 and temp2 upside down
for(i=0;i<mx3;i++)
{
for(j=0;j<nx3;j++)
{
//t = (double) temp1[3*j+i];
//mexPrintf("t %d",(int)t);
temp11[j+i*nx3] = temp1[mx3*j+i];
//temp11[j+i*nx3] = t;
temp12[j+i*nx3] = temp2[mx3*j+i];
}
}
for(i=0;i<mx3*nx3;i++)
{
/*X3[2*i] = (short int) (temp1[i]) ;
X3[2*i+1] = (short int) (temp2[i]) ;*/ //
X3[2*i] = (short int) (temp11[i]) ;
X3[2*i+1] = (short int) (temp12[i]) ; // need to consider input as a col vector.
}
/* collect data : X4*/
temp3 = (double *)mxGetPr(X4_IN);
X4 = mxMalloc(sizeof(unsigned short int*)*mx4*nx4);
for(i=0;i<mx4*nx4;i++)
{
X4[i] = (unsigned short int) (temp3[i]) ; // X4 is validated
}
/* collect data : X5*/
temp4 = (double *)mxGetPr(X5_IN);
X5 = mxMalloc(sizeof(unsigned short int*)*mx5*nx5);
for(i=0;i<mx5*nx5;i++)
{
X5[i] = (unsigned short int) (temp4[i]) ; // X5 is validated
}
/* collect data : X6*/
temp5 = (double *)mxGetPr(X1_IN);
X6 = (unsigned short int) (temp5[0]); // X6 validated
/* collect data : X7*/
temp6 = (double *)mxGetPr(X2_IN);
X7 = (unsigned short int) (temp6[0]); // X7 validated
// define output dimensions
my1=1;ny1=48; //still in debug version ; maybe changes to be done here.
my2=2;ny2=12;
// allocation for outputs
Y1 = mxMalloc(sizeof(short int*)*my1*ny1);
Y2 = mxMalloc(sizeof(short int*)*my2*ny2);
// function call
status = SBX_FPULSPK_SlotExtraction(Y1,Y2,X3,X4,X5,X6,X7);
// outputs collection
Y1_OUT = mxCreateNumericMatrix(my1, ny1, mxDOUBLE_CLASS, mxCOMPLEX);
temp7 = (double*)mxGetPr(Y1_OUT); temp8 = (double*)mxGetPi(Y1_OUT);
for(i=0;i<my1*ny1;i++)
{
temp7[i] = (double) Y1[i*2];
temp8[i] = (double) Y1[i*2+1];
}
Y2_OUT = mxCreateNumericMatrix(my2, ny2, mxDOUBLE_CLASS, mxCOMPLEX);
temp9 = (double*)mxGetPr(Y2_OUT); temp10 = (double*)mxGetPi(Y2_OUT);
for(i=0;i<ny2;i++)
{
temp9[2*i] = (double) Y2[i*2];
temp9[2*i+1] = (double) Y2[i*2 + ny2*2];
temp10[2*i] = (double) Y2[i*2+1];;
temp10[2*i+1] = (double) Y2[i*2 + ny2*2 +1 ];
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -