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::TIME_SERIES::transaction class can start a transaction by calling RDM::TIME_SERIES::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::TIME_SERIES::transaction::end() can be called. If for any reason an error condition is encountered, RDM::TIME_SERIES::transaction::rollback() can be called. It will roll the transaction back and also restore the stae of the classes.

The data passed to RDM::TIME_SERIES::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 "rdmtimeseries.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;
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;
}