spandsp 3.0.0
meteor-engine.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * meteor-engine.h - The meteor FIR design algorithm
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2013 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2, as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#if !defined(_METEOR_ENGINE_H_)
27#define _METEOR_ENGINE_H_
28
29#define num_specs_MAX 20 /* Max. no. of specifications */
30#define MAX_COEFFS 64 /* Max. no. of coefficients */
31#define MAX_TAPS 129 /* Max. size of n, where there are n+1 grid-points */
32#define NCOL_MAX 6000 /* Max. no. of columns allowed in tableau */
33
34enum meteor_result_e
35{
36 badly_formed_requirements = -1,
37 optimum_obtained = -2,
38 too_many_columns = -3,
39 too_many_pivots = -4,
40 unbounded_dual = -5,
41 infeasible_dual = -6,
42 infeasible_primal = -7,
43 no_feasible_solution_found = -8,
44 no_feasible_band_edge_found = -9
45};
46
47enum symmetry_types_e
48{
49 symmetry_cosine,
50 symmetry_sine
51};
52
53enum constraint_types_e
54{
55 constraint_type_convexity,
56 constraint_type_limit
57};
58
59enum sense_e
60{
61 sense_lower,
62 sense_upper,
63 sense_envelope,
64 sense_concave,
65 sense_convex
66};
67
68enum interpolation_e
69{
70 interpolation_arithmetic,
71 interpolation_geometric
72};
73
74#if defined(__cplusplus)
75extern "C"
76{
77#endif
78
80{
81 const char *name; /* A name to use to refer to this definition */
82 enum constraint_types_e type; /* Type of band */
83 double left_freq; /* Band edges as read in */
84 double right_freq;
85 double left_bound;
86 double right_bound;
87 enum sense_e sense; /* Sense of constraint. */
88 enum interpolation_e interpolation; /* Interpolation method */
89 int first_col; /* Leftmost column of spec */
90 int last_col; /* Rightmost column of spec */
91 bool hug; /* Allow this constraint to be hugged? */
92 int band_pushed; /* Band edges pushed */
93};
94
96{
97 const char *filter_name;
98 double sample_rate;
99 enum symmetry_types_e symmetry_type; /* Cosine or sine symmetry */
100 int grid_points; /* There are n+1 grid-points from 0 to pi */
101 int shortest; /* Range of L = 2*m-1, 2*m, or 2*m+1 */
102 int longest; /* Range of L = 2*m-1, 2*m, or 2*m+1 */
103 int num_specs; /* No. of bands */
104 struct meteor_constraint_s spec[num_specs_MAX];
105};
106
108{
109 struct meteor_spec_s *spec;
110 bool unbounded;
111 bool optimal; /* Flags for simplex */
112 int iteration; /* Iteration count, index */
113 int num_pivots; /* Pivot count */
114 int pivot_col; /* Pivot column */
115 int pivot_row; /* Pivot row */
116 double pivot_element; /* Pivot element */
117 double cbar; /* Price when searching for entering column */
118 enum meteor_result_e result; /* Result of simplex */
119 int m; /* No. of coefficients, left and right half m */
120 int length; /* Filter length = 2*m-1, 2*m, 2*m+1 */
121
122 int phase; /* Phase */
123
124 double coeff[MAX_COEFFS]; /* Coefficients */
125
126 double price[MAX_COEFFS + 1]; /* Shadow prices = row -1 of carry = -dual variables = -coefficients */
127 int basis[MAX_COEFFS + 1]; /* Basis columns, negative integers artificial */
128
129 double carry[MAX_COEFFS + 2][MAX_COEFFS + 2]; /* Inverse-basis matrix of the revised simplex method */
130
131 double tab[MAX_COEFFS + 1][NCOL_MAX]; /* Tableau */
132 double cur_col[MAX_COEFFS + 2]; /* Current column */
133 double cur_cost; /* Current cost */
134
135 double freq[NCOL_MAX]; /* Frequencies at grid points */
136 double d[NCOL_MAX]; /* Current cost vector */
137 double c[NCOL_MAX]; /* Cost in original problem */
138
139 bool found_feasible_solution; /* Found feasible solution */
140 int smallest_m; /* Range of m */
141 int largest_m; /* Range of m */
142 int best_m; /* Best order */
143 int num_cols; /* Number of columns */
144 enum
145 {
146 find_len,
147 max_dist,
148 push_edge
149 } what_to_do; /* Type of optimization */
150 int num_pushed; /* Number of band edges pushed */
151 enum
152 {
153 rr,
154 ll
155 } which_way; /* Push which way? */
156 double low_limit; /* Lower limit for finding if primal is feasible */
157 bool odd_length; /* Odd-length filters? */
158 FILE *log_fd;
159};
160
161void output_filter_performance_as_csv_file(struct meteor_working_data_s *s, const char *file_name);
162
163int meteor_design_filter(struct meteor_working_data_s *s, struct meteor_spec_s *t, double coeffs[]);
164
165#if defined(__cplusplus)
166}
167#endif
168
169#endif
170/*- End of file ------------------------------------------------------------*/
Definition meteor-engine.h:80
Definition meteor-engine.h:96
Definition meteor-engine.h:108