Commit 3180510e authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libpsdxx [WP][FEATURE]: implement function log_frequency

parent 8b1932b5
......@@ -34,9 +34,69 @@
"PSDXX_FUNCTION_LOG_FREQUENCY_CC V1.0"
#include <psdxx/psd.h>
#include <psdxx/error.h>
namespace psd {
/*! \brief return a logarithmic frequency scale
*
* \par mapping function
* \f[
* f_l = \Delta f \, \left\{ c \, \left(10^{\frac{l}{m}}-1 \right) +1
* \right\}
* \f]
* Where
* - \f$ \Delta f =\f$ \p df
* - \f$ m= \f$ \p n_per_decade
*
* This mapping ensures \f$ f_0 = \Delta f \f$.
* Adjust \f$ c \f$ such that
* \f[
* f_1 - f_0 \geq \Delta f.
* \f]
* This condition is satisfied for
* \f[
* c = \textrm{max}\left(1,\frac{1}{10^{\frac{1}{m}}-1}\right)
* \f]
* The largest index \f$ l_\textrm{max} \f$ of the output array
* is
* \f[
* l_\textrm{max} = \textrm{floor}\left\{
* m\,\log_{10}\left(\frac{\frac{f_\textrm{max}}{\Delta f}-1}{c}+1
* \right)\right\}
* \f]
* to make
* \f[
* f(l_\textrm{max}) \leq N\,\Delta f
* \f]
* and
* \f[
* N\,\Delta f - f(l_\textrm{max}) \leq \Delta f
* \f]
* if \f$ N= \f$ \p nsamples.
*
*/
TDseries log_frequency(const double& df,
unsigned int& nsamples,
unsigned int& n_per_decade)
{
PSDXX_assert(n_per_decade>0, "must be positive");
double logfac=std::pow(10.,1./n_per_decade);
double c=1./(logfac-1.);
c=c<1.? 1. : c;
unsigned int lmax
=int(std::floor(n_per_decade
*std::log((nsamples-1.)/c)/std::log(10.)));
TDseries retval(0,lmax);
for (int i=retval.f(); i<=retval.l(); ++i)
{
retval(i)=df*(c*(std::pow(logfac,i)-1.)+1.);
}
return(retval);
} // TDseries log_frequency(const double& df,
// unsigned int& nsamples,
// unsigned int& n_per_decade)
} // namespace psd
/* ----- END OF function_log_frequency.cc ----- */
......@@ -221,7 +221,7 @@ namespace psd {
TDseries lin_frequency(const double& df,
unsigned int& nsamples);
/*! return a logarithmic frequency scale
/*! \brief return a logarithmic frequency scale
*
* \param df sampling interval in Hz of uniformly samples spectral values
* \param nsamples number of samples of spectral data
......
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