issues in creating a mex file that uses as c++ object that works on complex data type…
Hi,
I am trying to create a mex file that uses a c++ object called my_chain. The c++ function process() uses inputs that are of complex<int32_t> data type.
So, I used mxComplexInt32 to declare my arrays. Though the mex file gets compiled, Matlab crashes when I try to run the mex routine.
Any help in this regard is appreciated.
Regards
surendra
PS: Please find attached my mex file..
#include <iostream>
#include <complex>
#include "stdlib.h"
#include "mex.h"
#include "my_chain.h"
using namespace std;
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray* prhs[])
{
complex<int> *input_data, *output_data;
int num_input_samples=0, num_output_samples=0, num_rows_out;
int bw_MHz; // Operating bandwidth
double f_rf_MHz; // RF frequency
double rs_ratio;
// Check for proper number of arguments
if (nrhs != 4) {
mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin", "mexfn_rx_ds_chain requires four input arguments.");
}
if (nlhs != 1) {
mexErrMsgIdAndTxt("MATLAB:mexcpp:nargout", "mexfn_rx_ds_chain requires two outputs argument.");
}
f_rf_MHz = mxGetScalar(prhs[0]);
bw_MHz = mxGetScalar(prhs[1]);
input_data = (complex<int> *)mxGetComplexInt32s(prhs[2]);
num_input_samples = mxGetScalar(prhs[3]);
rs_ratio = f_rf_MHz/bw_MHz;
num_rows_out = (int)((double)num_input_samples/(32.0 * rs_ratio)) + 2;
plhs[0] = mxCreateNumericMatrix(num_rows_out,1,mxINT32_CLASS, mxCOMPLEX);
output_data = (complex<int> *)mxGetComplexInt32s(plhs[0]);
// instantiate object
my_chain object1(f_rf_MHz,bw_MHz);
mexPrintf("f_rf_MHz is %fn",f_rf_MHz);
mexPrintf("num_input_samples is %dn",num_input_samples);
//Matlab crashes if I the below lines are executed.
for(int ii=0; ii<20; ii++)
{
mexPrintf("%d %dn",input_data[ii].real(), input_data[ii].imag());
}
num_output_samples = object1.process(input_data, num_input_samples, output_data);
return;
}Hi,
I am trying to create a mex file that uses a c++ object called my_chain. The c++ function process() uses inputs that are of complex<int32_t> data type.
So, I used mxComplexInt32 to declare my arrays. Though the mex file gets compiled, Matlab crashes when I try to run the mex routine.
Any help in this regard is appreciated.
Regards
surendra
PS: Please find attached my mex file..
#include <iostream>
#include <complex>
#include "stdlib.h"
#include "mex.h"
#include "my_chain.h"
using namespace std;
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray* prhs[])
{
complex<int> *input_data, *output_data;
int num_input_samples=0, num_output_samples=0, num_rows_out;
int bw_MHz; // Operating bandwidth
double f_rf_MHz; // RF frequency
double rs_ratio;
// Check for proper number of arguments
if (nrhs != 4) {
mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin", "mexfn_rx_ds_chain requires four input arguments.");
}
if (nlhs != 1) {
mexErrMsgIdAndTxt("MATLAB:mexcpp:nargout", "mexfn_rx_ds_chain requires two outputs argument.");
}
f_rf_MHz = mxGetScalar(prhs[0]);
bw_MHz = mxGetScalar(prhs[1]);
input_data = (complex<int> *)mxGetComplexInt32s(prhs[2]);
num_input_samples = mxGetScalar(prhs[3]);
rs_ratio = f_rf_MHz/bw_MHz;
num_rows_out = (int)((double)num_input_samples/(32.0 * rs_ratio)) + 2;
plhs[0] = mxCreateNumericMatrix(num_rows_out,1,mxINT32_CLASS, mxCOMPLEX);
output_data = (complex<int> *)mxGetComplexInt32s(plhs[0]);
// instantiate object
my_chain object1(f_rf_MHz,bw_MHz);
mexPrintf("f_rf_MHz is %fn",f_rf_MHz);
mexPrintf("num_input_samples is %dn",num_input_samples);
//Matlab crashes if I the below lines are executed.
for(int ii=0; ii<20; ii++)
{
mexPrintf("%d %dn",input_data[ii].real(), input_data[ii].imag());
}
num_output_samples = object1.process(input_data, num_input_samples, output_data);
return;
} Hi,
I am trying to create a mex file that uses a c++ object called my_chain. The c++ function process() uses inputs that are of complex<int32_t> data type.
So, I used mxComplexInt32 to declare my arrays. Though the mex file gets compiled, Matlab crashes when I try to run the mex routine.
Any help in this regard is appreciated.
Regards
surendra
PS: Please find attached my mex file..
#include <iostream>
#include <complex>
#include "stdlib.h"
#include "mex.h"
#include "my_chain.h"
using namespace std;
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray* prhs[])
{
complex<int> *input_data, *output_data;
int num_input_samples=0, num_output_samples=0, num_rows_out;
int bw_MHz; // Operating bandwidth
double f_rf_MHz; // RF frequency
double rs_ratio;
// Check for proper number of arguments
if (nrhs != 4) {
mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin", "mexfn_rx_ds_chain requires four input arguments.");
}
if (nlhs != 1) {
mexErrMsgIdAndTxt("MATLAB:mexcpp:nargout", "mexfn_rx_ds_chain requires two outputs argument.");
}
f_rf_MHz = mxGetScalar(prhs[0]);
bw_MHz = mxGetScalar(prhs[1]);
input_data = (complex<int> *)mxGetComplexInt32s(prhs[2]);
num_input_samples = mxGetScalar(prhs[3]);
rs_ratio = f_rf_MHz/bw_MHz;
num_rows_out = (int)((double)num_input_samples/(32.0 * rs_ratio)) + 2;
plhs[0] = mxCreateNumericMatrix(num_rows_out,1,mxINT32_CLASS, mxCOMPLEX);
output_data = (complex<int> *)mxGetComplexInt32s(plhs[0]);
// instantiate object
my_chain object1(f_rf_MHz,bw_MHz);
mexPrintf("f_rf_MHz is %fn",f_rf_MHz);
mexPrintf("num_input_samples is %dn",num_input_samples);
//Matlab crashes if I the below lines are executed.
for(int ii=0; ii<20; ii++)
{
mexPrintf("%d %dn",input_data[ii].real(), input_data[ii].imag());
}
num_output_samples = object1.process(input_data, num_input_samples, output_data);
return;
} complex data types in mex files MATLAB Answers — New Questions