Commit 397c0a76 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Merge branch 'rasp3_BEL'

parents f678c170 602643d1
......@@ -12,6 +12,7 @@ PRIVATE/
CHANGELOG
DataLogger
TMP/*
usr/*
!usr/GNUPLOT
!usr/START
......
......@@ -17,7 +17,7 @@ USR_TARGET = $(patsubst $(USE_SRC_DIR)%.cpp,%,$(USR_FILES))
#--------------------------------------
CC=g++
CCFLAGS=-g -lrt -std=c++11 -lpthread
CCFLAGS=-g -lrt -std=c++11
EXCL=driver_serial_emulate.o
# Uncomment to use virtual serial port. Run 'make clean all' afterwards
......
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input and *
* output. It can be used in combination with the SHELL file operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_file_H
#define _BUFFER_OBS_file_H
#include <buffer_obs.hpp>
#include <data_obs.hpp>
#include <fstream>
class buffer_obs_file : public buffer_obs
{
//
// Private class variables
//
private:
// Precision
int precision;
// Path to output files
std::string path;
// Format of output file (strftime)
std::string format;
// Currently opened filename (no path)
std::string filename="";
// File stream
std::fstream file;
//
// Constructors
//
public:
//buffer_obs_file(int precision=2);
//buffer_obs_file(int precision,std::string path);
buffer_obs_file(int precision=2,std::string path="", std::string format="TEST_%Y%m%d.txt");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
/** Get last element and delete */
public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
//
// Private Methods
//
/** Initialize the buffer */
private: int init();
/** Open file and create folder */
private: int open(std::string filename);
};
#endif /* _BUFFER_OBS_file_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class allows to combine different types of buffers and split output.
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_mult_H
#define _BUFFER_OBS_mult_H
// Package headers
#include <buffer_obs.hpp>
#include <data_obs.hpp>
// C++ headers
#include <vector>
class buffer_obs_mult : public buffer_obs
{
//
// Private class variables
//
private:
// Vector of buffers
std::vector <buffer_obs*> buffers;
//
// Constructors
//
public:
buffer_obs_mult(buffer_obs* buffer);
// Don't allow to avoid checking for empty buffer
//buffer_obs_mult();
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
/** Get last element and delete */
public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
/** Add a buffer */
public: int add(buffer_obs* buffer);
//
// Private Methods
//
/** Initialize the buffer */
private: int init();
};
#endif /* _BUFFER_OBS_mult_H */
......@@ -69,6 +69,8 @@ public: int set_time(data_obs* data);
/** Get the time of the data */
public: int get_time(int* year, int* mon, int* day, int* hour, int* min, int* sec,
long* msec);
/** Get time as tm */
public: int get_time(struct tm* time) const;
/** Get time as timespec */
public: int get_time(struct timespec* time) const;
......
......@@ -91,7 +91,7 @@ int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout,
********************************************************************************/
int Driver_Obs_Serial::send(const char* cmd) {
//printf("Send: %s\n",cmd);
//fprintf(stderr,"Send: %s\n",cmd);
return(serial.send(cmd));
......@@ -214,13 +214,13 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
// Try different baudrates
for (int i = 0; i < valid_baudrates_size; i++) {
//printf("---- Test baud rate: %7d ----\n", valid_baudrates[i]);
//fprintf(stderr,"---- Test baud rate: %7d ----\n", valid_baudrates[i]);
serial.set_baud(valid_baudrates[i]);
usleep(100000);
for (int j = 0; j<init_chars_num-1; j++){
//printf("BAUD: %s\n",init_chars[j]);
//fprintf(stderr,"BAUD: %s\n",init_chars[j]);
send(init_chars[j]);
usleep(10000);
flush();
......@@ -232,14 +232,14 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
break;
}
//printf("VB: %d",valid_baudrates_size);
//fprintf(stderr,"VB: %d",valid_baudrates_size);
// This has to be in loop as characters received at false baud rate
// somehow can corrupt the value in valid_baudrates_size (Buffer overrun
// in driver_serial::receive
// in driver_serial::receive)
serial.get_baudrates(&valid_baudrates, &valid_baudrates_size);
//printf(" %d\n",valid_baudrates_size);
//fprintf(stderr," %d\n",valid_baudrates_size);
}
......@@ -280,7 +280,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context,
// Try different baudrates
for (int i = 0; i < valid_baudrates_size; i++) {
//printf("---- Test baud rate: %7d ----\n", valid_baudrates[i]);
//fprintf(stderr,"---- Test baud rate: %7d ----\n", valid_baudrates[i]);
if (context->check_baud(valid_baudrates[i]) == 1) {
baud = valid_baudrates[i];
break;
......@@ -289,7 +289,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context,
somehow can corrupt the value in valid_baudrates_size (Buffer overrun
in driver_serial::receive */
serial.get_baudrates(&valid_baudrates, &valid_baudrates_size);
//printf(" %d\n",valid_baudrates_size);
//fprintf(stderr," %d\n",valid_baudrates_size);
}
// Check if baud rate could be determined
......
......@@ -191,118 +191,145 @@ int Filter_Obs::fir_window_vec(buffer_obs* buffer_in,
int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
buffer_obs* buffer_out, double freq_in){
//
// Initialize
// ==========
//
std::vector <data_obs*> tofilter1; // Filter1 queue
std::vector <data_obs*> tofilter2; // Filter2 queue
data_obs_vector* data = // Data to hold the
new data_obs_vector(); // filtered value
// Filter1 downsamples to 16 Hz with a cut-off frequency of 5 Hz
std::vector <double> filter1_win; // Filter window
int filter1_sample; // Output sample rate
int filter1_count; // Internal counter
if (freq_in==128){
// Created with MATLAB: fir1(128,5/64,gausswin(129));
filter1_win={0.00000000,0.00005934,0.00012869,0.00020467,0.00028254,0.00035629,0.00041885,0.00046247,0.00047925,0.00046172,0.00040364,0.00030074,0.00015153,-0.00004204,-0.00027398,-0.00053397,-0.00080733,-0.00107531,-0.00131591,-0.00150492,-0.00161756,-0.00163027,-0.00152288,-0.00128078,-0.00089712,-0.00037471,0.00027244,0.00101835,0.00182487,0.00264267,0.00341299,0.00407058,0.00454748,0.00477771,0.00470236,0.00427512,0.00346756,0.00227400,0.00071541,-0.00115799,-0.00326580,-0.00549837,-0.00771983,-0.00977320,-0.01148740,-0.01268595,-0.01319690,-0.01286345,-0.01155462,-0.00917531,-0.00567502,-0.00105456,0.00462973,0.01126474,0.01868264,0.02666616,0.03495694,0.04326671,0.05129062,0.05872201,0.06526776,0.07066341,0.07468700,0.07717085,0.07801061,0.07717085,0.07468700,0.07066341,0.06526776,0.05872201,0.05129062,0.04326671,0.03495694,0.02666616,0.01868264,0.01126474,0.00462973,-0.00105456,-0.00567502,-0.00917531,-0.01155462,-0.01286345,-0.01319690,-0.01268595,-0.01148740,-0.00977320,-0.00771983,-0.00549837,-0.00326580,-0.00115799,0.00071541,0.00227400,0.00346756,0.00427512,0.00470236,0.00477771,0.00454748,0.00407058,0.00341299,0.00264267,0.00182487,0.00101835,0.00027244,-0.00037471,-0.00089712,-0.00128078,-0.00152288,-0.00163027,-0.00161756,-0.00150492,-0.00131591,-0.00107531,-0.00080733,-0.00053397,-0.00027398,-0.00004204,0.00015153,0.00030074,0.00040364,0.00046172,0.00047925,0.00046247,0.00041885,0.00035629,0.00028254,0.00020467,0.00012869,0.00005934,0.00000000};
filter1_sample=8;
filter1_count=filter1_sample;
} else if (freq_in==640){
// Created with MATLAB: fir1(640,5/320,gausswin(641));
filter1_win={0.00000000, 0.00000219, 0.00000448, 0.00000685, 0.00000932, 0.00001187, 0.00001450, 0.00001721, 0.00001999, 0.00002283, 0.00002574, 0.00002870, 0.00003170, 0.00003475, 0.00003783, 0.00004093, 0.00004405, 0.00004718, 0.00005030, 0.00005342, 0.00005651, 0.00005957, 0.00006258, 0.00006554, 0.00006844, 0.00007126, 0.00007399, 0.00007662, 0.00007913, 0.00008152, 0.00008377, 0.00008587, 0.00008780, 0.00008956, 0.00009113, 0.00009249, 0.00009364, 0.00009457, 0.00009525, 0.00009568, 0.00009585, 0.00009574, 0.00009535, 0.00009465, 0.00009366, 0.00009234, 0.00009070, 0.00008873, 0.00008641, 0.00008375, 0.00008073, 0.00007735, 0.00007360, 0.00006949, 0.00006500, 0.00006015, 0.00005492, 0.00004932, 0.00004335, 0.00003701, 0.00003031, 0.00002325, 0.00001584, 0.00000809, -0.00000000, -0.00000841, -0.00001712, -0.00002614, -0.00003543, -0.00004499, -0.00005480, -0.00006483, -0.00007507, -0.00008549, -0.00009607, -0.00010679, -0.00011762, -0.00012853, -0.00013950, -0.00015049, -0.00016146, -0.00017240, -0.00018327, -0.00019402, -0.00020463, -0.00021506, -0.00022527, -0.00023523, -0.00024489, -0.00025422, -0.00026318, -0.00027172, -0.00027982, -0.00028742, -0.00029449, -0.00030098, -0.00030687, -0.00031210, -0.00031664, -0.00032046, -0.00032351, -0.00032576, -0.00032717, -0.00032771, -0.00032735, -0.00032605, -0.00032379, -0.00032054, -0.00031626, -0.00031095, -0.00030457, -0.00029711, -0.00028855, -0.00027888, -0.00026808, -0.00025615, -0.00024308, -0.00022887, -0.00021352, -0.00019704, -0.00017942, -0.00016069, -0.00014086, -0.00011994, -0.00009796, -0.00007494, -0.00005092, -0.00002593, 0.00000000, 0.00002682, 0.00005449, 0.00008295, 0.00011216, 0.00014206, 0.00017258, 0.00020367, 0.00023524, 0.00026724, 0.00029958, 0.00033218, 0.00036497, 0.00039786, 0.00043075, 0.00046355, 0.00049618, 0.00052853, 0.00056051, 0.00059200, 0.00062292, 0.00065315, 0.00068259, 0.00071113, 0.00073866, 0.00076508, 0.00079026, 0.00081411, 0.00083651, 0.00085736, 0.00087654, 0.00089395, 0.00090949, 0.00092305, 0.00093453, 0.00094383, 0.00095087, 0.00095553, 0.00095775, 0.00095743, 0.00095449, 0.00094886, 0.00094046, 0.00092924, 0.00091514, 0.00089810, 0.00087807, 0.00085502, 0.00082891, 0.00079971, 0.00076742, 0.00073202, 0.00069351, 0.00065189, 0.00060718, 0.00055940, 0.00050859, 0.00045480, 0.00039806, 0.00033844, 0.00027602, 0.00021087, 0.00014308, 0.00007275, -0.00000000, -0.00007506, -0.00015231, -0.00023160, -0.00031278, -0.00039570, -0.00048018, -0.00056607, -0.00065316, -0.00074126, -0.00083018, -0.00091970, -0.00100960, -0.00109966, -0.00118965, -0.00127932, -0.00136843, -0.00145673, -0.00154395, -0.00162984, -0.00171413, -0.00179653, -0.00187679, -0.00195462, -0.00202974, -0.00210187, -0.00217072, -0.00223601, -0.00229746, -0.00235478, -0.00240769, -0.00245591, -0.00249916, -0.00253717, -0.00256967, -0.00259639, -0.00261708, -0.00263149, -0.00263936, -0.00264046, -0.00263455, -0.00262143, -0.00260086, -0.00257267, -0.00253664, -0.00249262, -0.00244042, -0.00237989, -0.00231090, -0.00223332, -0.00214703, -0.00205195, -0.00194797, -0.00183505, -0.00171312, -0.00158216, -0.00144215, -0.00129309, -0.00113499, -0.00096790, -0.00079187, -0.00060696, -0.00041327, -0.00021091, 0.00000000, 0.00021931, 0.00044686, 0.00068247, 0.00092594, 0.00117705, 0.00143556, 0.00170123, 0.00197378, 0.00225293, 0.00253837, 0.00282979, 0.00312686, 0.00342921, 0.00373650, 0.00404833, 0.00436433, 0.00468408, 0.00500718, 0.00533319, 0.00566167, 0.00599219, 0.00632428, 0.00665748, 0.00699133, 0.00732533, 0.00765902, 0.00799190, 0.00832348, 0.00865327, 0.00898077, 0.00930550, 0.00962694, 0.00994462, 0.01025804, 0.01056670, 0.01087014, 0.01116786, 0.01145941, 0.01174430, 0.01202209, 0.01229233, 0.01255459, 0.01280843, 0.01305344, 0.01328923, 0.01351540, 0.01373158, 0.01393741, 0.01413256, 0.01431670, 0.01448952, 0.01465073, 0.01480006, 0.01493727, 0.01506212, 0.01517440, 0.01527392, 0.01536052, 0.01543404, 0.01549436, 0.01554139, 0.01557504, 0.01559525, 0.01560199, 0.01559525, 0.01557504, 0.01554139, 0.01549436, 0.01543404, 0.01536052, 0.01527392, 0.01517440, 0.01506212, 0.01493727, 0.01480006, 0.01465073, 0.01448952, 0.01431670, 0.01413256, 0.01393741, 0.01373158, 0.01351540, 0.01328923, 0.01305344, 0.01280843, 0.01255459, 0.01229233, 0.01202209, 0.01174430, 0.01145941, 0.01116786, 0.01087014, 0.01056670, 0.01025804, 0.00994462, 0.00962694, 0.00930550, 0.00898077, 0.00865327, 0.00832348, 0.00799190, 0.00765902, 0.00732533, 0.00699133, 0.00665748, 0.00632428, 0.00599219, 0.00566167, 0.00533319, 0.00500718, 0.00468408, 0.00436433, 0.00404833, 0.00373650, 0.00342921, 0.00312686, 0.00282979, 0.00253837, 0.00225293, 0.00197378, 0.00170123, 0.00143556, 0.00117705, 0.00092594, 0.00068247, 0.00044686, 0.00021931, 0.00000000, -0.00021091, -0.00041327, -0.00060696, -0.00079187, -0.00096790, -0.00113499, -0.00129309, -0.00144215, -0.00158216, -0.00171312, -0.00183505, -0.00194797, -0.00205195, -0.00214703, -0.00223332, -0.00231090, -0.00237989, -0.00244042, -0.00249262, -0.00253664, -0.00257267, -0.00260086, -0.00262143, -0.00263455, -0.00264046, -0.00263936, -0.00263149, -0.00261708, -0.00259639, -0.00256967, -0.00253717, -0.00249916, -0.00245591, -0.00240769, -0.00235478, -0.00229746, -0.00223601, -0.00217072, -0.00210187, -0.00202974, -0.00195462, -0.00187679, -0.00179653, -0.00171413, -0.00162984, -0.00154395, -0.00145673, -0.00136843, -0.00127932, -0.00118965, -0.00109966, -0.00100960, -0.00091970, -0.00083018, -0.00074126, -0.00065316, -0.00056607, -0.00048018, -0.00039570, -0.00031278, -0.00023160, -0.00015231, -0.00007506, -0.00000000, 0.00007275, 0.00014308, 0.00021087, 0.00027602, 0.00033844, 0.00039806, 0.00045480, 0.00050859, 0.00055940, 0.00060718, 0.00065189, 0.00069351, 0.00073202, 0.00076742, 0.00079971, 0.00082891, 0.00085502, 0.00087807, 0.00089810, 0.00091514, 0.00092924, 0.00094046, 0.00094886, 0.00095449, 0.00095743, 0.00095775, 0.00095553, 0.00095087, 0.00094383, 0.00093453, 0.00092305, 0.00090949, 0.00089395, 0.00087654, 0.00085736, 0.00083651, 0.00081411, 0.00079026, 0.00076508, 0.00073866, 0.00071113, 0.00068259, 0.00065315, 0.00062292, 0.00059200, 0.00056051, 0.00052853, 0.00049618, 0.00046355, 0.00043075, 0.00039786, 0.00036497, 0.00033218, 0.00029958, 0.00026724, 0.00023524, 0.00020367, 0.00017258, 0.00014206, 0.00011216, 0.00008295, 0.00005449, 0.00002682, 0.00000000, -0.00002593, -0.00005092, -0.00007494, -0.00009796, -0.00011994, -0.00014086, -0.00016069, -0.00017942, -0.00019704, -0.00021352, -0.00022887, -0.00024308, -0.00025615, -0.00026808, -0.00027888, -0.00028855, -0.00029711, -0.00030457, -0.00031095, -0.00031626, -0.00032054, -0.00032379, -0.00032605, -0.00032735, -0.00032771, -0.00032717, -0.00032576, -0.00032351, -0.00032046, -0.00031664, -0.00031210, -0.00030687, -0.00030098, -0.00029449, -0.00028742, -0.00027982, -0.00027172, -0.00026318, -0.00025422, -0.00024489, -0.00023523, -0.00022527, -0.00021506, -0.00020463, -0.00019402, -0.00018327, -0.00017240, -0.00016146, -0.00015049, -0.00013950, -0.00012853, -0.00011762, -0.00010679, -0.00009607, -0.00008549, -0.00007507, -0.00006483, -0.00005480, -0.00004499, -0.00003543, -0.00002614, -0.00001712, -0.00000841, -0.00000000, 0.00000809, 0.00001584, 0.00002325, 0.00003031, 0.00003701, 0.00004335, 0.00004932, 0.00005492, 0.00006015, 0.00006500, 0.00006949, 0.00007360, 0.00007735, 0.00008073, 0.00008375, 0.00008641, 0.00008873, 0.00009070, 0.00009234, 0.00009366, 0.00009465, 0.00009535, 0.00009574, 0.00009585, 0.00009568, 0.00009525, 0.00009457, 0.00009364, 0.00009249, 0.00009113, 0.00008956, 0.00008780, 0.00008587, 0.00008377, 0.00008152, 0.00007913, 0.00007662, 0.00007399, 0.00007126, 0.00006844, 0.00006554, 0.00006258, 0.00005957, 0.00005651, 0.00005342, 0.00005030, 0.00004718, 0.00004405, 0.00004093, 0.00003783, 0.00003475, 0.00003170, 0.00002870, 0.00002574, 0.00002283, 0.00001999, 0.00001721, 0.00001450, 0.00001187, 0.00000932, 0.00000685, 0.00000448, 0.00000219, 0.00000000};
filter1_sample=40;
filter1_count=filter1_sample;
} else {
return(-1);
}
// Filter2 downsamples to 1 Hz with a cut-off frequency of XXX Hz
std::vector <double> filter2_win={0.00006417,0.00007841,0.00009291,0.00010743,0.00012169,0.00013541,0.00014827,0.00015992,0.00017001,0.00017819,0.00018409,0.00018735,0.00018762,0.00018456,0.00017787,0.00016727,0.00015255,0.00013351,0.00011006,0.00008214,0.00004980,0.00001314,-0.00002761,-0.00007216,-0.00012009,-0.00017089,-0.00022395,-0.00027856,-0.00033390,-0.00038907,-0.00044307,-0.00049485,-0.00054327,-0.00058715,-0.00062530,-0.00065649,-0.00067952,-0.00069321,-0.00069646,-0.00068821,-0.00066755,-0.00063369,-0.00058598,-0.00052399,-0.00044747,-0.00035643,-0.00025112,-0.00013204,0.00000000,0.00014390,0.00029827,0.00046141,0.00063134,0.00080578,0.00098218,0.00115777,0.00132951,0.00149423,0.00164858,0.00178912,0.00191235,0.00201478,0.00209301,0.00214372,0.00216381,0.00215043,0.00210107,0.00201359,0.00188631,0.00171807,0.00150829,0.00125701,0.00096496,0.00063355,0.00026496,-0.00013787,-0.00057125,-0.00103071,-0.00151101,-0.00200620,-0.00250963,-0.00301402,-0.00351151,-0.00399372,-0.00445189,-0.00487692,-0.00525952,-0.00559029,-0.00585988,-0.00605909,-0.00617901,-0.00621117,-0.00614765,-0.00598123,-0.00570551,-0.00531503,-0.00480541,-0.00417341,-0.00341705,-0.00253570,-0.00153009,-0.00040242,0.00084364,0.00220297,0.00366896,0.00523358,0.00688740,0.00861970,0.01041852,0.01227080,0.01416249,0.01607870,0.01800386,0.01992185,0.02181626,0.02367050,0.02546803,0.02719254,0.02882815,0.03035961,0.03177248,0.03305330,0.03418976,0.03517086,0.03598706,0.03663036,0.03709444,0.03737474,0.03746848,0.03737474,0.03709444,0.03663036,0.03598706,0.03517086,0.03418976,0.03305330,0.03177248,0.03035961,0.02882815,0.02719254,0.02546803,0.02367050,0.02181626,0.01992185,0.01800386,0.01607870,0.01416249,0.01227080,0.01041852,0.00861970,0.00688740,0.00523358,0.00366896,0.00220297,0.00084364,-0.00040242,-0.00153009,-0.00253570,-0.00341705,-0.00417341,-0.00480541,-0.00531503,-0.00570551,-0.00598123,-0.00614765,-0.00621117,-0.00617901,-0.00605909,-0.00585988,-0.00559029,-0.00525952,-0.00487692,-0.00445189,-0.00399372,-0.00351151,-0.00301402,-0.00250963,-0.00200620,-0.00151101,-0.00103071,-0.00057125,-0.00013787,0.00026496,0.00063355,0.00096496,0.00125701,0.00150829,0.00171807,0.00188631,0.00201359,0.00210107,0.00215043,0.00216381,0.00214372,0.00209301,0.00201478,0.00191235,0.00178912,0.00164858,0.00149423,0.00132951,0.00115777,0.00098218,0.00080578,0.00063134,0.00046141,0.00029827,0.00014390,0.00000000,-0.00013204,-0.00025112,-0.00035643,-0.00044747,-0.00052399,-0.00058598,-0.00063369,-0.00066755,-0.00068821,-0.00069646,-0.00069321,-0.00067952,-0.00065649,-0.00062530,-0.00058715,-0.00054327,-0.00049485,-0.00044307,-0.00038907,-0.00033390,-0.00027856,-0.00022395,-0.00017089,-0.00012009,-0.00007216,-0.00002761,0.00001314,0.00004980,0.00008214,0.00011006,0.00013351,0.00015255,0.00016727,0.00017787,0.00018456,0.00018762,0.00018735,0.00018409,0.00017819,0.00017001,0.00015992,0.00014827,0.00013541,0.00012169,0.00010743,0.00009291,0.00007841,0.00006417};
int filter2_sample=16;
int filter2_count=filter2_sample;
//
// 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));
}
//
// Initialize
// ==========
//
std::vector <data_obs*> tofilter1; // Filter1 queue
std::vector <data_obs*> tofilter2; // Filter2 queue
data_obs_vector* data = // Data to hold the
new data_obs_vector(); // filtered value
// Filter1 downsamples to 16 Hz with a cut-off frequency of 5 Hz
std::vector <double> filter1_win; // Filter window
int filter1_sample; // Output sample rate
int filter1_count; // Internal counter
if (freq_in==128){
// Created with MATLAB: fir1(128,5/64,gausswin(129));
filter1_win={0.00000000,0.00005934,0.00012869,0.00020467,0.00028254,0.00035629,0.00041885,0.00046247,0.00047925,0.00046172,0.00040364,0.00030074,0.00015153,-0.00004204,-0.00027398,-0.00053397,-0.00080733,-0.00107531,-0.00131591,-0.00150492,-0.00161756,-0.00163027,-0.00152288,-0.00128078,-0.00089712,-0.00037471,0.00027244,0.00101835,0.00182487,0.00264267,0.00341299,0.00407058,0.00454748,0.00477771,0.00470236,0.00427512,0.00346756,0.00227400,0.00071541,-0.00115799,-0.00326580,-0.00549837,-0.00771983,-0.00977320,-0.01148740,-0.01268595,-0.01319690,-0.01286345,-0.01155462,-0.00917531,-0.00567502,-0.00105456,0.00462973,0.01126474,0.01868264,0.02666616,0.03495694,0.04326671,0.05129062,0.05872201,0.06526776,0.07066341,0.07468700,0.07717085,0.07801061,0.07717085,0.07468700,0.07066341,0.06526776,0.05872201,0.05129062,0.04326671,0.03495694,0.02666616,0.01868264,0.01126474,0.00462973,-0.00105456,-0.00567502,-0.00917531,-0.01155462,-0.01286345,-0.01319690,-0.01268595,-0.01148740,-0.00977320,-0.00771983,-0.00549837,-0.00326580,-0.00115799,0.00071541,0.00227400,0.00346756,0.00427512,0.00470236,0.00477771,0.00454748,0.00407058,0.00341299,0.00264267,0.00182487,0.00101835,0.00027244,-0.00037471,-0.00089712,-0.00128078,-0.00152288,-0.00163027,-0.00161756,-0.00150492,-0.00131591,-0.00107531,-0.00080733,-0.00053397,-0.00027398,-0.00004204,0.00015153,0.00030074,0.00040364,0.00046172,0.00047925,0.00046247,0.00041885,0.00035629,0.00028254,0.00020467,0.00012869,0.00005934,0.00000000};
filter1_sample=8;
filter1_count=filter1_sample;
} else if (freq_in==640){
// Created with MATLAB: fir1(640,5/320,gausswin(641));
filter1_win={0.00000000, 0.00000219, 0.00000448, 0.00000685, 0.00000932, 0.00001187, 0.00001450, 0.00001721, 0.00001999, 0.00002283, 0.00002574, 0.00002870, 0.00003170, 0.00003475, 0.00003783, 0.00004093, 0.00004405, 0.00004718, 0.00005030, 0.00005342, 0.00005651, 0.00005957, 0.00006258, 0.00006554, 0.00006844, 0.00007126, 0.00007399, 0.00007662, 0.00007913, 0.00008152, 0.00008377, 0.00008587, 0.00008780, 0.00008956, 0.00009113, 0.00009249, 0.00009364, 0.00009457, 0.00009525, 0.00009568, 0.00009585, 0.00009574, 0.00009535, 0.00009465, 0.00009366, 0.00009234, 0.00009070, 0.00008873, 0.00008641, 0.00008375, 0.00008073, 0.00007735, 0.00007360, 0.00006949, 0.00006500, 0.00006015, 0.00005492, 0.00004932, 0.00004335, 0.00003701, 0.00003031, 0.00002325, 0.00001584, 0.00000809, -0.00000000, -0.00000841, -0.00001712, -0.00002614, -0.00003543, -0.00004499, -0.00005480, -0.00006483, -0.00007507, -0.00008549, -0.00009607, -0.00010679, -0.00011762, -0.00012853, -0.00013950, -0.00015049, -0.00016146, -0.00017240, -0.00018327, -0.00019402, -0.00020463, -0.00021506, -0.00022527, -0.00023523, -0.00024489, -0.00025422, -0.00026318, -0.00027172, -0.00027982, -0.00028742, -0.00029449, -0.00030098, -0.00030687, -0.00031210, -0.00031664, -0.00032046, -0.00032351, -0.00032576, -0.00032717, -0.00032771, -0.00032735, -0.00032605, -0.00032379, -0.00032054, -0.00031626, -0.00031095, -0.00030457, -0.00029711, -0.00028855, -0.00027888, -0.00026808, -0.00025615, -0.00024308, -0.00022887, -0.00021352, -0.00019704, -0.00017942, -0.00016069, -0.00014086, -0.00011994, -0.00009796, -0.00007494, -0.00005092, -0.00002593, 0.00000000, 0.00002682, 0.00005449, 0.00008295, 0.00011216, 0.00014206, 0.00017258, 0.00020367, 0.00023524, 0.00026724, 0.00029958, 0.00033218, 0.00036497, 0.00039786, 0.00043075, 0.00046355, 0.00049618, 0.00052853, 0.00056051, 0.00059200, 0.00062292, 0.00065315, 0.00068259, 0.00071113, 0.00073866, 0.00076508, 0.00079026, 0.00081411, 0.00083651, 0.00085736, 0.00087654, 0.00089395, 0.00090949, 0.00092305, 0.00093453, 0.00094383, 0.00095087, 0.00095553, 0.00095775, 0.00095743, 0.00095449, 0.00094886, 0.00094046, 0.00092924, 0.00091514, 0.00089810, 0.00087807, 0.00085502, 0.00082891, 0.00079971, 0.00076742, 0.00073202, 0.00069351, 0.00065189, 0.00060718, 0.00055940, 0.00050859, 0.00045480, 0.00039806, 0.00033844, 0.00027602, 0.00021087, 0.00014308, 0.00007275, -0.00000000, -0.00007506, -0.00015231, -0.00023160, -0.00031278, -0.00039570, -0.00048018, -0.00056607, -0.00065316, -0.00074126, -0.00083018, -0.00091970, -0.00100960, -0.00109966, -0.00118965, -0.00127932, -0.00136843, -0.00145673, -0.00154395, -0.00162984, -0.00171413, -0.00179653, -0.00187679, -0.00195462, -0.00202974, -0.00210187, -0.00217072, -0.00223601, -0.00229746, -0.00235478, -0.00240769, -0.00245591, -0.00249916, -0.00253717, -0.00256967, -0.00259639, -0.00261708, -0.00263149, -0.00263936, -0.00264046, -0.00263455, -0.00262143, -0.00260086, -0.00257267, -0.00253664, -0.00249262, -0.00244042, -0.00237989, -0.00231090, -0.00223332, -0.00214703, -0.00205195, -0.00194797, -0.00183505, -0.00171312, -0.00158216, -0.00144215, -0.00129309, -0.00113499, -0.00096790, -0.00079187, -0.00060696, -0.00041327, -0.00021091, 0.00000000, 0.00021931, 0.00044686, 0.00068247, 0.00092594, 0.00117705, 0.00143556, 0.00170123, 0.00197378, 0.00225293, 0.00253837, 0.00282979, 0.00312686, 0.00342921, 0.00373650, 0.00404833, 0.00436433, 0.00468408, 0.00500718, 0.00533319, 0.00566167, 0.00599219, 0.00632428, 0.00665748, 0.00699133, 0.00732533, 0.00765902, 0.00799190, 0.00832348, 0.00865327, 0.00898077, 0.00930550, 0.00962694, 0.00994462, 0.01025804, 0.01056670, 0.01087014, 0.01116786, 0.01145941, 0.01174430, 0.01202209, 0.01229233, 0.01255459, 0.01280843, 0.01305344, 0.01328923, 0.01351540, 0.01373158, 0.01393741, 0.01413256, 0.01431670, 0.01448952, 0.01465073, 0.01480006, 0.01493727, 0.01506212, 0.01517440, 0.01527392, 0.01536052, 0.01543404, 0.01549436, 0.01554139, 0.01557504, 0.01559525, 0.01560199, 0.01559525, 0.01557504, 0.01554139, 0.01549436, 0.01543404, 0.01536052, 0.01527392, 0.01517440, 0.01506212, 0.01493727, 0.01480006, 0.01465073, 0.01448952, 0.01431670, 0.01413256, 0.01393741, 0.01373158, 0.01351540, 0.01328923, 0.01305344, 0.01280843, 0.01255459, 0.01229233, 0.01202209, 0.01174430, 0.01145941, 0.01116786, 0.01087014, 0.01056670, 0.01025804, 0.00994462, 0.00962694, 0.00930550, 0.00898077, 0.00865327, 0.00832348, 0.00799190, 0.00765902, 0.00732533, 0.00699133, 0.00665748, 0.00632428, 0.00599219, 0.00566167, 0.00533319, 0.00500718, 0.00468408, 0.00436433, 0.00404833, 0.00373650, 0.00342921, 0.00312686, 0.00282979, 0.00253837, 0.00225293, 0.00197378, 0.00170123, 0.00143556, 0.00117705, 0.00092594, 0.00068247, 0.00044686, 0.00021931, 0.00000000, -0.00021091, -0.00041327, -0.00060696, -0.00079187, -0.00096790, -0.00113499, -0.00129309, -0.00144215, -0.00158216, -0.00171312, -0.00183505, -0.00194797, -0.00205195, -0.00214703, -0.00223332, -0.00231090, -0.00237989, -0.00244042, -0.00249262, -0.00253664, -0.00257267, -0.00260086, -0.00262143, -0.00263455, -0.00264046, -0.00263936, -0.00263149, -0.00261708, -0.00259639, -0.00256967, -0.00253717, -0.00249916, -0.00245591, -0.00240769, -0.00235478, -0.00229746, -0.00223601, -0.00217072, -0.00210187, -0.00202974, -0.00195462, -0.00187679, -0.00179653, -0.00171413, -0.00162984, -0.00154395, -0.00145673, -0.00136843, -0.00127932, -0.00118965, -0.00109966, -0.00100960, -0.00091970, -0.00083018, -0.00074126, -0.00065316, -0.00056607, -0.00048018, -0.00039570, -0.00031278, -0.00023160, -0.00015231, -0.00007506, -0.00000000, 0.00007275, 0.00014308, 0.00021087, 0.00027602, 0.00033844, 0.00039806, 0.00045480, 0.00050859, 0.00055940, 0.00060718, 0.00065189, 0.00069351, 0.00073202, 0.00076742, 0.00079971, 0.00082891, 0.00085502, 0.00087807, 0.00089810, 0.00091514, 0.00092924, 0.00094046, 0.00094886, 0.00095449, 0.00095743, 0.00095775, 0.00095553, 0.00095087, 0.00094383, 0.00093453, 0.00092305, 0.00090949, 0.00089395, 0.00087654, 0.00085736, 0.00083651, 0.00081411, 0.00079026, 0.00076508, 0.00073866, 0.00071113, 0.00068259, 0.00065315, 0.00062292, 0.00059200, 0.00056051, 0.00052853, 0.00049618, 0.00046355, 0.00043075, 0.00039786, 0.00036497, 0.00033218, 0.00029958, 0.00026724, 0.00023524, 0.00020367, 0.00017258, 0.00014206, 0.00011216, 0.00008295, 0.00005449, 0.00002682, 0.00000000, -0.00002593, -0.00005092, -0.00007494, -0.00009796, -0.00011994, -0.00014086, -0.00016069, -0.00017942, -0.00019704, -0.00021352, -0.00022887, -0.00024308, -0.00025615, -0.00026808, -0.00027888, -0.00028855, -0.00029711, -0.00030457, -0.00031095, -0.00031626, -0.00032054, -0.00032379, -0.00032605, -0.00032735, -0.00032771, -0.00032717, -0.00032576, -0.00032351, -0.00032046, -0.00031664, -0.00031210, -0.00030687, -0.00030098, -0.00029449, -0.00028742, -0.00027982, -0.00027172, -0.00026318, -0.00025422, -0.00024489, -0.00023523, -0.00022527, -0.00021506, -0.00020463, -0.00019402, -0.00018327, -0.00017240, -0.00016146, -0.00015049, -0.00013950, -0.00012853, -0.00011762, -0.00010679, -0.00009607, -0.00008549, -0.00007507, -0.00006483, -0.00005480, -0.00004499, -0.00003543, -0.00002614, -0.00001712, -0.00000841, -0.00000000, 0.00000809, 0.00001584, 0.00002325, 0.00003031, 0.00003701, 0.00004335, 0.00004932, 0.00005492, 0.00006015, 0.00006500, 0.00006949, 0.00007360, 0.00007735, 0.00008073, 0.00008375, 0.00008641, 0.00008873, 0.00009070, 0.00009234, 0.00009366, 0.00009465, 0.00009535, 0.00009574, 0.00009585, 0.00009568, 0.00009525, 0.00009457, 0.00009364, 0.00009249, 0.00009113, 0.00008956, 0.00008780, 0.00008587, 0.00008377, 0.00008152, 0.00007913, 0.00007662, 0.00007399, 0.00007126, 0.00006844, 0.00006554, 0.00006258, 0.00005957, 0.00005651, 0.00005342, 0.00005030, 0.00004718, 0.00004405, 0.00004093, 0.00003783, 0.00003475, 0.00003170, 0.00002870, 0.00002574, 0.00002283, 0.00001999, 0.00001721, 0.00001450, 0.00001187, 0.00000932, 0.00000685, 0.00000448, 0.00000219, 0.00000000};
filter1_sample=40;
filter1_count=filter1_sample;
} else {
return(-1);
}
// Filter2 downsamples to 1 Hz with a cut-off frequency of XXX Hz
std::vector <double> filter2_win={0.00006417,0.00007841,0.00009291,0.00010743,0.00012169,0.00013541,0.00014827,0.00015992,0.00017001,0.00017819,0.00018409,0.00018735,0.00018762,0.00018456,0.00017787,0.00016727,0.00015255,0.00013351,0.00011006,0.00008214,0.00004980,0.00001314,-0.00002761,-0.00007216,-0.00012009,-0.00017089,-0.00022395,-0.00027856,-0.00033390,-0.00038907,-0.00044307,-0.00049485,-0.00054327,-0.00058715,-0.00062530,-0.00065649,-0.00067952,-0.00069321,-0.00069646,-0.00068821,-0.00066755,-0.00063369,-0.00058598,-0.00052399,-0.00044747,-0.00035643,-0.00025112,-0.00013204,0.00000000,0.00014390,0.00029827,0.00046141,0.00063134,0.00080578,0.00098218,0.00115777,0.00132951,0.00149423,0.00164858,0.00178912,0.00191235,0.00201478,0.00209301,0.00214372,0.00216381,0.00215043,0.00210107,0.00201359,0.00188631,0.00171807,0.00150829,0.00125701,0.00096496,0.00063355,0.00026496,-0.00013787,-0.00057125,-0.00103071,-0.00151101,-0.00200620,-0.00250963,-0.00301402,-0.00351151,-0.00399372,-0.00445189,-0.00487692,-0.00525952,-0.00559029,-0.00585988,-0.00605909,-0.00617901,-0.00621117,-0.00614765,-0.00598123,-0.00570551,-0.00531503,-0.00480541,-0.00417341,-0.00341705,-0.00253570,-0.00153009,-0.00040242,0.00084364,0.00220297,0.00366896,0.00523358,0.00688740,0.00861970,0.01041852,0.01227080,0.01416249,0.01607870,0.01800386,0.01992185,0.02181626,0.02367050,0.02546803,0.02719254,0.02882815,0.03035961,0.03177248,0.03305330,0.03418976,0.03517086,0.03598706,0.03663036,0.03709444,0.03737474,0.03746848,0.03737474,0.03709444,0.03663036,0.03598706,0.03517086,0.03418976,0.03305330,0.03177248,0.03035961,0.02882815,0.02719254,0.02546803,0.02367050,0.02181626,0.01992185,0.01800386,0.01607870,0.01416249,0.01227080,0.01041852,0.00861970,0.00688740,0.00523358,0.00366896,0.00220297,0.00084364,-0.00040242,-0.00153009,-0.00253570,-0.00341705,-0.00417341,-0.00480541,-0.00531503,-0.00570551,-0.00598123,-0.00614765,-0.00621117,-0.00617901,-0.00605909,-0.00585988,-0.00559029,-0.00525952,-0.00487692,-0.00445189,-0.00399372,-0.00351151,-0.00301402,-0.00250963,-0.00200620,-0.00151101,-0.00103071,-0.00057125,-0.00013787,0.00026496,0.00063355,0.00096496,0.00125701,0.00150829,0.00171807,0.00188631,0.00201359,0.00210107,0.00215043,0.00216381,0.00214372,0.00209301,0.00201478,0.00191235,0.00178912,0.00164858,0.00149423,0.00132951,0.00115777,0.00098218,0.00080578,0.00063134,0.00046141,0.00029827,0.00014390,0.00000000,-0.00013204,-0.00025112,-0.00035643,-0.00044747,-0.00052399,-0.00058598,-0.00063369,-0.00066755,-0.00068821,-0.00069646,-0.00069321,-0.00067952,-0.00065649,-0.00062530,-0.00058715,-0.00054327,-0.00049485,-0.00044307,-0.00038907,-0.00033390,-0.00027856,-0.00022395,-0.00017089,-0.00012009,-0.00007216,-0.00002761,0.00001314,0.00004980,0.00008214,0.00011006,0.00013351,0.00015255,0.00016727,0.00017787,0.00018456,0.00018762,0.00018735,0.00018409,0.00017819,0.00017001,0.00015992,0.00014827,0.00013541,0.00012169,0.00010743,0.00009291,0.00007841,0.00006417};
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));
}
//
// Continuously run concatenated filters one and two.
// =================================================
//
while (1){
// Read the data
buffer_in->pop(data);
// Add to filter1 queue
tofilter1.push_back(new data_obs_vector(data));
// Wait for downsampling and apply filter1
if (filter1_count==filter1_sample){
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()){
//
// Continuously run concatenated filters one and two.
// =================================================
//
while (1){
// Read the data
buffer_in->pop(data);
// Add to filter1 queue
tofilter1.push_back(new data_obs_vector(data));
// Wait for downsampling and apply filter1
if (filter1_count==filter1_sample){
data->filter_fir_sym(&tofilter1,&filter1_win);
tofilter2.push_back(new data_obs_vector(data));
// Wait until filter2 queue is filled
if (tofilter2.size()==filter2_win.size()){
// 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
delete(tofilter2[0]);
tofilter2.erase(tofilter2.begin());
}
filter1_count=1;
} else {
filter1_count++;
}
// Delete oldest data from filter2
delete(tofilter1[0]);
tofilter1.erase(tofilter1.begin());
}
return(0);
}
//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
delete(tofilter2[0]);
tofilter2.erase(tofilter2.begin());
}
filter1_count=1;
} else {
filter1_count++;
}
// Delete oldest data from filter1
delete(tofilter1[0]);
tofilter1.erase(tofilter1.begin());
}
return(0);
}
\ No newline at end of file
......@@ -83,9 +83,9 @@ int Obs_Calibration_Vector::calibrate(data_obs_vector* vdata){
vdata->get_data(data);
for (int i=0;i<3;i++){
//printf("SCALE: %f ",data[i]);
//fprintf(stderr,"SCALE: %f ",data[i]);
data[i]=data[i]*scale[i]+offset[i];
//printf("%f %f\n",data[i],scale[i]);
//fprintf(stderr,"%f %f\n",data[i],scale[i]);
}
vdata->set_data(data);
......@@ -305,7 +305,7 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
}
file.close();
} else {
std::cout << "Unable to open file: " << filename << std::endl;
std::cerr << "Unable to open file: " << filename << std::endl;
}
......
......@@ -64,21 +64,33 @@ Parameters_Reader::Parameters_Reader(std::string filename) {
*******************************************************************************/
std::string Parameters_Reader::get_str(std::string key){
return parMap.at(key);
if (parMap.find(key) == parMap.end()){
return("");
} else {
return parMap.at(key);
}
}
int Parameters_Reader::get_int(std::string key){
return std::stoi(parMap.at(key));
if (parMap.find(key) == parMap.end()){
return(-1);
} else {
return std::stoi(parMap.at(key));
}
}
double Parameters_Reader::get_dbl(std::string key){