-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmorlet_interface_mex.cpp
More file actions
77 lines (67 loc) · 2.62 KB
/
morlet_interface_mex.cpp
File metadata and controls
77 lines (67 loc) · 2.62 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
#include "mex.h"
#include "matrix.h"
#include "class_handle.hpp"
#include "morlet.h"
#include <cstdlib>
//#include <cstdio>
#include <cstring>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// Get the command string
char cmd[64];
if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
mexErrMsgTxt("First input should be a command string less than 64 characters long.");
// New
if (!strcmp("new", cmd)) {
// Check parameters
if (nlhs != 1)
mexErrMsgTxt("New: One output expected.");
// Return a handle to a new C++ instance
plhs[0] = convertPtr2Mat<MorletWaveletTransform>(new MorletWaveletTransform);
return;
}
// Check there is a second input, which should be the class instance handle
if (nrhs < 2)
mexErrMsgTxt("Second input should be a class instance handle.");
// Delete
if (!strcmp("delete", cmd)) {
// Destroy the C++ object
destroyObject<MorletWaveletTransform>(prhs[1]);
// Warn if other commands were ignored
if (nlhs != 0 || nrhs != 2)
mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
return;
}
// Get the class instance pointer from the second input
MorletWaveletTransform *wavelet_transformer = convertMat2Ptr<MorletWaveletTransform>(prhs[1]);
// Call the various class methods
// init
if (!strcmp("init", cmd)) {
// Check parameters
if (nlhs < 0 || nrhs < 8)
mexErrMsgTxt("init: Unexpected arguments.");
// Call the method
size_t width = size_t(mxGetScalar(prhs[2]));
double min_freq = mxGetScalar(prhs[3]);
double max_freq = mxGetScalar(prhs[4]);
size_t n_freqs = size_t(mxGetScalar(prhs[5]));
double samplerate = mxGetScalar(prhs[6]);
size_t winsize = size_t(mxGetScalar(prhs[7]));
//printf("width=%ld, min_freq=%lg, max_freq=%lg, n_freqs=%ld, samplerate=%lg, winsize=%ld\n", width, min_freq, max_freq, n_freqs, samplerate, winsize);
wavelet_transformer->init(width, min_freq, max_freq, n_freqs, samplerate, winsize);
return;
}
// multiphasevec
if (!strcmp("multiphasevec", cmd)) {
// Check parameters
if (nlhs < 0 || nrhs < 4)
mexErrMsgTxt("multiphasevec: Unexpected arguments.");
// Call the method
double* signal = mxGetPr(prhs[2]);
double* powers = mxGetPr(prhs[3]);
wavelet_transformer->multiphasevec_powers(signal, powers);
return;
}
// Got here, so command not recognized
mexErrMsgTxt("Command not recognized.");
}