-
Notifications
You must be signed in to change notification settings - Fork 6
/
pam_llr_mex.c
68 lines (58 loc) · 1.92 KB
/
pam_llr_mex.c
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
/*
* pam_llr_mex.c - Compute LLRs for PAM
*
* Usage: pam_llr_mex(C, sigma2, y, Pk)
* C := Real constellation in Gray-mapping order
* sigma2:= Noise variance per each constellation point
* y := Received complex symbols
* Pk := Probability of each constellation symbol
*
* Use this function to compute log-likelihood-ratios
* for M-PAM constellations assuming an AWGN channel.
*
* Compile with: mex -lm -R2018a pam_llr_mex.c
* (requires MATLAB R2018a or newer versions)
* Works under 64-bit Linux. Don't know/care under other OSs.
*
* Copyright (c) 2018 Dario Pilori, Politecnico di Torino <[email protected]>
* SPDX-License-Identifier: MIT
*/
#include <math.h>
#include <complex.h>
#include <omp.h>
#include "capacity_functions.h"
#include "mex.h"
/* Gateway function */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
size_t M, Ns; /* constellation and data size */
double *C, *y; /* Data and constellation */
double *l, *Pk, *s2;
/* Verify input */
if(nrhs != 4) {
mexErrMsgIdAndTxt("DspLibrary:pam_gmi_mex:nrhs",
"Four inputs required.");
}
/* Verify output */
if(nlhs > 1) {
mexErrMsgIdAndTxt("DspLibrary:pam_gmi_mex:nlhs",
"Max one output.");
}
/* Get sizes */
M = mxGetM(prhs[0]);
Ns = mxGetM(prhs[2]);
/* Get noise variance */
s2 = mxGetDoubles(prhs[1]);
/* Get constellation and received data */
C = mxGetDoubles(prhs[0]);
y = mxGetDoubles(prhs[2]);
/* Get probabilities */
Pk = mxGetDoubles(prhs[3]);
/* Allocate the output matrix */
plhs[0] = mxCreateDoubleMatrix((mwSize) (Ns*log2(M)),1,mxREAL);
/* get a pointer to the output matrix */
l = mxGetDoubles(plhs[0]);
/* Call function */
pam_soft_decode(y, Ns, C, Pk, M, s2, l);
}