Commit f0fe55b3 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Center filter on full second

parent 22ae1ef4
......@@ -235,17 +235,44 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
int filter2_sample=16;
int filter2_count=filter2_sample;
std::cerr << "Filter 1: " << filter1_win.size() << " Filter 2: " << filter2_win.size() << std::endl;
//
// Find the time closest to zero
// =============================
//
int start;
long msec;
long msec_prev=-1;
while (1){
buffer_in->pop(data);
msec=lrint(data->get_msec()/1.0e6);
std::cerr << "MSEC/MSEC_MIN: " << msec << " / " << msec_prev << std::endl;
if (msec<msec_prev){
// TODO: Check if this or previous closer to full second
start=1;
std::cerr << "FINISHED" << std::endl;
break;
} else {
msec_prev=msec;
}
}
// Wait in order to center on full minute
for (int i=start; i<=round((filter1_win.size()-1)/2); i++){
buffer_in->pop(data);
}
//
// Load initial number of points for filter1.
// ==========================================
//
for (int i=0; i<filter1_win.size()-1; i++){
buffer_in->pop(data);
tofilter1.push_back(new data_obs_vector(data));
}
//
......@@ -267,20 +294,20 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
data->filter_fir_sym(&tofilter1,&filter1_win);
tofilter2.push_back(new data_obs_vector(data));
//std::cerr << "FILTER1: " << tofilter2.size() << " " << filter2_win.size() << std::endl;
// Wait until filter2 queue is filled
if (tofilter2.size()==filter2_win.size()){
//std::cerr << "FILTER2: " << filter2_count << " " << filter2_sample << std::endl;
// Wait for downsampling and apply filter2
if (filter2_count==filter2_sample){
data->filter_fir_sym(&tofilter2,&filter2_win);
buffer_out->put(data);
filter2_count=1;
} else {
filter2_count++;
}
// Delete oldest data from filter2
......@@ -297,7 +324,7 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
}
// Delete oldest data from filter2
// Delete oldest data from filter1
delete(tofilter1[0]);
tofilter1.erase(tofilter1.begin());
......
......@@ -223,9 +223,9 @@ int data_obs::get_min() {
int data_obs::get_sec() {
return (sec);
}
// Microseconds
long data_obs::get_msec() {
return (msec);
return(msec);
}
/********************************************************************************
......
......@@ -308,13 +308,13 @@ int data_obs_vector::filter_fir_sym(std::vector <data_obs*>* data,
std::vector <double>* win){
// Sum of data
double Xs=0.0,Ys=0.0,Zs=0.0;
double Xs=0.0,Ys=0.0,Zs=0.0,T1s=0.0,T2s=0.0;
// Filtered values
double Xf=0.0,Yf=0.0,Zf=0.0;
// Missing data
double Xm=0.0,Ym=0.0,Zm=0.0;
// Number of missing data
int XmN=0,YmN=0,ZmN=0;
int XmN=0,YmN=0,ZmN=0,T1mN=0,T2mN=0;
double tmp_f;
......@@ -323,7 +323,6 @@ int data_obs_vector::filter_fir_sym(std::vector <data_obs*>* data,
// Number of data
int N=data->size();
if (data->size() != win->size()){
std::cerr << "Number of elements in data and win"
"must match !" << std::endl;
......@@ -346,15 +345,6 @@ int data_obs_vector::filter_fir_sym(std::vector <data_obs*>* data,
// Filter the data
for (int i=0; i<data->size(); i++){
data_in = dynamic_cast <data_obs_vector*> (data->at(i));
/*
if (data.size()>200){
std::cerr << i << " "
<< X << " "
<< data_in->X << " "
<< win[i] << " "
<< std::endl;
}
*/
// Look for missing data
if ( (data_in->X) == MD) {
......@@ -370,8 +360,8 @@ int data_obs_vector::filter_fir_sym(std::vector <data_obs*>* data,
Ym+=win->at(i);
YmN++;
} else {
Ys+=(data_in->Y);
Yf+=(data_in->Y)*(win->at(i));
Ys+=(data_in->Y);
}
if ( (data_in->Z) == MD) {
......@@ -381,6 +371,18 @@ int data_obs_vector::filter_fir_sym(std::vector <data_obs*>* data,
Zs+=(data_in->Z);
Zf+=(data_in->Z)*(win->at(i));
}
// Simple average for temperatures
if ( (data_in->T1) == MD) {
T1mN++;
} else {
T1s++;
}
if ( (data_in->T2) == MD) {
T2mN++;
} else {
T2s++;
}
}
......@@ -388,6 +390,9 @@ int data_obs_vector::filter_fir_sym(std::vector <data_obs*>* data,
this->X=Xf+1/(N-XmN)*Xm*Xs;
this->Y=Yf+1/(N-YmN)*Ym*Ys;
this->Z=Zf+1/(N-ZmN)*Zm*Zs;
// Simple average for T1 and T2
this->T1=T1s/(N-T1mN);
this->T2=T2s/(N-T2mN);
return(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment