Project

General

Profile

trombone_calc.txt

Kyle Hazelwood, 01/15/2015 12:01 PM

 
1
int trombone_calc(int tromb_id,TROMB_STRUCT *tune_set);
2
extern "C" void free_vector(float *data, int nl, int nh);
3
extern "C" float *vector(int nl, int nh);
4

    
5
/******************************************************************************/
6
/*++> int trombone_calc(int tromb_id,TROMB_STRUCT *tune_set)
7
*+
8
*++	Authored by Meiqin Xiao, copied from old R64.
9
*+
10
*+     	inputs:
11
*+      	tromb_id = 0 for GRP_QT_60X, 1 for GRP_QT_30X 
12
*+      	tune_set->delta_q[2] for h/v
13
*+      outputs:
14
*+      	tune_set->amps[NKNOB] cuurents(amps) for NKNOB quad trims
15
*+   
16
*/
17
/******************************************************************************/
18
int trombone_calc(int tromb_id,TROMB_STRUCT *tune_set)
19
{  
20
  int sts;
21
  int i,j,ii;
22
  float wmax,wmin;
23
  float **u;
24
  float **v;
25
  float *w;
26
  float *b;
27
  float *x;
28
 
29
 /* Meiqin's Coefficients for trombone 60x. date: 05/28/2013 */
30

    
31
  float u_60x[9][9] = {
32
                   { -136.992, 1678.1, 144.639, -1696.96, -74.2027, 
33
                  	1786.81, 47.9609, -1762.77, -52.5754}, 
34
	           {35.2887, 75.3339, -33.5186, -44.1195,37.1867, 
35
		  	42.1706, -35.7823, -14.7396, 37.5639}, 
36
		   {5756.82, -1306.98, -3853.78, 1679.54, 3048.33, 
37
		  	-1551.15, -795.505, 1760.18, 268.669},
38
		   {-151.905, -22.4222, 164.601, 12.7766, -181.884, 
39
		  	-12.9934, 186.623, 6.74839, -192.135}, 
40
		   {2.98716, 15.3422, 2.88162, 14.9116, 3.0027, 
41
		   	15.567, 2.86146, 15.0054, 3.01143}, 
42
		   {-15.6529, -2.77037, -14.7677, -2.94121, -15.5028, 
43
		  	-2.74323, -14.9448, -2.96573, -15.3222}, 
44
		   {0,0,0,0,0,0,0,0,0},
45
		   {0,0,0,0,0,0,0,0,0},
46
		   {0,0,0,0,0,0,0,0,0}
47
		   };
48

    
49
  float b_60x[4] = {0.00711792, 0.00276458, 0.0249164, 0.00257196};
50

    
51

    
52
/* Meiqin's Coefficients for trombone 30x. date: 05/28/2013  */
53

    
54
  float u_30x[9][9] = {
55
		   {-73.9913, 1095.79, 84.7623, -1209.83, -64.3239, 
56
		   	1199.45, 22.1875, -1269.98, -58.443}, 
57
  		   {22.9931, 61.8662, -16.1731, -21.4507, 22.545, 
58
		   	34.9442, -17.6378, 6.48973, 23.3571}, 
59
		   {-4235.46, -1174.04, 2616.28, 1171.92, -2118.35, 
60
		   	-1349.98, 579.233, 1272.17, 278.865}, 
61
		   {-84.5418, 12.6394, 91.5666, -10.6392, -106.494, 
62
		   	5.27928, 104.425, -2.80121, -113.037}, 
63
		   {1.8591, 8.60531, 1.58512, 8.33284, 1.86073, 
64
		   	8.47441, 1.5825, 8.46498, 1.85782}, 
65
		   {-9.18802, -1.94483, -8.21778, -1.87796, -9.13484, 
66
		   	-1.97709, -8.29325, -1.84834, -9.01922},
67
		   {0,0,0,0,0,0,0,0,0},
68
		   {0,0,0,0,0,0,0,0,0},
69
		   {0,0,0,0,0,0,0,0,0}
70
		   };
71

    
72
  float b_30x[4] = {-0.0000304265, -9.35635e-7, 0.000110228, -2.90133e-7};
73
   
74
  sts = TRUE;
75
  
76
  u=create_matrix(1,N, 1,N);
77
  v=create_matrix(1,N, 1,N);
78
  w=vector( 1,N);
79
  b=vector( 1,N);
80
  x=vector( 1,N);
81

    
82
  /* assign values to u vector and b[1:4] vector. They are trombone dependent */
83
  
84
  if (tromb_id == GRP_QT_60X) {
85

    
86
     /* Meiqin's Coefficients for trombone 60x */
87
     for (i = 0; i < 9; i++) {
88
        for (j = 0; j < 9; j++) {
89
           u[i+1][j+1] = u_60x[i][j];
90
	}
91
     }	   
92
     for (i = 0; i < 4; i++) b[i + 1] = b_60x[i];
93
  }
94
  else if (tromb_id == GRP_QT_30X) {
95

    
96
      /* Meiqin's Coefficients for trombone 30x */
97
     
98
     for (i = 0; i < 9; i++) {
99
        for (j = 0; j < 9; j++) {
100
           u[i+1][j+1] = u_30x[i][j];
101
	}
102
     }	   
103
     for (i = 0; i < 4; i++) b[i + 1] = b_30x[i];
104
  }
105

    
106
  else {
107
     error_message_c("Err: Invalid trombone id passed!",
108
                     ERR_SIMPLE_DISPLAY,RED);
109
     return TRUE;
110
  }   
111
  
112
  /* assign value to b[5:9] vector. Inputs delta_q[2] used here*/
113

    
114
  b[5]=tune_set->delta_q[0];
115
  b[6]=tune_set->delta_q[1];
116
  b[7]=0;
117
  b[8]=0;
118
  b[9]=0;
119

    
120
/*SVD the square matrix a.*/
121

    
122
       svdcmp(u,N,N,w,v);
123
       wmax=0.0;   /* will be the maximum singular value obtained.*/
124
       for (j=1;j<=N;j++) if (w[j]>wmax) wmax=w[j];
125
       wmin=wmax*10e-6;
126

    
127
/*This is where we set the threshold for singular values allowed to be nonzero. The constant is typical , but not universal. You have to experiment with your own application.*/
128

    
129
       for (j=1;j<=N;j++) if (w[j]<wmin) w[j]=0.;
130
       svbksb(u,w,v,N,N,b,x);
131

    
132
       for (i=0;i< NKNOB;i++){
133
	 ii=i+1;
134
	 tune_set->amps[i]=x[ii]/0.3048/0.00297;
135
	 if ( tune_set->amps[i] > 6.5 ) {
136
         error_message_c("Err: Maximum current exceed 6.5 Amps!",
137
                       ERR_SIMPLE_DISPLAY,RED);
138

    
139
	 tune_set->amps[i] = 6.5;
140
	 error_message_c("Caution: The current is repalced by 6.5 Amps!",
141
                       ERR_SIMPLE_DISPLAY,RED);
142
       }
143
	 if ( tune_set->amps[i] < -6.5 ) {
144
         error_message_c("Err: Maximum current exceed -6.5 Amps!",
145
                       ERR_SIMPLE_DISPLAY,RED);
146

    
147
	 tune_set->amps[i] = -6.5;
148
	 error_message_c("Caution: The current is repalced by -6.5 Amps!",
149
                       ERR_SIMPLE_DISPLAY,RED);
150
       }
151
       }
152
       
153
       sts = 0;
154
    //error_message_c("GOOD SOLUTION!",ERR_SIMPLE_DISPLAY,BLUE);
155

    
156
 /*
157
  for (i = 0; i < 5; i++) { 
158
    value = tune_set->amps[i];
159
    sprintf(numstr,"%8.3f",value);
160
    window_tvm_c(win_dis_id,i+12,10,numstr,8,GREEN);
161
  }
162
    for (i = 5; i <9; i++) { 
163
    value = tune_set->amps[i];
164
     sprintf(numstr,"%8.3f",value);
165
    window_tvm_c(win_dis_id,20-i,27,numstr,8,GREEN);
166
    
167
  }
168
  */
169
   
170
  //memcpy(q_amps,tune_set->amps,NKNOB*sizeof(float));
171

    
172
 return (sts);
173
}
174