48 #define MODULE "array_smoother" 50 float median (
int *counter,
float valin,
float valbuf[],
int lmed,
int mmed);
51 float hanning (
int *counter,
float valin,
float valhan[],
float win_coeff[],
59 int i, j, mid1, mid2 = 0, filler, nloops;
60 int C1, C2 = 0, C3 = 0, C4 = 0, c1, c2, c3, c4;
61 int delay, delx = 0, dely = 0;
70 float medval1, medval2, hanval1, hanval2, zatn;
73 xdel =
new float[2*
MAX_LEN-2]();
74 ydel =
new float[2*
MAX_LEN-2]();
75 inarray =
new float[arraylen];
76 for (i = 0; i < arraylen; ++i)
77 inarray[i] = p_array[i];
107 delay = delx + dely - 2;
116 for (i = 0; i < delay / 2; i++)
124 nloops = arraylen + delay;
127 for (j = 0; j < nloops; j++)
129 if (j < filler || j >= nloops - filler)
132 input = inarray[in++];
136 for (i = delx - 1; i > 0; i--)
137 xdel[i] = xdel[i - 1];
150 hanval1 =
hanning (&c2, medval1, hanbuf1, win_coeffs, ms);
160 if (output != ms->
breaker && xdel[delx - 1]
162 zatn = xdel[delx - 1] - output;
166 for (i = dely - 1; i > 0; i--)
167 ydel[i] = ydel[i - 1];
170 medval2 =
median (&c3, zatn, medbuf2,
177 hanval2 =
hanning (&c4, medval2, hanbuf2,
184 if (output != ms->
breaker && ydel[dely - 1]
186 output += ydel[dely - 1];
194 p_array[out++] = output;
198 for (i = 0; i < delay / 2; i++)
201 if (newms)
delete ms;
207 float median (
int *counter,
float valin,
float valbuf[],
int lmed,
int mmed)
212 for (i = lmed - 1; i > 0; i--)
213 valbuf[i] = valbuf[i - 1];
225 for (i = 0; i < lmed; i++)
226 filmed[i] = valbuf[i];
228 for (j = lmed - 1; j > 0; j--)
229 for (i = 0; i < j; i++)
230 if (filmed[i] > filmed[i + 1])
233 filmed[i + 1] = filmed[i];
236 return (filmed[mmed]);
241 #define TWO_PI 6.28318530717958647698 248 for (i = 0; i < length; i++) {
249 x =
TWO_PI * (i + 1.0) / (length + 1.0);
250 win_coeff[i] = (1.0 - (float) cos (x)) / (length + 1.0);
255 float hanning (
int *counter,
float valin,
float valhan[],
float win_coeff[],
259 float valout = 0.0, weight[
MAX_LEN];
262 valhan[i] = valhan[i - 1];
275 valout += valhan[i] * win_coeff[i];
281 valout += valhan[i] * weight[j++];
float hanning(int *counter, float valin, float valhan[], float win_coeff[], struct Ms_Op *ms)
void mk_window_coeffs(int length, float win_coeff[])
void initialise_parameters(struct Ms_Op *p_par)
struct Ms_Op * default_ms_op(struct Ms_Op *ms)
float median(int *counter, float valin, float valbuf[], int lmed, int mmed)
void array_smoother(float *p_array, int arraylen, struct Ms_Op *ms)