File: maxstar.h

package info (click to toggle)
codec2 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,376 kB
  • sloc: ansic: 436,819; cpp: 2,091; objc: 1,736; sh: 1,510; python: 1,405; asm: 683; makefile: 605
file content (219 lines) | stat: -rw-r--r-- 6,165 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* File maxstar.h

   Description: Performs the max* operations (Jacobian logarithm) defined as:
		max*( x, y ) = max( x,y) + log( 1 + exp( - |x-y| ) )

   There are several versions of this function, max_starX, where "X":
      X = 0 For linear approximation to log-MAP
        = 1 For max-log-MAP algorithm (i.e. max*(x,y) = max(x,y) )
        = 2 For Constant-log-MAP algorithm
	    = 3 For log-MAP, correction factor from small nonuniform table and interpolation
        = 4 For log-MAP, correction factor uses C function calls

   Calling syntax:
      output = max_starX( delta1, delta2 )

   Where:
  	  output =	The result of max*(x,y)

   	  delta1 = T] he first argument (i.e. x) of max*(x,y)
	  delta2 = The second argument (i.e. y) of max*(x,y)

   Copyright (C) 2005, Matthew C. Valenti

   Functions max_star0, max_star1, max_star2, max_star3, and max_star4
   are part of the Iterative Solutions Coded Modulation Library
   The Iterative Solutions Coded Modulation Library is free software;
   you can redistribute it and/or modify it under the terms of 
   the GNU Lesser General Public License as published by the 
   Free Software Foundation; either version 2.1 of the License, 
   or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
  
   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

/* values for the jacobian logarithm table (DecoderType=4) */
#define BOUNDARY0    0
#define BOUNDARY1    0.4200
#define BOUNDARY2    0.8500
#define BOUNDARY3    1.3100
#define BOUNDARY4    1.8300
#define BOUNDARY5    2.4100
#define BOUNDARY6    3.1300
#define BOUNDARY7    4.0800
#define BOUNDARY8    5.6000

#define SLOPE0  -0.44788139700522
#define SLOPE1  -0.34691145436176
#define SLOPE2  -0.25432579542705
#define SLOPE3  -0.17326680196715
#define SLOPE4  -0.10822110027877
#define SLOPE5  -0.06002650498009
#define SLOPE6  -0.02739265095522
#define SLOPE7  -0.00860202759280

#define VALUE0   0.68954718055995
#define VALUE1   0.50153699381775
#define VALUE2   0.35256506844219
#define VALUE3   0.23567520254575
#define VALUE4   0.14607646552283
#define VALUE5   0.08360822736113
#define VALUE6   0.04088914377547
#define VALUE7   0.01516612536801

/* values for the constant log-MAP algorithm (DecoderType=3) */
#define CVALUE   0.5
#define TVALUE   1.5

/* values for the linear approximation (DecoderType=1) */
#define TTHRESH  2.508
#define AVALUE  -0.236
#define BVALUE   0.592

/* Values for linear approximation (DecoderType=5) */
#define AJIAN -0.24904163195436
#define TJIAN 2.50681740420944

/* The linear-log-MAP algorithm */
static float max_star0(
					  float delta1, 
					  float delta2 )
{
	float diff;
	
	diff = delta2 - delta1;

	if ( diff > TJIAN )
		return( delta2 );
	else if ( diff < -TJIAN )
		return( delta1 );
	else if ( diff > 0 )
		return( delta2 + AJIAN*(diff-TJIAN) );
	else
		return( delta1 - AJIAN*(diff+TJIAN) );
}


/* The max-log-MAP algorithm */
static float max_star1(
					  float delta1, 
					  float delta2 )
{
	/* Return the maximum of delta1 and delta2 */
	if (delta1 > delta2)		
		return(delta1);
	else			
		return(delta2);
}


/* The constant-log-MAP algorithm */
static float max_star2(
					  float delta1, 
					  float delta2 )
{
/* Return maximum of delta1 and delta2
   and in correction value if |delta1-delta2| < TVALUE */
	float diff;	
	diff = delta2 - delta1;

	if ( diff > TVALUE )
		return( delta2 );
	else if ( diff < -TVALUE )
		return( delta1 );
	else if ( diff > 0 )
		return( delta2 + CVALUE );
	else
		return( delta1 + CVALUE );

}

/* Accurate approximation of the log-MAP algorithm using an optimized
   8 element nonuniform table with linear interpolation */
static float max_star3(
					  float delta1, 
					  float delta2 )
{
	float diff;
	diff = (float) fabs( delta2 - delta1 );
	
	if (delta1 > delta2) {
		if (diff > BOUNDARY8 )
			return( delta1 );
		else if ( diff > BOUNDARY4 ) {
			if (diff > BOUNDARY6 ) {
				if ( diff > BOUNDARY7 )
					return( delta1 + VALUE7 + SLOPE7*(diff-BOUNDARY7) );
				else
					return( delta1 + VALUE6 + SLOPE6*(diff-BOUNDARY6) );
			} else {
				if ( diff > BOUNDARY5 )
					return( delta1 + VALUE5 + SLOPE5*(diff-BOUNDARY5) );
				else
					return( delta1 + VALUE4 + SLOPE4*(diff-BOUNDARY4) );
			}	
		} else {
			if (diff > BOUNDARY2 ) {
				if ( diff > BOUNDARY3 )
					return( delta1 + VALUE3 + SLOPE3*(diff-BOUNDARY3) );
				else
					return( delta1 + VALUE2 + SLOPE2*(diff-BOUNDARY2) );
			} else {
				if ( diff > BOUNDARY1 )
					return( delta1 + VALUE1 + SLOPE1*(diff-BOUNDARY1) );
				else
					return( delta1 + VALUE0 + SLOPE0*(diff-BOUNDARY0) );
			}
		}
	} else {
		if (diff > BOUNDARY8 )
			return( delta2 );
		else if ( diff > BOUNDARY4 ) {
			if (diff > BOUNDARY6 ) {
				if ( diff > BOUNDARY7 )
					return( delta2 + VALUE7 + SLOPE7*(diff-BOUNDARY7) );
				else
					return( delta2 + VALUE6 + SLOPE6*(diff-BOUNDARY6) );
			} else {
				if ( diff > BOUNDARY5 )
					return( delta2 + VALUE5 + SLOPE5*(diff-BOUNDARY5) );
				else
					return( delta2 + VALUE4 + SLOPE4*(diff-BOUNDARY4) );
			}	
		} else {
			if (diff > BOUNDARY2 ) {
				if ( diff > BOUNDARY3 )
					return( delta2 + VALUE3 + SLOPE3*(diff-BOUNDARY3) );
				else
					return( delta2 + VALUE2 + SLOPE2*(diff-BOUNDARY2) );
			} else {
				if ( diff > BOUNDARY1 )
					return( delta2 + VALUE1 + SLOPE1*(diff-BOUNDARY1) );
				else
					return( delta2 + VALUE0 + SLOPE0*(diff-BOUNDARY0) );
			}
		}
	}
}

/* Exact calculation of the log-MAP algorithm */
static float max_star4(
					  float delta1, 
					  float delta2 )
{
	/* Use C-function calls to compute the correction function */	
	if (delta1 > delta2) {
		return( (float) (delta1 + log( 1 + exp( delta2-delta1) ) ) );		
	} else	{
		return( (float) (delta2 + log( 1 + exp( delta1-delta2) ) ) );		
	}
}