function_lin_log_sampling.cc 2.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*! \file function_lin_log_sampling.cc
 * \brief take a series with linear sampling and resample to logarithmic sampling (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 14/02/2019
 * 
 * take a series with linear sampling and resample to logarithmic sampling
 * (implementation)
 * 
 * Copyright (c) 2019 by Thomas Forbriger (BFO Schiltach) 
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ----
 *
 * REVISIONS and CHANGES 
 *  - 14/02/2019   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define PSDXX_FUNCTION_LIN_LOG_SAMPLING_CC_VERSION \
  "PSDXX_FUNCTION_LIN_LOG_SAMPLING_CC   V1.0"

#include <psdxx/psd.h>
#include <psdxx/error.h>

namespace psd {

  TDseries log_sampling(const TDseries::Tcoc& s,
                        const TDseries::Tcoc& flin,
                        const TDseries::Tcoc& flog)
  {
    // consistency checks
    PSDXX_assert(s.size()>1, "input series must contain at least 2 values");
    PSDXX_assert(s.size()==flin.size(),
                 "series of frequencies does not match data series");
50
51
52
    double df1=flin(flin.f()+1)-flin(flin.f());
    double df2=flin(flin.l())-flin(flin.l()-1);
    PSDXX_assert(std::abs((df2/df1)-1.)<1.e-8,
53
54
                 "input frequency scale is not linear");
    TDISeries::Tcoc data;
55
    data.interval=df1;
56
57
58
59
60
61
62
63
64
65
    data.data=s;
    TDseries retval=log_sampling(data, flog);
    return(retval);
  } // TDseries log_sampling(const TDseries::Tcoc& s,
    //                       const TDseries::Tcoc& flin,
    //                       const TDseries::Tcoc& flog)

} // namespace psd

/* ----- END OF function_lin_log_sampling.cc ----- */