time_series_fft.cpp

Example for RDM::TIME_SERIES template classes. This example needs a compiled schema, time_series_fft.sdl.

This example shows usage of the RDM::TIME_SERIES template classes with several classes including a split. The RDM::DB::transaction class can start a transaction by calling RDM::DB::transaction::begin(). It know which tables to lock and will also capture the state of the classes in the chain. When done with inserting data, RDM::DB::transaction::end() can be called. If for any reason an error condition is encountered, RDM::DB::transaction::rollback() can be called. It will roll the transaction back and also restore the stae of the classes.

The data passed to RDM::DB::transaction will be passed to RDM::TIME_SERIES::split which in turn will pass the same data to both classes in the split. Each class in the chain does what it is repsonsible for and passes it on untill it has been inserted into the database.

The example further show usage of two of the FFT classes we have provided. RDM::TIME_SERIES::fft_abs_positive does a Fast Fourier Transform (FFT) with a result set of the DC value and the absolute value of all the positive frequencies. RDM::TIME_SERIES::fft_abs does the same except that it also includes the negative frequencies.

The RDM::TIME_SERIES::scale class scales the result according to the ration specified and RDM::TIME_SERIES::arithmetic_mean computes the average values.

#include <math.h>
#include "time_series_fft_structs.h"
static RDM_RETCODE timeSeriesFftOfSineCurves (RDM_DB db)
{
using namespace RDM_CPP::TIME_SERIES_FFT;
using namespace RDM::TIME_SERIES;
using namespace RDM::DB;
const double tau = 6.283185307179586;
transaction <split <fft_abs_positive <32, MEASUREMENT_FFT1, double,
downsample <8, fft_abs <32, MEASUREMENT_FFT2, double,
arithmetic_mean <4, MEASUREMENT_FFT2, double,
RDM_RETCODE rc = ts_chain.init (db);
if (rc == sOKAY)
{
rc = ts_chain.begin ();
}
if (rc == sOKAY)
{
for (uint64_t time_stamp = 0; rc == sOKAY && time_stamp < 1024; time_stamp++)
{
const double signal = 10
+ sin (tau * time_stamp / 4) * 9
+ sin (tau * time_stamp / 8) * 8
+ sin (tau * time_stamp / 16) * 7
+ sin (tau * time_stamp / 32) * 6;
MEASUREMENT measurement = {time_stamp, signal};
rc = ts_chain.put_value (&measurement);
}
if (rc == sOKAY)
{
rc = ts_chain.end ();
}
else
{
ts_chain.rollback ();
}
}
return rc;
}
Time series for fft template classes.
Time series for mean template classes.
Time series for split template classes.
Template Class for doing an FFT with absoulte values.
Definition: rdm_time_series_fft.h:584
The RDM Time Series Namespace.
Definition: rdm_time_series.h:32
Time series for scale template class.
@ sOKAY
Definition: rdmretcodetypes.h:100
Template Class for downsampling.
Definition: rdm_time_series_downsample.h:53
Time series for downsample template class.
enum RDM_RETCODE_E RDM_RETCODE
RaimaDB status and error return codes.
The RDM Database Namespace.
Definition: rdm_db.h:31
Template Class for doing an arithmetic mean.
Definition: rdm_time_series_mean.h:626
Template Class for inserting a row.
Definition: rdm_db_insert_row.h:39
Template Class for doing transactions.
Definition: rdm_db_transaction.h:55
Time series for transaction template class.
Template Class for doing a split.
Definition: rdm_time_series_split.h:42
Template Class for scaling.
Definition: rdm_time_series_scale.h:51
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:346
Time series for insert_row template class.
RDM_RETCODE init(RDM_DB p_db)
Initialize this object.
Definition: rdm_db_insert_row.h:152
Template Class for doing an FFT with absoulte value of the positive frequencies.
Definition: rdm_time_series_fft.h:669