-
Notifications
You must be signed in to change notification settings - Fork 4
/
amplitude_1d.cpp
67 lines (55 loc) · 1.87 KB
/
amplitude_1d.cpp
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
// Software: Discrete Fourier Transform 1D (for real and complex signals)
// Author: Hy Truong Son
// Position: PhD Student
// Institution: Department of Computer Science, The University of Chicago
// Email: [email protected], [email protected]
// Website: http://people.inf.elte.hu/hytruongson/
// Copyright 2016 (c) Hy Truong Son. All rights reserved.
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <iterator>
#include <algorithm>
#include <ctime>
#include "mex.h"
using namespace std;
int N;
double *Re;
double *Im;
double *Amplitude;
void mexFunction(int nOutputs, mxArray *output_pointers[], int nInputs, const mxArray *input_pointers[]) {
if (nInputs != 2) {
std::cerr << "Exactly 2 input parameters!" << std::endl;
return;
}
if (nOutputs != 1) {
std::cerr << "Exactly 1 output parameters!" << std::endl;
return;
}
if ((mxGetM(input_pointers[0]) > (size_t)(1)) && (mxGetN(input_pointers[0]) > (size_t)(1))) {
std::cerr << "Parameter as vector only!" << std::endl;
return;
}
if ((mxGetM(input_pointers[0]) != mxGetM(input_pointers[1])) || (mxGetN(input_pointers[0]) != mxGetN(input_pointers[1]))) {
std::cerr << "The size of the real part and the imaginary part must be the same!" << std::endl;
return;
}
if (mxGetM(input_pointers[0]) > (size_t)(1)) {
N = mxGetM(input_pointers[0]);
} else {
N = mxGetN(input_pointers[1]);
}
Re = mxGetPr(input_pointers[0]);
Im = mxGetPr(input_pointers[1]);
output_pointers[0] = mxCreateDoubleMatrix(N, 1, mxREAL);
Amplitude = mxGetPr(output_pointers[0]);
for (int f = 0; f < N; ++f) {
Amplitude[f] = sqrt(Re[f] * Re[f] + Im[f] * Im[f]);
}
}