float DigFil(invar, states)
float invar, *states;
/******************************************************************************/
/* Filter Solutions Version 2015 Nuhertz Technologies, L.L.C. */
/* www.nuhertz.com */
/* +1 602-279-2448 */
/* 4th Order Low Pass Butterworth */
/* Bilinear Transformation with Prewarping */
/* Sample Frequency = 50.00 KHz */
/* Standard Form */
/* Arithmetic Precision = 4 Digits */
/* */
/* Pass Band Frequency = 10.00 KHz */
/* */
/******************************************************************************/
/* */
/* Input Variable Definitions: */
/* Inputs: */
/* invar float The input to the filter */
/* *states float Pointer to array holding the filter states */
/* (Minimum array dimension: 4) */
/* */
/* Option Selections: */
/* Standard C; Externally Initialized; External States; Optimized; */
/* */
/******************************************************************************/
/* */
/* This software is automatically generated by Filter Solutions */
/* no restrictions from Nuhertz Technologies, L.L.C. regarding the use and */
/* distributions of this software. */
/* */
/******************************************************************************/
{
float sumnum=0.0, sumden=0.0; int i=0;
static float znum[3] = {
4.658e-02,
.1863,
.2795
};
static float zden[4] = {
3.012e-02,
-.1827,
.68,
-.7821
};
sumnum = sumden = 0.0;
for (i=0;i<4;i++){
sumden += states[i]*zden[i];
sumnum += states[i]*znum[i<3?i:4-i];
if (i<3) states[i] = states[i+1];
}
states[3] = invar-sumden;
sumnum += states[3]*znum[0];
return sumnum;
}
float DigFil(invar, initval, setic)
float invar, initval; int setic;
/******************************************************************************/
/* Filter Solutions Version 2015 Nuhertz Technologies, L.L.C. */
/* www.nuhertz.com */
/* +1 602-279-2448 */
/* 10th Order Low Pass Butterworth */
/* Bilinear Transformation with Prewarping */
/* Sample Frequency = 100.0 KHz */
/* Standard Form */
/* Arithmetic Precision = 4 Digits */
/* */
/* Pass Band Frequency = 8.000 KHz */
/* */
/******************************************************************************/
/* */
/* Input Variable Definitions: */
/* Inputs: */
/* invar float The input to the filter */
/* initvar float The initial value of the filter */
/* setic int 1 to initialize the filter to the value of initvar */
/* */
/* Option Selections: */
/* Standard C; Initializable; Internal States; Optimized; */
/* */
/* There is no requirement to ever initialize the filter. */
/* The default initialization is zero when the filter is first called */
/* */
/******************************************************************************/
/* */
/* This software is automatically generated by Filter Solutions */
/* no restrictions from Nuhertz Technologies, L.L.C. regarding the use and */
/* distributions of this software. */
/* */
/******************************************************************************/
{
float sumnum=0.0, sumden=0.0; int i=0;
static float states[10] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
static float znum[6] = {
2.442e-07,
2.442e-06,
1.099e-05,
2.93e-05,
5.127e-05,
6.153e-05
};
static float zden[10] = {
3.845e-02,
-.508,
3.045,
-10.91,
25.92,
-42.64,
49.28,
-39.55,
21.12,
-6.789
};
if (setic==1){
for (i=0;i<10;i++) states[i] = 4000.0*initval;
return initval;
}
else{
sumnum = sumden = 0.0;
for (i=0;i<10;i++){
sumden += states[i]*zden[i];
sumnum += states[i]*znum[i<6?i:10-i];
if (i<9) states[i] = states[i+1];
}
states[9] = invar-sumden;
sumnum += states[9]*znum[0];
return sumnum;
}
}
float value, output;
value = ADCgetFunction();
output=DigFil(value, initval,1); //I dont know what I must set at initval
theVector.push_back(output); //in this vector I store the filter's output
while(condition){
value=ADCgetFunction();
output=DigFil(value, initval,0); //agai I dont know whats to set at initval
theVector.push_back(output);
qcustomplotFunction(theVector);
}
I dont know what state to use.
The variable state refers to the initial value stored in the filter, such as if an input was present there before you inject the signal to be filtered. You could arbitrate any initial values for this variable, as for example the average value of the input signal of your AD converter; note that you've defined the option "Externally Initialized" therefore the argument is present at the function. This entry could even be ommited in the code for most the applications where data streams are continuously processed.
FilteredValue = DigFil (ADConverterResult(), states);
private double DigFil(double invar)
{
double sumnum, sumden; int i=0;
double [] znum = {0.0000002442, 0.000002442, 0.00001099, 0.0000293,0.00005127, 0.00006153 };
double [] zden = { 0.03845, -0.508, 3.045, -10.91, 25.92, -42.64, 49.28, -39.55,21.12,-6.789 };
sumnum = sumden = 0.0;
for (i=0;i<10;i++){
sumden += states[i]*zden[i];
sumnum += states[i]*znum[i<6?i:10-i];
if (i<9) states[i] = states[i+1];
}
states[9] = invar-sumden;
sumnum += states[9]*znum[0];
return sumnum;
}
public void onSensorChanged(SensorEvent event) {
if(flag==0) //just to see if this is the first time
{
for(int i=0;i<10;i++)
{
states[i]=event.values[SensorManager.DATA_X];
}
flag=1;
}
else {
double value;
valor = DigFil((double) event.values[SensorManager.DATA_X]); //event.values[SensorManager.DATA_X]just get the sensor value
this.tv1.setText("X = " + value);
this.tv2.setText("X = "+event.values[SensorManager.DATA_X]);
}
}
thanks andre. What do you mean by post-processing?
No, not with the controllable canonical form implemented in this filter.The vector (float *state), will gets the previous ADC values, right?
state[0] = invar1
state[1] = invar2
stat[2] = invar3
states[3] = invar-sumden;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?